Smart contracts for Optimism Layer 2 scaling solution including L1/L2 messaging, bridging, rollup management, and predeploy contracts
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
L1 contracts responsible for managing the Optimistic Rollup infrastructure, including transaction ordering, state commitments, storage management, fraud proof verification, and deployment coordination.
Contract Path: L1/rollup/CanonicalTransactionChain.sol
Maintains the canonical ordering of L2 transactions and provides the authoritative transaction log for the Optimistic Rollup.
constructor(
address _libAddressManager,
uint256 _maxTransactionGasLimit,
uint256 _l2GasDiscountDivisor,
uint256 _enqueueGasCost
);Parameters:
_libAddressManager (address): Address manager contract_maxTransactionGasLimit (uint256): Maximum gas limit per transaction_l2GasDiscountDivisor (uint256): Divisor for L2 gas discount calculation_enqueueGasCost (uint256): Gas cost for the enqueue functionuint256 public constant MIN_ROLLUP_TX_GAS = 100000;
uint256 public constant MAX_ROLLUP_TX_SIZE = 50000;contract CanonicalTransactionChain {
function enqueue(
address _target,
uint256 _gasLimit,
bytes memory _data
) external;
function appendQueueBatch(uint256 _numQueuedTransactions) external;
function appendSequencerBatch() external;
function getTotalElements() external view returns (uint256);
function getTotalBatches() external view returns (uint256);
function getQueueElement(uint256 _index) external view returns (
bytes32 transactionHash,
uint256 timestamp,
uint256 blockNumber
);
}Adds a transaction to the queue for inclusion in L2. Anyone can call this to force inclusion of a transaction.
Parameters:
_target (address): Target contract address on L2_gasLimit (uint256): Gas limit for the transaction (must be >= MIN_ROLLUP_TX_GAS)_data (bytes): Transaction data to executeUsage:
// Force inclusion of a transaction in L2
ctc.enqueue(
l2ContractAddress,
200000,
abi.encodeWithSignature("myFunction(uint256)", 123)
);Appends a batch of queued transactions to the chain (sequencer only).
Parameters:
_numQueuedTransactions (uint256): Number of queued transactions to includeAppends a batch of sequencer transactions to the chain (sequencer only).
event TransactionEnqueued(
address indexed _l1TxOrigin,
address indexed _target,
uint256 _gasLimit,
bytes _data,
uint256 indexed _queueIndex,
uint256 _timestamp
);
event QueueBatchAppended(
uint256 _startingQueueIndex,
uint256 _numQueueElements,
uint256 _totalElements
);
event SequencerBatchAppended(
uint256 _startingQueueIndex,
uint256 _numQueueElements,
uint256 _totalElements
);Contract Path: L1/rollup/StateCommitmentChain.sol
Manages state root commitments for L2 blocks and provides fraud proof verification.
contract StateCommitmentChain {
function appendStateBatch(
bytes32[] memory _batch,
uint256 _shouldStartAtElement
) external;
function deleteStateBatch(ChainBatchHeader memory _batchHeader) external;
function verifyStateCommitment(
bytes32 _element,
ChainBatchHeader memory _batchHeader,
ChainInclusionProof memory _proof
) external view returns (bool);
function getTotalElements() external view returns (uint256);
function getTotalBatches() external view returns (uint256);
function getLastSequencerTimestamp() external view returns (uint256);
}Appends a batch of state roots to the chain (sequencer only).
Parameters:
_batch (bytes32[]): Array of state roots to append_shouldStartAtElement (uint256): Expected starting element indexUsage:
bytes32[] memory stateRoots = new bytes32[](10);
// ... populate state roots
scc.appendStateBatch(stateRoots, currentIndex);Deletes an invalid state batch during fraud proof process.
Parameters:
_batchHeader (ChainBatchHeader): Header of the batch to deleteVerifies that a state root is included in a committed batch.
Parameters:
_element (bytes32): State root to verify_batchHeader (ChainBatchHeader): Batch header containing the element_proof (ChainInclusionProof): Merkle proof of inclusionReturns: bool - True if the commitment is valid
event StateBatchAppended(
uint256 indexed _batchIndex,
bytes32 _batchRoot,
uint256 _batchSize,
uint256 _prevTotalElements,
bytes _extraData
);
event StateBatchDeleted(
uint256 indexed _batchIndex,
bytes32 _batchRoot
);Contract Path: L1/rollup/ChainStorageContainer.sol
Manages append-only storage for chain data with access control and metadata.
contract ChainStorageContainer {
function setGlobalMetadata(bytes27 _globalMetadata) external;
function getGlobalMetadata() external view returns (bytes27);
function length() external view returns (uint256);
function push(bytes32 _object) external;
function push(bytes32 _object, bytes27 _globalMetadata) external;
function get(uint256 _index) external view returns (bytes32);
function deleteElementsAfterInclusive(uint256 _index) external;
}Sets global metadata for the container (self only).
Parameters:
_globalMetadata (bytes27): Metadata to storeAdds a new element to the container (self only).
Parameters:
_object (bytes32): Element to add_globalMetadata (bytes27, optional): Metadata for this pushRetrieves an element by index.
Parameters:
_index (uint256): Index of element to retrieveReturns: bytes32 - The stored element
event ObjectStored(
bytes32 _object,
uint256 _index
);Contract Path: L1/verification/BondManager.sol
Manages bonding for the fraud proof system, handling bond deposits, withdrawals, and slashing.
contract BondManager {
function isCollateralized(address _who) external view returns (bool);
function startBondWithdrawal(
bytes32 _preStateRoot,
bytes32 _postStateRoot
) external;
function finalizeWithdrawal() external;
function claim(address _who) external;
function deposit() external payable;
function getGasSpent(
bytes32 _preStateRoot,
bytes32 _postStateRoot
) external view returns (uint256);
}Checks if an address has sufficient bond collateral.
Parameters:
_who (address): Address to checkReturns: bool - True if sufficiently collateralized
Initiates the bond withdrawal process.
Parameters:
_preStateRoot (bytes32): State root before the disputed transition_postStateRoot (bytes32): State root after the disputed transitionCompletes bond withdrawal after the dispute period.
Claims another user's bond after a successful fraud proof.
Parameters:
_who (address): Address whose bond to claimDeposits ETH as bond collateral.
Usage:
// Deposit bond
bondManager.deposit{value: bondAmount}();
// Check if collateralized
require(bondManager.isCollateralized(proposer), "Insufficient bond");Contract Path: L1/deployment/AddressDictator.sol
Manages atomic address updates during system upgrades with ownership transfer mechanisms.
contract AddressDictator {
function setAddresses(
string[] memory _names,
address[] memory _addresses
) external;
function transferAddressManagerOwnership(address _newOwner) external;
function finalizeNamedAddressSet(
string memory _name,
address _namedAddress
) external;
}Sets multiple addresses atomically.
Parameters:
_names (string[]): Array of address names_addresses (address[]): Array of corresponding addressesTransfers ownership of the address manager.
Parameters:
_newOwner (address): New owner addressContract Path: L1/deployment/ChugSplashDictator.sol
Manages ChugSplash proxy deployment and upgrade coordination.
contract ChugSplashDictator {
function doActions(uint256 _step) external;
function finalize() external;
function isFinalized() external view returns (bool);
}Executes a step in the deployment process.
Parameters:
_step (uint256): Step number to executeFinalizes the deployment process.
struct ChainBatchHeader {
uint256 batchIndex;
bytes32 batchRoot;
uint256 batchSize;
uint256 prevTotalElements;
bytes extraData;
}struct ChainInclusionProof {
uint256 index;
bytes32[] siblings;
}contract L1Gateway {
ICanonicalTransactionChain public ctc;
function forceL2Transaction(
address target,
bytes calldata data
) external payable {
// Calculate required gas
uint256 gasLimit = gasleft() / 10; // Simplified calculation
// Enqueue transaction for forced inclusion
ctc.enqueue(target, gasLimit, data);
}
}contract FraudProofVerifier {
IStateCommitmentChain public scc;
function verifyStateTransition(
bytes32 stateRoot,
ChainBatchHeader memory batchHeader,
ChainInclusionProof memory proof
) public view returns (bool) {
return scc.verifyStateCommitment(stateRoot, batchHeader, proof);
}
}contract ProposerContract {
IBondManager public bondManager;
modifier onlyCollateralized() {
require(
bondManager.isCollateralized(msg.sender),
"Insufficient collateral"
);
_;
}
function proposeStateRoot(bytes32 stateRoot) external onlyCollateralized {
// Propose new state root
// ...
}
function depositBond() external payable {
bondManager.deposit{value: msg.value}();
}
}