Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ValidatorWalletTest.t.sol #511

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
undo yarn format
  • Loading branch information
mahsamoosavi committed Dec 22, 2023
commit 19f71f16de626cb53ee4dc2682cb8743b88b8e32
13 changes: 2 additions & 11 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ const solidity = {
},
},
},
{
version: '0.8.0',
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
],
overrides: {
'src/challengeV2/EdgeChallengeManager.sol': {
Expand Down Expand Up @@ -185,6 +176,6 @@ module.exports = {
target: 'ethers-v5',
},
contractSizer: {
strict: process.env.STRICT ? true : false,
},
strict: process.env.STRICT ? true : false
}
}
8 changes: 2 additions & 6 deletions contracts/scripts/boldUpgradeFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
export const deployDependencies = async (
signer: Signer,
maxDataSize: number,
log: boolean = false
log: boolean = false,
): Promise<
Omit<DeployedContracts, 'boldAction' | 'preImageHashLookup' | 'rollupReader'>
> => {
Expand Down Expand Up @@ -147,11 +147,7 @@ export const deployBoldUpgrade = async (
config: Config,
log: boolean = false
): Promise<DeployedContracts> => {
const deployed = await deployDependencies(
wallet,
config.settings.maxDataSize,
log
)
const deployed = await deployDependencies(wallet, config.settings.maxDataSize, log)

const fac = new BOLDUpgradeAction__factory(wallet)
const boldUpgradeAction = await fac.deploy(
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface Config {
seqInbox: string
}
settings: {
challengeGracePeriodBlocks: number
challengeGracePeriodBlocks: number,
confirmPeriodBlocks: number
challengePeriodBlocks: number
stakeToken: string
Expand Down
4 changes: 3 additions & 1 deletion contracts/scripts/files/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
"numBigStepLevel": 4,
"maxDataSize": 117964
},
"validators": ["0xf10EF80c6eF4930A62C5F9661c91339Df4dBB173"]
"validators": [
"0xf10EF80c6eF4930A62C5F9661c91339Df4dBB173"
]
}
3 changes: 2 additions & 1 deletion contracts/scripts/files/localDeployedContracts.json
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{}
{
}
6 changes: 5 additions & 1 deletion contracts/scripts/prepareBoldUpgrade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ethers, Wallet } from 'ethers'
import fs from 'fs'
import { DeployedContracts, getConfig, getJsonFile } from './common'
import {
DeployedContracts,
getConfig,
getJsonFile,
} from './common'
import { deployBoldUpgrade } from './boldUpgradeFunctions'
import dotenv from 'dotenv'

Expand Down
4 changes: 2 additions & 2 deletions contracts/scripts/testLocalPrepareTestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dotenv.config()

const transferToUpgradeExec = async (
rollupAdmin: Wallet,
rollupAddress: string
rollupAddress: string,
) => {
const upgradeExecutorImpl = await new ContractFactory(
UpgradeExecutorAbi,
Expand All @@ -32,7 +32,7 @@ const transferToUpgradeExec = async (
).deploy()
await upgradeExecutorImpl.deployed()

const proxyAdminAddress = '0xa4884de60AEef09b1b35fa255F56ee37198A80B3'
const proxyAdminAddress = "0xa4884de60AEef09b1b35fa255F56ee37198A80B3"

const upExecProxy = await new TransparentUpgradeableProxy__factory(
rollupAdmin
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/bridge/IOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IOutbox {
function OUTBOX_VERSION() external view returns (uint128); // the outbox version

function updateSendRoot(bytes32 sendRoot, bytes32 l2BlockHash) external;

function updateRollupAddress() external;

/// @notice When l2ToL1Sender returns a nonzero address, the message was originated by an L2 account
Expand Down
1 change: 1 addition & 0 deletions contracts/src/bridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
);
}


function _deliverMessage(
uint8 _kind,
address _sender,
Expand Down
16 changes: 3 additions & 13 deletions contracts/src/challenge/OldChallengeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ contract OldChallengeManager is DelegateCallAware, IOldChallengeManager {
} else if (expectedMode == ChallengeModeRequirement.BLOCK) {
require(challenge.mode == OldChallengeLib.ChallengeMode.BLOCK, "CHAL_NOT_BLOCK");
} else if (expectedMode == ChallengeModeRequirement.EXECUTION) {
require(
challenge.mode == OldChallengeLib.ChallengeMode.EXECUTION,
"CHAL_NOT_EXECUTION"
);
require(challenge.mode == OldChallengeLib.ChallengeMode.EXECUTION, "CHAL_NOT_EXECUTION");
} else {
assert(false);
}
Expand Down Expand Up @@ -149,10 +146,7 @@ contract OldChallengeManager is DelegateCallAware, IOldChallengeManager {
maxInboxMessagesRead++;
}
challenge.maxInboxMessages = maxInboxMessagesRead;
challenge.next = OldChallengeLib.Participant({
addr: asserter_,
timeLeft: asserterTimeLeft_
});
challenge.next = OldChallengeLib.Participant({addr: asserter_, timeLeft: asserterTimeLeft_});
challenge.current = OldChallengeLib.Participant({
addr: challenger_,
timeLeft: challengerTimeLeft_
Expand Down Expand Up @@ -260,11 +254,7 @@ contract OldChallengeManager is DelegateCallAware, IOldChallengeManager {
}

bytes32 afterHash = osp.proveOneStep(
ExecutionContext({
maxInboxMessagesRead: challenge.maxInboxMessages,
bridge: bridge,
initialWasmModuleRoot: challenge.wasmModuleRoot
}),
ExecutionContext({maxInboxMessagesRead: challenge.maxInboxMessages, bridge: bridge, initialWasmModuleRoot: challenge.wasmModuleRoot}),
challengeStart,
selection.oldSegments[selection.challengePosition],
proof
Expand Down
113 changes: 25 additions & 88 deletions contracts/src/challengeV2/EdgeChallengeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ interface IEdgeChallengeManager {
/// @param prefixProof A proof to show that the bisectionHistoryRoot commits to a prefix of the current endHistoryRoot
/// @return lowerChildId The id of the newly created lower child edge
/// @return upperChildId The id of the newly created upper child edge
function bisectEdge(
bytes32 edgeId,
bytes32 bisectionHistoryRoot,
bytes calldata prefixProof
) external returns (bytes32, bytes32);
function bisectEdge(bytes32 edgeId, bytes32 bisectionHistoryRoot, bytes calldata prefixProof)
external
returns (bytes32, bytes32);

/// @notice Confirm an edge if both its children are already confirmed
function confirmEdgeByChildren(bytes32 edgeId) external;
Expand Down Expand Up @@ -227,10 +225,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
/// @param upperChildId The id of the upper child created during bisection
/// @param lowerChildAlreadyExists When an edge is bisected the lower child may already exist - created by a rival.
event EdgeBisected(
bytes32 indexed edgeId,
bytes32 indexed lowerChildId,
bytes32 indexed upperChildId,
bool lowerChildAlreadyExists
bytes32 indexed edgeId, bytes32 indexed lowerChildId, bytes32 indexed upperChildId, bool lowerChildAlreadyExists
);

/// @notice An edge can be confirmed if both of its children were already confirmed.
Expand All @@ -242,21 +237,13 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
/// @param edgeId The edge that was confirmed
/// @param mutualId The mutual id of the confirmed edge
/// @param totalTimeUnrivaled The cumulative amount of time (in blocks) this edge spent unrivaled
event EdgeConfirmedByTime(
bytes32 indexed edgeId,
bytes32 indexed mutualId,
uint64 totalTimeUnrivaled
);
event EdgeConfirmedByTime(bytes32 indexed edgeId, bytes32 indexed mutualId, uint64 totalTimeUnrivaled);

/// @notice An edge can be confirmed if a zero layer edge in the level below claims this edge
/// @param edgeId The edge that was confirmed
/// @param mutualId The mutual id of the confirmed edge
/// @param claimingEdgeId The id of the zero layer edge that claimed this edge
event EdgeConfirmedByClaim(
bytes32 indexed edgeId,
bytes32 indexed mutualId,
bytes32 claimingEdgeId
);
event EdgeConfirmedByClaim(bytes32 indexed edgeId, bytes32 indexed mutualId, bytes32 claimingEdgeId);

/// @notice A SmallStep edge of length 1 can be confirmed via a one step proof
/// @param edgeId The edge that was confirmed
Expand All @@ -268,12 +255,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
/// @param mutualId The mutual id of the confirmed edge
/// @param stakeToken The ERC20 being refunded
/// @param stakeAmount The amount of tokens being refunded
event EdgeRefunded(
bytes32 indexed edgeId,
bytes32 indexed mutualId,
address stakeToken,
uint256 stakeAmount
);
event EdgeRefunded(bytes32 indexed edgeId, bytes32 indexed mutualId, address stakeToken, uint256 stakeAmount);

/// @dev Store for all edges and rival data
/// All edges, including edges from different challenges, are stored together in the same store
Expand Down Expand Up @@ -391,17 +373,11 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
if (args.proof.length == 0) {
revert EmptyEdgeSpecificProof();
}
(
,
ExecutionStateData memory predecessorStateData,
ExecutionStateData memory claimStateData
) = abi.decode(args.proof, (bytes32[], ExecutionStateData, ExecutionStateData));
(, ExecutionStateData memory predecessorStateData, ExecutionStateData memory claimStateData) =
abi.decode(args.proof, (bytes32[], ExecutionStateData, ExecutionStateData));

assertionChain.validateAssertionHash(
args.claimId,
claimStateData.executionState,
claimStateData.prevAssertionHash,
claimStateData.inboxAcc
args.claimId, claimStateData.executionState, claimStateData.prevAssertionHash, claimStateData.inboxAcc
);

assertionChain.validateAssertionHash(
Expand All @@ -420,21 +396,9 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
claimStateData.executionState
);

edgeAdded = store.createLayerZeroEdge(
args,
ard,
oneStepProofEntry,
expectedEndHeight,
NUM_BIGSTEP_LEVEL
);
edgeAdded = store.createLayerZeroEdge(args, ard, oneStepProofEntry, expectedEndHeight, NUM_BIGSTEP_LEVEL);
} else {
edgeAdded = store.createLayerZeroEdge(
args,
ard,
oneStepProofEntry,
expectedEndHeight,
NUM_BIGSTEP_LEVEL
);
edgeAdded = store.createLayerZeroEdge(args, ard, oneStepProofEntry, expectedEndHeight, NUM_BIGSTEP_LEVEL);
}

IERC20 st = stakeToken;
Expand Down Expand Up @@ -467,16 +431,12 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
}

/// @inheritdoc IEdgeChallengeManager
function bisectEdge(
bytes32 edgeId,
bytes32 bisectionHistoryRoot,
bytes calldata prefixProof
) external returns (bytes32, bytes32) {
(
bytes32 lowerChildId,
EdgeAddedData memory lowerChildAdded,
EdgeAddedData memory upperChildAdded
) = store.bisectEdge(edgeId, bisectionHistoryRoot, prefixProof);
function bisectEdge(bytes32 edgeId, bytes32 bisectionHistoryRoot, bytes calldata prefixProof)
external
returns (bytes32, bytes32)
{
(bytes32 lowerChildId, EdgeAddedData memory lowerChildAdded, EdgeAddedData memory upperChildAdded) =
store.bisectEdge(edgeId, bisectionHistoryRoot, prefixProof);

bool lowerChildAlreadyExists = lowerChildAdded.edgeId == 0;
// the lower child might already exist, if it didnt then a new
Expand Down Expand Up @@ -531,9 +491,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
ExecutionStateData calldata claimStateData
) public {
// if there are no ancestors provided, then the top edge is the edge we're confirming itself
bytes32 lastEdgeId = ancestorEdges.length > 0
? ancestorEdges[ancestorEdges.length - 1]
: edgeId;
bytes32 lastEdgeId = ancestorEdges.length > 0 ? ancestorEdges[ancestorEdges.length - 1] : edgeId;
ChallengeEdge storage topEdge = store.get(lastEdgeId);
EdgeType topLevelType = ChallengeEdgeLib.levelToType(topEdge.level, NUM_BIGSTEP_LEVEL);

Expand All @@ -556,22 +514,16 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
claimStateData.prevAssertionHash,
claimStateData.inboxAcc
);
assertionBlocks =
assertionChain.getSecondChildCreationBlock(claimStateData.prevAssertionHash) -
assertionChain.getFirstChildCreationBlock(claimStateData.prevAssertionHash);
assertionBlocks = assertionChain.getSecondChildCreationBlock(claimStateData.prevAssertionHash)
- assertionChain.getFirstChildCreationBlock(claimStateData.prevAssertionHash);
} else {
// if the assertion being claimed is not the first child, then it had siblings from the moment
// it was created, so it has no time unrivaled
assertionBlocks = 0;
}

uint64 totalTimeUnrivaled = store.confirmEdgeByTime(
edgeId,
ancestorEdges,
assertionBlocks,
challengePeriodBlocks,
NUM_BIGSTEP_LEVEL
);
uint64 totalTimeUnrivaled =
store.confirmEdgeByTime(edgeId, ancestorEdges, assertionBlocks, challengePeriodBlocks, NUM_BIGSTEP_LEVEL);

emit EdgeConfirmedByTime(edgeId, store.edges[edgeId].mutualId(), totalTimeUnrivaled);
}
Expand Down Expand Up @@ -649,15 +601,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
uint256 endHeight,
bytes32 endHistoryRoot
) public pure returns (bytes32) {
return
ChallengeEdgeLib.idComponent(
level,
originId,
startHeight,
startHistoryRoot,
endHeight,
endHistoryRoot
);
return ChallengeEdgeLib.idComponent(level, originId, startHeight, startHistoryRoot, endHeight, endHistoryRoot);
}

/// @inheritdoc IEdgeChallengeManager
Expand All @@ -668,14 +612,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
bytes32 startHistoryRoot,
uint256 endHeight
) public pure returns (bytes32) {
return
ChallengeEdgeLib.mutualIdComponent(
level,
originId,
startHeight,
startHistoryRoot,
endHeight
);
return ChallengeEdgeLib.mutualIdComponent(level, originId, startHeight, startHistoryRoot, endHeight);
}

/// @inheritdoc IEdgeChallengeManager
Expand Down
6 changes: 0 additions & 6 deletions contracts/src/challengeV2/IAssertionChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ import "../rollup/Assertion.sol";
/// @notice The interface required by the EdgeChallengeManager for requesting assertion data from the AssertionChain
interface IAssertionChain {
function bridge() external view returns (IBridge);

function validateAssertionHash(
bytes32 assertionHash,
ExecutionState calldata state,
bytes32 prevAssertionHash,
bytes32 inboxAcc
) external view;

function validateConfig(bytes32 assertionHash, ConfigData calldata configData) external view;

function getFirstChildCreationBlock(bytes32 assertionHash) external view returns (uint64);

function getSecondChildCreationBlock(bytes32 assertionHash) external view returns (uint64);

function isFirstChild(bytes32 assertionHash) external view returns (bool);

function isPending(bytes32 assertionHash) external view returns (bool);
}
Loading
Loading