// Copyright 2021-2022, 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; import "./AssertionState.sol"; enum AssertionStatus { // No assertion at this index NoAssertion, // Assertion is being computed Pending, // Assertion is confirmed Confirmed } struct AssertionNode { // This value starts at zero and is set to a value when the first child is created. After that it is constant until the assertion is destroyed or the owner destroys pending assertions uint64 firstChildBlock; // This value starts at zero and is set to a value when the second child is created. After that it is constant until the assertion is destroyed or the owner destroys pending assertions uint64 secondChildBlock; // The block number when this assertion was created uint64 createdAtBlock; // True if this assertion is the first child of its prev bool isFirstChild; // Status of the Assertion AssertionStatus status; // A hash of the context available at the time of this assertions creation. It should contain information that is not specific // to this assertion, but instead to the environment at the time of creation. This is necessary to store on the assertion // as this environment can change and we need to know what it was like at the time this assertion was created. An example // of this is the wasm module root which determines the state transition function on the L2. If the wasm module root // changes we need to know that previous assertions were made under a different root, so that we can understand that they // were valid at the time. So when resolving a challenge by one step, the edge challenge manager finds the wasm module root // that was recorded on the prev of the assertions being disputed and uses it to resolve the one step proof. bytes32 configHash; } 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; } struct AssertionInputs { // Additional data used to validate the before state BeforeStateData beforeStateData; AssertionState beforeState; AssertionState afterState; } struct ConfigData { bytes32 wasmModuleRoot; uint256 requiredStake; address challengeManager; uint64 confirmPeriodBlocks; uint64 nextInboxPosition; } /** * @notice Utility functions for Assertion */ library AssertionNodeLib { /** * @notice Initialize a Assertion */ function createAssertion( bool _isFirstChild, bytes32 _configHash ) internal view returns (AssertionNode memory) { AssertionNode memory assertion; assertion.createdAtBlock = uint64(block.number); assertion.isFirstChild = _isFirstChild; assertion.configHash = _configHash; assertion.status = AssertionStatus.Pending; return assertion; } /** * @notice Update child properties */ function childCreated( AssertionNode storage self ) internal { if (self.firstChildBlock == 0) { self.firstChildBlock = uint64(block.number); } else if (self.secondChildBlock == 0) { self.secondChildBlock = uint64(block.number); } } function requireExists( AssertionNode memory self ) internal pure { require(self.status != AssertionStatus.NoAssertion, "ASSERTION_NOT_EXIST"); } }