Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion scripts/config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const chainId = ethers.BigNumber.from('13331370')

const genesisAssertionState: AssertionStateStruct = {
globalState: {
bytes32Vals: [ethers.constants.HashZero, ethers.constants.HashZero],
bytes32Vals: [
ethers.constants.HashZero,
ethers.constants.HashZero,
ethers.constants.HashZero,
ethers.constants.HashZero,
],
u64Vals: [ethers.BigNumber.from('0'), ethers.BigNumber.from('0')],
},
machineStatus: 1, // FINISHED
Expand Down
7 changes: 6 additions & 1 deletion scripts/rollupCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ async function _getDevRollupConfig(

const genesisAssertionState: AssertionStateStruct = {
globalState: {
bytes32Vals: [ethers.constants.HashZero, ethers.constants.HashZero],
bytes32Vals: [
ethers.constants.HashZero,
ethers.constants.HashZero,
ethers.constants.HashZero,
ethers.constants.HashZero,
],
u64Vals: [ethers.BigNumber.from('0'), ethers.BigNumber.from('0')],
},
machineStatus: 1, // FINISHED
Expand Down
18 changes: 7 additions & 11 deletions src/challengeV2/EdgeChallengeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,13 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
) = abi.decode(args.proof, (bytes32[], AssertionStateData, AssertionStateData));

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

assertionChain.validateAssertionHash(
claimStateData.prevAssertionHash,
predecessorStateData.assertionState,
predecessorStateData.prevAssertionHash,
predecessorStateData.inboxAcc
predecessorStateData.prevAssertionHash
);

if (args.endHistoryRoot != claimStateData.assertionState.endHistoryRoot) {
Expand Down Expand Up @@ -374,10 +370,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
ChallengeEdgeLib.levelToType(topEdge.level, NUM_BIGSTEP_LEVEL) == EdgeType.Block;
if (isBlockLevel && assertionChain.isFirstChild(topEdge.claimId)) {
assertionChain.validateAssertionHash(
topEdge.claimId,
claimStateData.assertionState,
claimStateData.prevAssertionHash,
claimStateData.inboxAcc
topEdge.claimId, claimStateData.assertionState, claimStateData.prevAssertionHash
);
assertionBlocks = assertionChain.getSecondChildCreationBlock(
claimStateData.prevAssertionHash
Expand All @@ -402,8 +395,11 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {

assertionChain.validateConfig(prevAssertionHash, prevConfig);

// TODO(PR 427): OSP contracts are marked as pending work in the PR.
// Inbox-position-based checks no longer apply; use type(uint256).max as
// a stopgap until OSP is rewired against `nextParentChainBlockHash`.
ExecutionContext memory execCtx = ExecutionContext({
maxInboxMessagesRead: prevConfig.nextInboxPosition,
maxInboxMessagesRead: type(uint256).max,
bridge: assertionChain.bridge(),
initialWasmModuleRoot: prevConfig.wasmModuleRoot
});
Expand Down
3 changes: 1 addition & 2 deletions src/challengeV2/IAssertionChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ interface IAssertionChain {
function validateAssertionHash(
bytes32 assertionHash,
AssertionState calldata state,
bytes32 prevAssertionHash,
bytes32 inboxAcc
bytes32 prevAssertionHash
) external view;
function validateConfig(bytes32 assertionHash, ConfigData calldata configData) external view;
function getFirstChildCreationBlock(
Expand Down
4 changes: 0 additions & 4 deletions src/challengeV2/libraries/Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ struct AssertionStateData {
AssertionState assertionState;
/// @notice assertion Hash of the prev assertion
bytes32 prevAssertionHash;
/// @notice Inbox accumulator of the assertion
bytes32 inboxAcc;
}

/// @notice Data for creating a layer zero edge
Expand Down Expand Up @@ -44,8 +42,6 @@ struct CreateEdgeArgs {
/// bytes32[]: Inclusion proof - proof to show that the end state is the last state in the end history root
/// AssertionStateData: the before state of the edge
/// AssertionStateData: the after state of the edge
/// bytes32 predecessorId: id of the prev assertion
/// bytes32 inboxAcc: the inbox accumulator of the assertion
/// For BigStep and SmallStep edges this is the abi encoding of:
/// bytes32: Start state - first state the edge commits to
/// bytes32: End state - last state the edge commits to
Expand Down
7 changes: 4 additions & 3 deletions src/rollup/Assertion.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pragma solidity ^0.8.0;

import "./AssertionState.sol";
import "../state/MELState.sol";

enum AssertionStatus {
// No assertion at this index
Expand Down Expand Up @@ -39,8 +40,6 @@ struct AssertionNode {
struct BeforeStateData {
// The assertion hash of the prev of the beforeState(prev)
bytes32 prevPrevAssertionHash;
// The sequencer inbox accumulator asserted by the beforeState(prev)
bytes32 sequencerBatchAcc;
// below are the components of config hash
ConfigData configData;
}
Expand All @@ -50,14 +49,16 @@ struct AssertionInputs {
BeforeStateData beforeStateData;
AssertionState beforeState;
AssertionState afterState;
MELState afterMELState;
}

struct ConfigData {
bytes32 wasmModuleRoot;
uint256 requiredStake;
address challengeManager;
uint64 confirmPeriodBlocks;
uint64 nextInboxPosition;
// The next assertion should process parent chain blocks up to this one
bytes32 nextParentChainBlockHash;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/rollup/BOLDUpgradeAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ contract BOLDUpgradeAction {
layerZeroBigStepEdgeHeight: BIGSTEP_LEAF_SIZE,
layerZeroSmallStepEdgeHeight: SMALLSTEP_LEAF_SIZE,
genesisAssertionState: genesisAssertionState,
genesisInboxCount: inboxMaxCount,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the BOLDUpgradeAction depends on the current contracts, we need to remove this field. I'm wondering if we should remove this action from this branch now, or move it to a different repo.

anyTrustFastConfirmer: address(0), // fast confirmer would be migrated from the old rollup if existed
numBigStepLevel: NUM_BIGSTEP_LEVEL,
challengeGracePeriodBlocks: CHALLENGE_GRACE_PERIOD_BLOCKS,
Expand Down
2 changes: 0 additions & 2 deletions src/rollup/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ struct Config {
uint256 layerZeroSmallStepEdgeHeight;
/// @notice The execution state to be used in the genesis assertion
AssertionState genesisAssertionState;
/// @notice The inbox size at the time the genesis execution state was created
uint256 genesisInboxCount;
address anyTrustFastConfirmer;
uint8 numBigStepLevel;
uint64 challengeGracePeriodBlocks;
Expand Down
34 changes: 30 additions & 4 deletions src/rollup/IRollupAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ interface IRollupAdmin {
/// @dev Challenge manager was set
event ChallengeManagerSet(address challengeManager);

/// @dev MELConfig was set
event MELConfigSet(
uint16 indexed melVersion,
address indexed inbox,
address indexed sequencerInbox,
uint64 activationBlock
);

function initialize(
Config calldata config,
ContractDependencies calldata connectedContracts
Expand Down Expand Up @@ -157,9 +165,12 @@ interface IRollupAdmin {
* After decreasing the base stake the current staker will still have full stake locked up. They can release it by creating a new staker with the
* new smaller amount, and using it to create a child of the latest pending assertion. This will make the old staker inactive and withdrawable.
* @param newBaseStake New base stake to be set. Must be less than current base stake, otherwise use increaseBaseStake
* @param latestNextInboxPosition The nextInboxPosition of the only pending latestStakedAssertion
* @param latestNextParentChainBlockHash The nextParentChainBlockHash of the only pending latestStakedAssertion
*/
function decreaseBaseStake(uint256 newBaseStake, uint64 latestNextInboxPosition) external;
function decreaseBaseStake(
uint256 newBaseStake,
bytes32 latestNextParentChainBlockHash
) external;

/**
* @notice Increase the base stake required for creating an assertion
Expand All @@ -182,8 +193,7 @@ interface IRollupAdmin {
function forceConfirmAssertion(
bytes32 assertionHash,
bytes32 parentAssertionHash,
AssertionState calldata confirmState,
bytes32 inboxAcc
AssertionState calldata confirmState
) external;

function setLoserStakeEscrow(
Expand All @@ -206,6 +216,14 @@ interface IRollupAdmin {
address _sequencerInbox
) external;

/**
* @notice sets the rollup's inbox reference. Does not update the bridge's view.
* @param newInbox new address of inbox
*/
function setInbox(
IInboxBase newInbox
) external;

/**
* @notice set the validatorWhitelistDisabled flag
* @param _validatorWhitelistDisabled new value of validatorWhitelistDisabled, i.e. true = disabled
Expand All @@ -229,4 +247,12 @@ interface IRollupAdmin {
function setChallengeManager(
address _challengeManager
) external;

/**
* @notice set a new MELConfig which updates the current version and sets new Inbox and Bridge contracts
* @param _melVersion new MEL Version
* @param _inbox new address of the inbox contract
* @param _sequencerInbox new address of sequencer inbox
*/
function setMELConfig(uint16 _melVersion, address _inbox, address _sequencerInbox) external;
}
14 changes: 12 additions & 2 deletions src/rollup/IRollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ interface IRollupCore is IAssertionChain {
address withdrawalAddress;
}

struct MELConfig {
// MEL version
uint64 melVersion;
// Inbox contract that MEL will use from this moment on
address inbox;
// SequencerInbox contract that MEL will use from this moment on
address sequencerInbox;
// The block number at which this MEL version was activated
uint64 activationBlockNumber;
}

event RollupInitialized(bytes32 machineHash, uint256 chainId);

event AssertionCreated(
bytes32 indexed assertionHash,
bytes32 indexed parentAssertionHash,
AssertionInputs assertion,
bytes32 afterInboxBatchAcc,
uint256 inboxMaxCount,
bytes32 nextParentChainBlockHash,
bytes32 wasmModuleRoot,
uint256 requiredStake,
address challengeManager,
Expand Down
3 changes: 1 addition & 2 deletions src/rollup/IRollupLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ interface IRollupUser is IRollupCore, IOwnable {
bytes32 prevAssertionHash,
AssertionState calldata confirmState,
bytes32 winningEdgeId,
ConfigData calldata prevConfig,
bytes32 inboxAcc
ConfigData calldata prevConfig
) external;

function stakeOnNewAssertion(
Expand Down
61 changes: 42 additions & 19 deletions src/rollup/RollupAdminLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,20 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
anyTrustFastConfirmer = config.anyTrustFastConfirmer;

bytes32 parentAssertionHash = bytes32(0);
bytes32 inboxAcc = bytes32(0);
bytes32 genesisHash = RollupLib.assertionHash({
parentAssertionHash: parentAssertionHash,
afterStateHash: config.genesisAssertionState.hash(),
inboxAcc: inboxAcc
afterStateHash: config.genesisAssertionState.hash()
});

uint256 currentInboxCount = bridge.sequencerMessageCount();
// ensure to move the inbox forward by at least one message
if (currentInboxCount == config.genesisInboxCount) {
currentInboxCount += 1;
}
bytes32 nextParentChainBlockHash = blockhash(block.number - 1);
AssertionNode memory initialAssertion = AssertionNodeLib.createAssertion(
true,
RollupLib.configHash({
wasmModuleRoot: wasmModuleRoot,
requiredStake: baseStake,
challengeManager: address(challengeManager),
confirmPeriodBlocks: confirmPeriodBlocks,
nextInboxPosition: uint64(currentInboxCount)
nextParentChainBlockHash: nextParentChainBlockHash
})
);
initializeCore(initialAssertion, genesisHash);
Expand All @@ -99,8 +93,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
genesisHash,
parentAssertionHash,
assertionInputs,
inboxAcc,
currentInboxCount,
nextParentChainBlockHash,
wasmModuleRoot,
baseStake,
address(challengeManager),
Expand Down Expand Up @@ -267,7 +260,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
*/
function decreaseBaseStake(
uint256 newBaseStake,
uint64 latestNextInboxPosition
bytes32 latestNextParentChainBlockHash
) external override {
require(newBaseStake < baseStake, "BASE_STAKE_NOT_DECREASED");

Expand All @@ -292,7 +285,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
requiredStake: baseStake,
challengeManager: address(challengeManager),
confirmPeriodBlocks: confirmPeriodBlocks,
nextInboxPosition: uint64(latestNextInboxPosition)
nextParentChainBlockHash: latestNextParentChainBlockHash
});

uint256 pendingCount = 0;
Expand All @@ -313,7 +306,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
requiredStake: newBaseStake,
challengeManager: address(challengeManager),
confirmPeriodBlocks: confirmPeriodBlocks,
nextInboxPosition: uint64(latestNextInboxPosition)
nextParentChainBlockHash: latestNextParentChainBlockHash
});

pendingCount++;
Expand Down Expand Up @@ -376,11 +369,10 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
function forceConfirmAssertion(
bytes32 assertionHash,
bytes32 parentAssertionHash,
AssertionState calldata confirmState,
bytes32 inboxAcc
AssertionState calldata confirmState
) external override whenPaused {
// this skip deadline, prev, challenge validations
confirmAssertionInternal(assertionHash, parentAssertionHash, confirmState, inboxAcc);
confirmAssertionInternal(assertionHash, parentAssertionHash, confirmState);
emit AssertionForceConfirmed(assertionHash);
// previously: emit OwnerFunctionCalled(24);
}
Expand Down Expand Up @@ -414,7 +406,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
*/
function setSequencerInbox(
address _sequencerInbox
) external override {
) public {
bridge.setSequencerInbox(_sequencerInbox);
emit SequencerInboxSet(_sequencerInbox);
// previously: emit OwnerFunctionCalled(27);
Expand All @@ -426,7 +418,7 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
*/
function setInbox(
IInboxBase newInbox
) external {
) public {
inbox = newInbox;
emit InboxSet(address(newInbox));
// previously: emit OwnerFunctionCalled(28);
Expand Down Expand Up @@ -467,4 +459,35 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
emit ChallengeManagerSet(_challengeManager);
// previously: emit OwnerFunctionCalled(32);
}

/**
* @inheritdoc IRollupAdmin
*/
function setMELConfig(uint16 _melVersion, address _inbox, address _sequencerInbox) external {
// MEL versions can only be increased, except for the initial version, which must be version 0
if (currentMelConfigHash == bytes32(0)) {
require(_melVersion == 0, "INVALID_MEL_VERSION");
} else {
require(_melVersion > melConfig[currentMelConfigHash].melVersion, "INVALID_MEL_VERSION");
}

// Save the new MELConfig
MELConfig memory _melConfig = MELConfig({
melVersion: _melVersion,
inbox: _inbox,
sequencerInbox: _sequencerInbox,
activationBlockNumber: uint64(block.number)
});

bytes32 melConfigHash = keccak256(abi.encode(_melConfig));
melConfig[melConfigHash] = _melConfig;
currentMelConfigHash = melConfigHash;

// Setting the contracts
setInbox(IInboxBase(_inbox));
setSequencerInbox(_sequencerInbox);

// Emit event to signal the update to nitro
emit MELConfigSet(_melVersion, _inbox, _sequencerInbox, uint64(block.number));
}
Comment thread
TucksonDev marked this conversation as resolved.
Dismissed
}
Loading
Loading