Verified contractPartialMIT
OVM_StateCommitmentChain
Address0x17834b754e2f09946ce48d7b5beb4d7d94d98ab6
- Balance
0 ETH
- Transactions
2,947
- Compiler
solc 0.7.6
- Same code
1 more contract
Details
- Compiler
- solc 0.7.6+commit.7338295f
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- istanbul
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 13,011,905
- Creation transaction
- 0xcdc457dd88…7b95aeb69e
103 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/optimistic-ethereum/OVM/chain/OVM_StateCommitmentChain.solmain12.1 KB
- @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol2.54 KB
- @openzeppelin/contracts-upgradeable/proxy/Initializable.sol2.08 KB
- @openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol6.85 KB
- @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol1.2 KB
- @openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol2.47 KB
- @openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol2.86 KB
- @openzeppelin/contracts/access/Ownable.sol2.25 KB
- @openzeppelin/contracts/cryptography/ECDSA.sol3.91 KB
- @openzeppelin/contracts/introspection/ERC165Checker.sol5.59 KB
- @openzeppelin/contracts/introspection/IERC165.sol794 B
- @openzeppelin/contracts/math/Math.sol809 B
- @openzeppelin/contracts/math/SafeMath.sol7.23 KB
- @openzeppelin/contracts/token/ERC20/ERC20.sol10.8 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.7 KB
- @openzeppelin/contracts/token/ERC20/SafeERC20.sol3.72 KB
- @openzeppelin/contracts/utils/Address.sol7.82 KB
- @openzeppelin/contracts/utils/Context.sol941 B
- @openzeppelin/contracts/utils/ReentrancyGuard.sol2.61 KB
- contracts/optimistic-ethereum/OVM/bridge/messaging/OVM_L1CrossDomainMessenger.sol14.19 KB
- contracts/optimistic-ethereum/OVM/bridge/messaging/OVM_L1MultiMessageRelayer.sol2.43 KB
- contracts/optimistic-ethereum/OVM/bridge/messaging/OVM_L2CrossDomainMessenger.sol6.45 KB
- contracts/optimistic-ethereum/OVM/bridge/tokens/OVM_L1StandardBridge.sol9.87 KB
- contracts/optimistic-ethereum/OVM/bridge/tokens/OVM_L2StandardBridge.sol7.5 KB
- contracts/optimistic-ethereum/OVM/bridge/tokens/OVM_L2StandardTokenFactory.sol1.37 KB
- contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol42.11 KB
- contracts/optimistic-ethereum/OVM/chain/OVM_ChainStorageContainer.sol4.23 KB
- contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol76.41 KB
- contracts/optimistic-ethereum/OVM/execution/OVM_SafetyChecker.sol7.86 KB
- contracts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol19.4 KB
- contracts/optimistic-ethereum/OVM/execution/OVM_StateManagerFactory.sol1.09 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol3.73 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_ECDSAContractAccount.sol5.87 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_ETH.sol2.65 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_GasPriceOracle.sol1.39 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_L1MessageSender.sol1.48 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_L2ToL1MessagePasser.sol1.48 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_ProxyEOA.sol3.31 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_SequencerEntrypoint.sol2.64 KB
- contracts/optimistic-ethereum/OVM/predeploys/OVM_SequencerFeeVault.sol2.11 KB
- contracts/optimistic-ethereum/OVM/verification/Abs_FraudContributor.sol852 B
- contracts/optimistic-ethereum/OVM/verification/OVM_BondManager.sol7.98 KB
- contracts/optimistic-ethereum/OVM/verification/OVM_FraudVerifier.sol11.1 KB
- contracts/optimistic-ethereum/OVM/verification/OVM_StateTransitioner.sol16.73 KB
- contracts/optimistic-ethereum/OVM/verification/OVM_StateTransitionerFactory.sol2.2 KB
- contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_CrossDomainMessenger.sol938 B
- contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_L1CrossDomainMessenger.sol1.9 KB
- contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_L1MultiMessageRelayer.sol559 B
- contracts/optimistic-ethereum/iOVM/bridge/messaging/iOVM_L2CrossDomainMessenger.sol827 B
- contracts/optimistic-ethereum/iOVM/bridge/tokens/iOVM_L1ERC20Bridge.sol3.41 KB
- contracts/optimistic-ethereum/iOVM/bridge/tokens/iOVM_L1StandardBridge.sol2.7 KB
- contracts/optimistic-ethereum/iOVM/bridge/tokens/iOVM_L2ERC20Bridge.sol3.49 KB
- contracts/optimistic-ethereum/iOVM/chain/iOVM_CanonicalTransactionChain.sol6.11 KB
- contracts/optimistic-ethereum/iOVM/chain/iOVM_ChainStorageContainer.sol2.65 KB
- contracts/optimistic-ethereum/iOVM/chain/iOVM_StateCommitmentChain.sol3.07 KB
- contracts/optimistic-ethereum/iOVM/execution/iOVM_ExecutionManager.sol5.51 KB
- contracts/optimistic-ethereum/iOVM/execution/iOVM_SafetyChecker.sol299 B
- contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol3.9 KB
- contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManagerFactory.sol512 B
- contracts/optimistic-ethereum/iOVM/predeploys/iOVM_DeployerWhitelist.sol724 B
- contracts/optimistic-ethereum/iOVM/predeploys/iOVM_ECDSAContractAccount.sol524 B
- contracts/optimistic-ethereum/iOVM/predeploys/iOVM_L1MessageSender.sol303 B
- contracts/optimistic-ethereum/iOVM/predeploys/iOVM_L2ToL1MessagePasser.sol444 B
- contracts/optimistic-ethereum/iOVM/verification/iOVM_BondManager.sol3.93 KB
- contracts/optimistic-ethereum/iOVM/verification/iOVM_FraudVerifier.sol2.09 KB
- contracts/optimistic-ethereum/iOVM/verification/iOVM_StateTransitioner.sol2.06 KB
- contracts/optimistic-ethereum/iOVM/verification/iOVM_StateTransitionerFactory.sol653 B
- contracts/optimistic-ethereum/libraries/bridge/Lib_CrossDomainUtils.sol1.04 KB
- contracts/optimistic-ethereum/libraries/bridge/OVM_CrossDomainEnabled.sol2.79 KB
- contracts/optimistic-ethereum/libraries/codec/Lib_EIP155Tx.sol7 KB
- contracts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol5.77 KB
- contracts/optimistic-ethereum/libraries/constants/Lib_PredeployAddresses.sol1.49 KB
- contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol1.98 KB
- contracts/optimistic-ethereum/libraries/resolver/Lib_AddressResolver.sol1.08 KB
- contracts/optimistic-ethereum/libraries/resolver/Lib_ResolvedDelegateProxy.sol2.25 KB
- contracts/optimistic-ethereum/libraries/rlp/Lib_RLPReader.sol13.43 KB
- contracts/optimistic-ethereum/libraries/rlp/Lib_RLPWriter.sol6.85 KB
- contracts/optimistic-ethereum/libraries/standards/IL2StandardERC20.sol557 B
- contracts/optimistic-ethereum/libraries/standards/IWETH9.sol571 B
- contracts/optimistic-ethereum/libraries/standards/L2StandardERC20.sol1.64 KB
- contracts/optimistic-ethereum/libraries/trie/Lib_MerkleTrie.sol35.14 KB
- contracts/optimistic-ethereum/libraries/trie/Lib_SecureMerkleTrie.sol4.06 KB
- contracts/optimistic-ethereum/libraries/utils/Lib_Buffer.sol6.42 KB
- contracts/optimistic-ethereum/libraries/utils/Lib_Bytes32Utils.sol2.63 KB
- contracts/optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol6.77 KB
- contracts/optimistic-ethereum/libraries/utils/Lib_ErrorUtils.sol928 B
- contracts/optimistic-ethereum/libraries/utils/Lib_EthUtils.sol4.38 KB
- contracts/optimistic-ethereum/libraries/utils/Lib_MerkleTree.sol7.29 KB
- contracts/optimistic-ethereum/libraries/wrappers/Lib_ExecutionManagerWrapper.sol6.54 KB
- contracts/optimistic-ethereum/mockOVM/verification/mockOVM_BondManager.sol1.63 KB
- contracts/test-helpers/Mock_FraudVerifier.sol1 KB
- contracts/test-helpers/TestERC20.sol2.29 KB
- contracts/test-libraries/codec/TestLib_EIP155Tx.sol1.34 KB
- contracts/test-libraries/codec/TestLib_OVMCodec.sol774 B
- contracts/test-libraries/rlp/TestLib_RLPReader.sol1.86 KB
- contracts/test-libraries/rlp/TestLib_RLPWriter.sol1.76 KB
- contracts/test-libraries/trie/TestLib_MerkleTrie.sol1.57 KB
- contracts/test-libraries/trie/TestLib_SecureMerkleTrie.sol1.66 KB
- contracts/test-libraries/utils/TestLib_Buffer.sol1.55 KB
- contracts/test-libraries/utils/TestLib_Bytes32Utils.sol1.02 KB
- contracts/test-libraries/utils/TestLib_BytesUtils.sol2.23 KB
- contracts/test-libraries/utils/TestLib_EthUtils.sol2.12 KB
- contracts/test-libraries/utils/TestLib_MerkleTree.sol923 B
contracts/optimistic-ethereum/OVM/chain/OVM_StateCommitmentChain.sol
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import { Lib_MerkleTree } from "../../libraries/utils/Lib_MerkleTree.sol";
/* Interface Imports */
import { iOVM_FraudVerifier } from "../../iOVM/verification/iOVM_FraudVerifier.sol";
import { iOVM_StateCommitmentChain } from "../../iOVM/chain/iOVM_StateCommitmentChain.sol";
import { iOVM_CanonicalTransactionChain } from
"../../iOVM/chain/iOVM_CanonicalTransactionChain.sol";
import { iOVM_BondManager } from "../../iOVM/verification/iOVM_BondManager.sol";
import { iOVM_ChainStorageContainer } from "../../iOVM/chain/iOVM_ChainStorageContainer.sol";
/* External Imports */
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
* @title OVM_StateCommitmentChain
* @dev The State Commitment Chain (SCC) contract contains a list of proposed state roots which
* Proposers assert to be a result of each transaction in the Canonical Transaction Chain (CTC).
* Elements here have a 1:1 correspondence with transactions in the CTC, and should be the unique
* state root calculated off-chain by applying the canonical transactions one by one.
*
* Compiler used: solc
* Runtime target: EVM
*/
contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, Lib_AddressResolver {
/*************
* Constants *
*************/
uint256 public FRAUD_PROOF_WINDOW;
uint256 public SEQUENCER_PUBLISH_WINDOW;
/***************
* Constructor *
***************/
/**
* @param _libAddressManager Address of the Address Manager.
*/
constructor(
address _libAddressManager,
uint256 _fraudProofWindow,
uint256 _sequencerPublishWindow
)
Lib_AddressResolver(_libAddressManager)
{
FRAUD_PROOF_WINDOW = _fraudProofWindow;
SEQUENCER_PUBLISH_WINDOW = _sequencerPublishWindow;
}
/********************
* Public Functions *
********************/
/**
* Accesses the batch storage container.
* @return Reference to the batch storage container.
*/
function batches()
public
view
returns (
iOVM_ChainStorageContainer
)
{
return iOVM_ChainStorageContainer(
resolve("OVM_ChainStorageContainer-SCC-batches")
);
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function getTotalElements()
override
public
view
returns (
uint256 _totalElements
)
{
(uint40 totalElements, ) = _getBatchExtraData();
return uint256(totalElements);
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function getTotalBatches()
override
public
view
returns (
uint256 _totalBatches
)
{
return batches().length();
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function getLastSequencerTimestamp()
override
public
view
returns (
uint256 _lastSequencerTimestamp
)
{
(, uint40 lastSequencerTimestamp) = _getBatchExtraData();
return uint256(lastSequencerTimestamp);
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function appendStateBatch(
bytes32[] memory _batch,
uint256 _shouldStartAtElement
)
override
public
{
// Fail fast in to make sure our batch roots aren't accidentally made fraudulent by the
// publication of batches by some other user.
require(
_shouldStartAtElement == getTotalElements(),
"Actual batch start index does not match expected start index."
);
// Proposers must have previously staked at the BondManager
require(
iOVM_BondManager(resolve("OVM_BondManager")).isCollateralized(msg.sender),
"Proposer does not have enough collateral posted"
);
require(
_batch.length > 0,
"Cannot submit an empty state batch."
);
require(
getTotalElements() + _batch.length <=
iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"))
.getTotalElements(),
"Number of state roots cannot exceed the number of canonical transactions."
);
// Pass the block's timestamp and the publisher of the data
// to be used in the fraud proofs
_appendBatch(
_batch,
abi.encode(block.timestamp, msg.sender)
);
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function deleteStateBatch(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
override
public
{
require(
msg.sender == resolve("OVM_FraudVerifier"),
"State batches can only be deleted by the OVM_FraudVerifier."
);
require(
_isValidBatchHeader(_batchHeader),
"Invalid batch header."
);
require(
insideFraudProofWindow(_batchHeader),
"State batches can only be deleted within the fraud proof window."
);
_deleteBatch(_batchHeader);
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function verifyStateCommitment(
bytes32 _element,
Lib_OVMCodec.ChainBatchHeader memory _batchHeader,
Lib_OVMCodec.ChainInclusionProof memory _proof
)
override
public
view
returns (
bool
)
{
require(
_isValidBatchHeader(_batchHeader),
"Invalid batch header."
);
require(
Lib_MerkleTree.verify(
_batchHeader.batchRoot,
_element,
_proof.index,
_proof.siblings,
_batchHeader.batchSize
),
"Invalid inclusion proof."
);
return true;
}
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function insideFraudProofWindow(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
override
public
view
returns (
bool _inside
)
{
(uint256 timestamp,) = abi.decode(
_batchHeader.extraData,
(uint256, address)
);
require(
timestamp != 0,
"Batch header timestamp cannot be zero"
);
return SafeMath.add(timestamp, FRAUD_PROOF_WINDOW) > block.timestamp;
}
/**********************
* Internal Functions *
**********************/
/**
* Parses the batch context from the extra data.
* @return Total number of elements submitted.
* @return Timestamp of the last batch submitted by the sequencer.
*/
function _getBatchExtraData()
internal
view
returns (
uint40,
uint40
)
{
bytes27 extraData = batches().getGlobalMetadata();
// solhint-disable max-line-length
uint40 totalElements;
uint40 lastSequencerTimestamp;
assembly {
extraData := shr(40, extraData)
totalElements := and(extraData, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
lastSequencerTimestamp := shr(40, and(extraData, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000))
}
// solhint-enable max-line-length
return (
totalElements,
lastSequencerTimestamp
);
}
/**
* Encodes the batch context for the extra data.
* @param _totalElements Total number of elements submitted.
* @param _lastSequencerTimestamp Timestamp of the last batch submitted by the sequencer.
* @return Encoded batch context.
*/
function _makeBatchExtraData(
uint40 _totalElements,
uint40 _lastSequencerTimestamp
)
internal
pure
returns (
bytes27
)
{
bytes27 extraData;
assembly {
extraData := _totalElements
extraData := or(extraData, shl(40, _lastSequencerTimestamp))
extraData := shl(40, extraData)
}
return extraData;
}
/**
* Appends a batch to the chain.
* @param _batch Elements within the batch.
* @param _extraData Any extra data to append to the batch.
*/
function _appendBatch(
bytes32[] memory _batch,
bytes memory _extraData
)
internal
{
address sequencer = resolve("OVM_Proposer");
(uint40 totalElements, uint40 lastSequencerTimestamp) = _getBatchExtraData();
if (msg.sender == sequencer) {
lastSequencerTimestamp = uint40(block.timestamp);
} else {
// We keep track of the last batch submitted by the sequencer so there's a window in
// which only the sequencer can publish state roots. A window like this just reduces
// the chance of "system breaking" state roots being published while we're still in
// testing mode. This window should be removed or significantly reduced in the future.
require(
lastSequencerTimestamp + SEQUENCER_PUBLISH_WINDOW < block.timestamp,
"Cannot publish state roots within the sequencer publication window."
);
}
// For efficiency reasons getMerkleRoot modifies the `_batch` argument in place
// while calculating the root hash therefore any arguments passed to it must not
// be used again afterwards
Lib_OVMCodec.ChainBatchHeader memory batchHeader = Lib_OVMCodec.ChainBatchHeader({
batchIndex: getTotalBatches(),
batchRoot: Lib_MerkleTree.getMerkleRoot(_batch),
batchSize: _batch.length,
prevTotalElements: totalElements,
extraData: _extraData
});
emit StateBatchAppended(
batchHeader.batchIndex,
batchHeader.batchRoot,
batchHeader.batchSize,
batchHeader.prevTotalElements,
batchHeader.extraData
);
batches().push(
Lib_OVMCodec.hashBatchHeader(batchHeader),
_makeBatchExtraData(
uint40(batchHeader.prevTotalElements + batchHeader.batchSize),
lastSequencerTimestamp
)
);
}
/**
* Removes a batch and all subsequent batches from the chain.
* @param _batchHeader Header of the batch to remove.
*/
function _deleteBatch(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
internal
{
require(
_batchHeader.batchIndex < batches().length(),
"Invalid batch index."
);
require(
_isValidBatchHeader(_batchHeader),
"Invalid batch header."
);
batches().deleteElementsAfterInclusive(
_batchHeader.batchIndex,
_makeBatchExtraData(
uint40(_batchHeader.prevTotalElements),
0
)
);
emit StateBatchDeleted(
_batchHeader.batchIndex,
_batchHeader.batchRoot
);
}
/**
* Checks that a batch header matches the stored hash for the given index.
* @param _batchHeader Batch header to validate.
* @return Whether or not the header matches the stored one.
*/
function _isValidBatchHeader(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
internal
view
returns (
bool
)
{
return Lib_OVMCodec.hashBatchHeader(_batchHeader) == batches().get(_batchHeader.batchIndex);
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.