Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
9 changes: 3 additions & 6 deletions src/challengeV2/EdgeChallengeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,13 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
assertionChain.validateAssertionHash(
args.claimId,
claimStateData.assertionState,
claimStateData.prevAssertionHash,
claimStateData.inboxAcc
claimStateData.prevAssertionHash
);

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

if (args.endHistoryRoot != claimStateData.assertionState.endHistoryRoot) {
Expand Down Expand Up @@ -376,8 +374,7 @@ contract EdgeChallengeManager is IEdgeChallengeManager, Initializable {
assertionChain.validateAssertionHash(
topEdge.claimId,
claimStateData.assertionState,
claimStateData.prevAssertionHash,
claimStateData.inboxAcc
claimStateData.prevAssertionHash
);
assertionBlocks = assertionChain.getSecondChildCreationBlock(
claimStateData.prevAssertionHash
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
5 changes: 4 additions & 1 deletion 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 "./MELState.sol";

enum AssertionStatus {
// No assertion at this index
Expand Down Expand Up @@ -50,14 +51,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
32 changes: 28 additions & 4 deletions src/rollup/IRollupAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ interface IRollupAdmin {
/// @dev Challenge manager was set
event ChallengeManagerSet(address challengeManager);

/// @dev MELConfig was set
event MELConfigSet(
uint64 indexed melVersion, address indexed inbox, address indexed sequencerInbox, uint64 activationBlock
Comment thread
TucksonDev marked this conversation as resolved.
Outdated
);

function initialize(
Config calldata config,
ContractDependencies calldata connectedContracts
Expand Down Expand Up @@ -157,9 +162,9 @@ 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 +187,7 @@ interface IRollupAdmin {
function forceConfirmAssertion(
bytes32 assertionHash,
bytes32 parentAssertionHash,
AssertionState calldata confirmState,
bytes32 inboxAcc
AssertionState calldata confirmState
) external;

function setLoserStakeEscrow(
Expand All @@ -206,6 +210,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 +241,16 @@ 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(
uint64 _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
46 changes: 46 additions & 0 deletions src/rollup/MELState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021-2026, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

struct MELState {
// Versioning struct for the state, starting at 0.
uint16 version;
// The parent chain block number where MEL becomes part of the Arbitrum chain's consensus.
uint64 versionActivationBlockNumber;

// Parent chain ID of the Arbitrum chain that is running MEL.
uint64 parentChainId;
// The latest parent chain block fields processed by MEL.
uint64 parentChainBlockNumber;
bytes32 parentChainBlockHash;
bytes32 parentChainPreviousBlockHash;

// Address of the contract where batches are posted to.
address batchPostingTargetAddress;
// Address of the contract where delayed messages are posted to.
address delayedMessagePostingTargetAddress;

// Number of batches observed when extracting with MEL.
uint64 batchCount;

// Local accumulators related to messsages and delayed messages.
uint64 msgCount;
bytes32 localMsgAccumulator;

// Accumulators and numbers related to delayed messages.
uint64 delayedMessagesRead;
uint64 delayedMessagesSeen;
bytes32 delayedMessageInboxAcc;
bytes32 delayedMessageOutboxAcc;
}

/**
* @notice Utility functions for MELState
*/
library MELStateLib {
function hash(MELState memory state) internal pure returns (bytes32) {
return keccak256(abi.encode(state));
}
}
63 changes: 44 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,37 @@ contract RollupAdminLogic is RollupCore, IRollupAdmin, DoubleLogicUUPSUpgradeabl
emit ChallengeManagerSet(_challengeManager);
// previously: emit OwnerFunctionCalled(32);
}

/**
* @inheritdoc IRollupAdmin
*/
function setMELConfig(
uint64 _melVersion,
address _inbox,
address _sequencerInbox
) external {
// MEL versions can only be increased
require(_melVersion > melVersion, "INVALID_MEL_VERSION");

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

// Set the new MEL version
melVersion = _melVersion;

// 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;

// 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