@arbitrum/nitro-contracts 1.0.0-beta.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/package.json +13 -2
  2. package/src/bridge/Bridge.sol +49 -29
  3. package/src/bridge/IBridge.sol +58 -45
  4. package/src/bridge/IDelayedMessageProvider.sol +2 -1
  5. package/src/bridge/IInbox.sol +133 -50
  6. package/src/bridge/IOutbox.sol +95 -27
  7. package/src/bridge/IOwnable.sol +2 -1
  8. package/src/bridge/ISequencerInbox.sol +79 -31
  9. package/src/bridge/Inbox.sol +171 -108
  10. package/src/bridge/Outbox.sol +26 -41
  11. package/src/bridge/SequencerInbox.sol +152 -62
  12. package/src/challenge/ChallengeManager.sol +0 -9
  13. package/src/challenge/IChallengeManager.sol +0 -2
  14. package/src/libraries/AdminFallbackProxy.sol +4 -4
  15. package/src/libraries/Constants.sol +3 -0
  16. package/src/libraries/{SecondaryLogicUUPSUpgradeable.sol → DoubleLogicUUPSUpgradeable.sol} +2 -1
  17. package/src/libraries/Error.sol +119 -0
  18. package/src/libraries/IGasRefunder.sol +13 -6
  19. package/src/libraries/MerkleLib.sol +5 -3
  20. package/src/mocks/BridgeStub.sol +22 -1
  21. package/src/mocks/BridgeUnproxied.sol +17 -0
  22. package/src/mocks/InboxStub.sol +49 -2
  23. package/src/mocks/SequencerInboxStub.sol +13 -3
  24. package/src/mocks/Simple.sol +69 -0
  25. package/src/node-interface/NodeInterface.sol +69 -7
  26. package/src/precompiles/ArbGasInfo.sol +16 -4
  27. package/src/precompiles/ArbOwner.sol +18 -0
  28. package/src/precompiles/ArbOwnerPublic.sol +3 -0
  29. package/src/precompiles/ArbSys.sol +7 -4
  30. package/src/rollup/IRollupCore.sol +2 -0
  31. package/src/rollup/IRollupLogic.sol +10 -0
  32. package/src/rollup/RollupAdminLogic.sol +69 -3
  33. package/src/rollup/RollupCore.sol +8 -2
  34. package/src/rollup/RollupCreator.sol +3 -3
  35. package/src/rollup/RollupEventInbox.sol +3 -6
  36. package/src/rollup/RollupLib.sol +1 -0
  37. package/src/{libraries/ArbitrumProxy.sol → rollup/RollupProxy.sol} +3 -3
  38. package/src/rollup/RollupUserLogic.sol +47 -10
  39. package/src/state/GlobalState.sol +7 -0
  40. package/src/test-helpers/BridgeTester.sol +17 -1
  41. package/src/test-helpers/InterfaceCompatibilityTester.sol +11 -0
  42. package/src/test-helpers/OutboxWithoutOptTester.sol +33 -7
@@ -2,32 +2,13 @@
2
2
  // For license information, see https://github.com/nitro/blob/master/LICENSE
3
3
  // SPDX-License-Identifier: BUSL-1.1
4
4
 
5
- pragma solidity ^0.8.4;
5
+ // solhint-disable-next-line compiler-version
6
+ pragma solidity >=0.6.9 <0.9.0;
6
7
 
7
- import {AlreadyInit, NotRollup} from "../libraries/Error.sol";
8
-
9
- /// @dev The provided proof was too long
10
- /// @param proofLength The length of the too-long proof
11
- error ProofTooLong(uint256 proofLength);
12
-
13
- /// @dev The output index was greater than the maximum
14
- /// @param index The output index
15
- /// @param maxIndex The max the index could be
16
- error PathNotMinimal(uint256 index, uint256 maxIndex);
17
-
18
- /// @dev The calculated root does not exist
19
- /// @param root The calculated root
20
- error UnknownRoot(bytes32 root);
21
-
22
- /// @dev The record has already been spent
23
- /// @param index The index of the spent record
24
- error AlreadySpent(uint256 index);
25
-
26
- /// @dev A call to the bridge failed with no return data
27
- error BridgeCallFailed();
8
+ import "./IBridge.sol";
28
9
 
29
10
  interface IOutbox {
30
- event SendRootUpdated(bytes32 indexed blockHash, bytes32 indexed outputRoot);
11
+ event SendRootUpdated(bytes32 indexed outputRoot, bytes32 indexed l2BlockHash);
31
12
  event OutBoxTransactionExecuted(
32
13
  address indexed to,
33
14
  address indexed l2Sender,
@@ -35,18 +16,105 @@ interface IOutbox {
35
16
  uint256 transactionIndex
36
17
  );
37
18
 
19
+ function rollup() external view returns (address); // the rollup contract
20
+
21
+ function bridge() external view returns (IBridge); // the bridge contract
22
+
23
+ function spent(uint256) external view returns (bytes32); // packed spent bitmap
24
+
25
+ function roots(bytes32) external view returns (bytes32); // maps root hashes => L2 block hash
26
+
27
+ // solhint-disable-next-line func-name-mixedcase
28
+ function OUTBOX_VERSION() external view returns (uint128); // the outbox version
29
+
30
+ function updateSendRoot(bytes32 sendRoot, bytes32 l2BlockHash) external;
31
+
32
+ /// @notice When l2ToL1Sender returns a nonzero address, the message was originated by an L2 account
33
+ /// When the return value is zero, that means this is a system message
34
+ /// @dev the l2ToL1Sender behaves as the tx.origin, the msg.sender should be validated to protect against reentrancies
38
35
  function l2ToL1Sender() external view returns (address);
39
36
 
37
+ /// @return l2Block return L2 block when the L2 tx was initiated or 0 if no L2 to L1 transaction is active
40
38
  function l2ToL1Block() external view returns (uint256);
41
39
 
40
+ /// @return l1Block return L1 block when the L2 tx was initiated or 0 if no L2 to L1 transaction is active
42
41
  function l2ToL1EthBlock() external view returns (uint256);
43
42
 
43
+ /// @return timestamp return L2 timestamp when the L2 tx was initiated or 0 if no L2 to L1 transaction is active
44
44
  function l2ToL1Timestamp() external view returns (uint256);
45
45
 
46
- // @deprecated batch number is now always 0
47
- function l2ToL1BatchNum() external view returns (uint256);
48
-
46
+ /// @return outputId returns the unique output identifier of the L2 to L1 tx or 0 if no L2 to L1 transaction is active
49
47
  function l2ToL1OutputId() external view returns (bytes32);
50
48
 
51
- function updateSendRoot(bytes32 sendRoot, bytes32 l2BlockHash) external;
49
+ /**
50
+ * @notice Executes a messages in an Outbox entry.
51
+ * @dev Reverts if dispute period hasn't expired, since the outbox entry
52
+ * is only created once the rollup confirms the respective assertion.
53
+ * @dev it is not possible to execute any L2-to-L1 transaction which contains data
54
+ * to a contract address without any code (as enforced by the Bridge contract).
55
+ * @param proof Merkle proof of message inclusion in send root
56
+ * @param index Merkle path to message
57
+ * @param l2Sender sender if original message (i.e., caller of ArbSys.sendTxToL1)
58
+ * @param to destination address for L1 contract call
59
+ * @param l2Block l2 block number at which sendTxToL1 call was made
60
+ * @param l1Block l1 block number at which sendTxToL1 call was made
61
+ * @param l2Timestamp l2 Timestamp at which sendTxToL1 call was made
62
+ * @param value wei in L1 message
63
+ * @param data abi-encoded L1 message data
64
+ */
65
+ function executeTransaction(
66
+ bytes32[] calldata proof,
67
+ uint256 index,
68
+ address l2Sender,
69
+ address to,
70
+ uint256 l2Block,
71
+ uint256 l1Block,
72
+ uint256 l2Timestamp,
73
+ uint256 value,
74
+ bytes calldata data
75
+ ) external;
76
+
77
+ /**
78
+ * @dev function used to simulate the result of a particular function call from the outbox
79
+ * it is useful for things such as gas estimates. This function includes all costs except for
80
+ * proof validation (which can be considered offchain as a somewhat of a fixed cost - it's
81
+ * not really a fixed cost, but can be treated as so with a fixed overhead for gas estimation).
82
+ * We can't include the cost of proof validation since this is intended to be used to simulate txs
83
+ * that are included in yet-to-be confirmed merkle roots. The simulation entrypoint could instead pretend
84
+ * to confirm a pending merkle root, but that would be less practical for integrating with tooling.
85
+ * It is only possible to trigger it when the msg sender is address zero, which should be impossible
86
+ * unless under simulation in an eth_call or eth_estimateGas
87
+ */
88
+ function executeTransactionSimulation(
89
+ uint256 index,
90
+ address l2Sender,
91
+ address to,
92
+ uint256 l2Block,
93
+ uint256 l1Block,
94
+ uint256 l2Timestamp,
95
+ uint256 value,
96
+ bytes calldata data
97
+ ) external;
98
+
99
+ /**
100
+ * @param index Merkle path to message
101
+ * @return true if the message has been spent
102
+ */
103
+ function isSpent(uint256 index) external view returns (bool);
104
+
105
+ function calculateItemHash(
106
+ address l2Sender,
107
+ address to,
108
+ uint256 l2Block,
109
+ uint256 l1Block,
110
+ uint256 l2Timestamp,
111
+ uint256 value,
112
+ bytes calldata data
113
+ ) external pure returns (bytes32);
114
+
115
+ function calculateMerkleRoot(
116
+ bytes32[] memory proof,
117
+ uint256 path,
118
+ bytes32 item
119
+ ) external pure returns (bytes32);
52
120
  }
@@ -2,7 +2,8 @@
2
2
  // For license information, see https://github.com/nitro/blob/master/LICENSE
3
3
  // SPDX-License-Identifier: BUSL-1.1
4
4
 
5
- pragma solidity ^0.8.4;
5
+ // solhint-disable-next-line compiler-version
6
+ pragma solidity >=0.4.21 <0.9.0;
6
7
 
7
8
  interface IOwnable {
8
9
  function owner() external view returns (address);
@@ -2,11 +2,13 @@
2
2
  // For license information, see https://github.com/nitro/blob/master/LICENSE
3
3
  // SPDX-License-Identifier: BUSL-1.1
4
4
 
5
- pragma solidity ^0.8.0;
5
+ // solhint-disable-next-line compiler-version
6
+ pragma solidity >=0.6.9 <0.9.0;
7
+ pragma experimental ABIEncoderV2;
6
8
 
7
9
  import "../libraries/IGasRefunder.sol";
8
- import {AlreadyInit, HadZeroInit, NotOrigin, DataTooLarge, NotRollup} from "../libraries/Error.sol";
9
10
  import "./IDelayedMessageProvider.sol";
11
+ import "./IBridge.sol";
10
12
 
11
13
  interface ISequencerInbox is IDelayedMessageProvider {
12
14
  struct MaxTimeVariation {
@@ -50,63 +52,109 @@ interface ISequencerInbox is IDelayedMessageProvider {
50
52
  /// @dev a keyset was invalidated
51
53
  event InvalidateKeyset(bytes32 indexed keysetHash);
52
54
 
53
- /// @dev Thrown when someone attempts to read fewer messages than have already been read
54
- error DelayedBackwards();
55
+ function totalDelayedMessagesRead() external view returns (uint256);
55
56
 
56
- /// @dev Thrown when someone attempts to read more messages than exist
57
- error DelayedTooFar();
57
+ function bridge() external view returns (IBridge);
58
58
 
59
- /// @dev Force include can only read messages more blocks old than the delay period
60
- error ForceIncludeBlockTooSoon();
59
+ /// @dev The size of the batch header
60
+ // solhint-disable-next-line func-name-mixedcase
61
+ function HEADER_LENGTH() external view returns (uint256);
61
62
 
62
- /// @dev Force include can only read messages more seconds old than the delay period
63
- error ForceIncludeTimeTooSoon();
63
+ /// @dev If the first batch data byte after the header has this bit set,
64
+ /// the sequencer inbox has authenticated the data. Currently not used.
65
+ // solhint-disable-next-line func-name-mixedcase
66
+ function DATA_AUTHENTICATED_FLAG() external view returns (bytes1);
64
67
 
65
- /// @dev The message provided did not match the hash in the delayed inbox
66
- error IncorrectMessagePreimage();
68
+ function rollup() external view returns (IOwnable);
67
69
 
68
- /// @dev This can only be called by the batch poster
69
- error NotBatchPoster();
70
+ function isBatchPoster(address) external view returns (bool);
70
71
 
71
- /// @dev The sequence number provided to this message was inconsistent with the number of batches already included
72
- error BadSequencerNumber(uint256 stored, uint256 received);
73
-
74
- /// @dev The batch data has the inbox authenticated bit set, but the batch data was not authenticated by the inbox
75
- error DataNotAuthenticated();
76
-
77
- /// @dev Tried to create an already valid Data Availability Service keyset
78
- error AlreadyValidDASKeyset(bytes32);
72
+ struct DasKeySetInfo {
73
+ bool isValidKeyset;
74
+ uint64 creationBlock;
75
+ }
79
76
 
80
- /// @dev Tried to use or invalidate an already invalid Data Availability Service keyset
81
- error NoSuchKeyset(bytes32);
77
+ // https://github.com/ethereum/solidity/issues/11826
78
+ // function maxTimeVariation() external view returns (MaxTimeVariation calldata);
79
+ // function dasKeySetInfo(bytes32) external view returns (DasKeySetInfo calldata);
80
+
81
+ /// @notice Remove force inclusion delay after a L1 chainId fork
82
+ function removeDelayAfterFork() external;
83
+
84
+ /// @notice Force messages from the delayed inbox to be included in the chain
85
+ /// Callable by any address, but message can only be force-included after maxTimeVariation.delayBlocks and
86
+ /// maxTimeVariation.delaySeconds has elapsed. As part of normal behaviour the sequencer will include these
87
+ /// messages so it's only necessary to call this if the sequencer is down, or not including any delayed messages.
88
+ /// @param _totalDelayedMessagesRead The total number of messages to read up to
89
+ /// @param kind The kind of the last message to be included
90
+ /// @param l1BlockAndTime The l1 block and the l1 timestamp of the last message to be included
91
+ /// @param baseFeeL1 The l1 gas price of the last message to be included
92
+ /// @param sender The sender of the last message to be included
93
+ /// @param messageDataHash The messageDataHash of the last message to be included
94
+ function forceInclusion(
95
+ uint256 _totalDelayedMessagesRead,
96
+ uint8 kind,
97
+ uint64[2] calldata l1BlockAndTime,
98
+ uint256 baseFeeL1,
99
+ address sender,
100
+ bytes32 messageDataHash
101
+ ) external;
82
102
 
83
103
  function inboxAccs(uint256 index) external view returns (bytes32);
84
104
 
85
105
  function batchCount() external view returns (uint256);
86
106
 
87
- function addSequencerL2Batch(
107
+ function isValidKeysetHash(bytes32 ksHash) external view returns (bool);
108
+
109
+ /// @notice the creation block is intended to still be available after a keyset is deleted
110
+ function getKeysetCreationBlock(bytes32 ksHash) external view returns (uint256);
111
+
112
+ // ---------- BatchPoster functions ----------
113
+
114
+ function addSequencerL2BatchFromOrigin(
88
115
  uint256 sequenceNumber,
89
116
  bytes calldata data,
90
117
  uint256 afterDelayedMessagesRead,
91
118
  IGasRefunder gasRefunder
92
119
  ) external;
93
120
 
94
- // Methods only callable by rollup owner
121
+ function addSequencerL2Batch(
122
+ uint256 sequenceNumber,
123
+ bytes calldata data,
124
+ uint256 afterDelayedMessagesRead,
125
+ IGasRefunder gasRefunder,
126
+ uint256 prevMessageCount,
127
+ uint256 newMessageCount
128
+ ) external;
129
+
130
+ // ---------- onlyRollupOrOwner functions ----------
95
131
 
96
132
  /**
97
- * @notice Set max time variation from actual time for sequencer inbox
98
- * @param timeVariation the maximum time variation parameters
133
+ * @notice Set max delay for sequencer inbox
134
+ * @param maxTimeVariation_ the maximum time variation parameters
99
135
  */
100
- function setMaxTimeVariation(MaxTimeVariation memory timeVariation) external;
136
+ function setMaxTimeVariation(MaxTimeVariation memory maxTimeVariation_) external;
101
137
 
102
138
  /**
103
139
  * @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
104
140
  * @param addr the address
105
- * @param isBatchPoster if the specified address should be authorized as a batch poster
141
+ * @param isBatchPoster_ if the specified address should be authorized as a batch poster
106
142
  */
107
- function setIsBatchPoster(address addr, bool isBatchPoster) external;
143
+ function setIsBatchPoster(address addr, bool isBatchPoster_) external;
108
144
 
145
+ /**
146
+ * @notice Makes Data Availability Service keyset valid
147
+ * @param keysetBytes bytes of the serialized keyset
148
+ */
109
149
  function setValidKeyset(bytes calldata keysetBytes) external;
110
150
 
151
+ /**
152
+ * @notice Invalidates a Data Availability Service keyset
153
+ * @param ksHash hash of the keyset
154
+ */
111
155
  function invalidateKeysetHash(bytes32 ksHash) external;
156
+
157
+ // ---------- initializer ----------
158
+
159
+ function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;
112
160
  }