@arbitrum/nitro-contracts 1.0.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierrc +5 -0
- package/.solhint.json +18 -0
- package/deploy/BridgeStubCreator.js +10 -0
- package/deploy/HashProofHelper.js +13 -0
- package/deploy/InboxStubCreator.js +17 -0
- package/deploy/OneStepProofEntryCreator.js +19 -0
- package/deploy/OneStepProver0Creator.js +14 -0
- package/deploy/OneStepProverHostIoCreator.js +14 -0
- package/deploy/OneStepProverMathCreator.js +14 -0
- package/deploy/OneStepProverMemoryCreator.js +14 -0
- package/deploy/SequencerInboxStubCreator.js +13 -0
- package/deploy/ValueArrayTesterCreator.js +13 -0
- package/hardhat.config.ts +47 -0
- package/hardhat.prod-config.js +18 -0
- package/package.json +49 -0
- package/scripts/build.bash +5 -0
- package/src/bridge/Bridge.sol +168 -0
- package/src/bridge/IBridge.sol +68 -0
- package/src/bridge/IInbox.sol +80 -0
- package/src/bridge/IMessageProvider.sol +11 -0
- package/src/bridge/IOutbox.sol +52 -0
- package/src/bridge/ISequencerInbox.sol +85 -0
- package/src/bridge/Inbox.sol +414 -0
- package/src/bridge/Messages.sol +38 -0
- package/src/bridge/Outbox.sol +188 -0
- package/src/bridge/SequencerInbox.sol +274 -0
- package/src/challenge/ChallengeLib.sol +135 -0
- package/src/challenge/ChallengeManager.sol +367 -0
- package/src/challenge/IChallengeManager.sol +75 -0
- package/src/challenge/IChallengeResultReceiver.sol +13 -0
- package/src/libraries/AddressAliasHelper.sol +29 -0
- package/src/libraries/AdminFallbackProxy.sol +153 -0
- package/src/libraries/ArbitrumProxy.sol +20 -0
- package/src/libraries/Constants.sol +10 -0
- package/src/libraries/CryptographyPrimitives.sol +323 -0
- package/src/libraries/DelegateCallAware.sol +44 -0
- package/src/libraries/Error.sol +38 -0
- package/src/libraries/IGasRefunder.sol +35 -0
- package/src/libraries/MerkleLib.sol +46 -0
- package/src/libraries/MessageTypes.sol +14 -0
- package/src/libraries/SecondaryLogicUUPSUpgradeable.sol +58 -0
- package/src/libraries/UUPSNotUpgradeable.sol +56 -0
- package/src/mocks/BridgeStub.sol +115 -0
- package/src/mocks/Counter.sol +13 -0
- package/src/mocks/ExecutionManager.sol +41 -0
- package/src/mocks/InboxStub.sol +131 -0
- package/src/mocks/MockResultReceiver.sol +59 -0
- package/src/mocks/SequencerInboxStub.sol +42 -0
- package/src/mocks/SimpleProxy.sol +19 -0
- package/src/node-interface/NodeInterface.sol +50 -0
- package/src/osp/HashProofHelper.sol +154 -0
- package/src/osp/IOneStepProofEntry.sol +20 -0
- package/src/osp/IOneStepProver.sol +27 -0
- package/src/osp/OneStepProofEntry.sol +129 -0
- package/src/osp/OneStepProver0.sol +566 -0
- package/src/osp/OneStepProverHostIo.sol +357 -0
- package/src/osp/OneStepProverMath.sol +514 -0
- package/src/osp/OneStepProverMemory.sol +313 -0
- package/src/precompiles/ArbAddressTable.sol +60 -0
- package/src/precompiles/ArbAggregator.sol +62 -0
- package/src/precompiles/ArbBLS.sol +53 -0
- package/src/precompiles/ArbDebug.sol +39 -0
- package/src/precompiles/ArbFunctionTable.sol +29 -0
- package/src/precompiles/ArbGasInfo.sol +121 -0
- package/src/precompiles/ArbInfo.sol +15 -0
- package/src/precompiles/ArbOwner.sol +65 -0
- package/src/precompiles/ArbOwnerPublic.sol +18 -0
- package/src/precompiles/ArbRetryableTx.sol +89 -0
- package/src/precompiles/ArbStatistics.sol +29 -0
- package/src/precompiles/ArbSys.sol +134 -0
- package/src/precompiles/ArbosActs.sol +41 -0
- package/src/precompiles/ArbosTest.sol +14 -0
- package/src/rollup/BridgeCreator.sol +120 -0
- package/src/rollup/IRollupCore.sol +152 -0
- package/src/rollup/IRollupLogic.sol +183 -0
- package/src/rollup/Node.sol +99 -0
- package/src/rollup/RollupAdminLogic.sol +322 -0
- package/src/rollup/RollupCore.sol +627 -0
- package/src/rollup/RollupCreator.sol +133 -0
- package/src/rollup/RollupEventBridge.sol +46 -0
- package/src/rollup/RollupLib.sol +135 -0
- package/src/rollup/RollupUserLogic.sol +712 -0
- package/src/rollup/ValidatorUtils.sol +243 -0
- package/src/rollup/ValidatorWallet.sol +76 -0
- package/src/rollup/ValidatorWalletCreator.sol +43 -0
- package/src/state/Deserialize.sol +321 -0
- package/src/state/GlobalState.sol +44 -0
- package/src/state/Instructions.sol +159 -0
- package/src/state/Machine.sol +65 -0
- package/src/state/MerkleProof.sol +99 -0
- package/src/state/Module.sol +33 -0
- package/src/state/ModuleMemory.sol +42 -0
- package/src/state/PcArray.sol +45 -0
- package/src/state/PcStack.sol +32 -0
- package/src/state/StackFrame.sol +63 -0
- package/src/state/Value.sol +65 -0
- package/src/state/ValueArray.sol +47 -0
- package/src/state/ValueStack.sol +39 -0
- package/src/test-helpers/CryptographyPrimitivesTester.sol +27 -0
- package/src/test-helpers/MessageTester.sol +34 -0
- package/src/test-helpers/ValueArrayTester.sol +34 -0
- package/test/contract/arbRollup.spec.ts +869 -0
- package/test/contract/common/challengeLib.ts +43 -0
- package/test/contract/common/globalStateLib.ts +17 -0
- package/test/contract/common/rolluplib.ts +259 -0
- package/test/contract/cryptographyPrimitives.spec.ts +82 -0
- package/test/contract/sequencerInboxForceInclude.spec.ts +516 -0
- package/test/contract/utils.ts +40 -0
- package/test/prover/hash-proofs.ts +75 -0
- package/test/prover/one-step-proof.ts +93 -0
- package/test/prover/proofs/.gitkeep +0 -0
- package/test/prover/value-arrays.ts +11 -0
- package/tsconfig.json +13 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
// Copyright 2021-2022, Offchain Labs, Inc.
|
2
|
+
// For license information, see https://github.com/nitro/blob/master/LICENSE
|
3
|
+
// SPDX-License-Identifier: BUSL-1.1
|
4
|
+
|
5
|
+
pragma solidity ^0.8.0;
|
6
|
+
|
7
|
+
import "./Value.sol";
|
8
|
+
|
9
|
+
struct ValueArray {
|
10
|
+
Value[] inner;
|
11
|
+
}
|
12
|
+
|
13
|
+
library ValueArrayLib {
|
14
|
+
function get(ValueArray memory arr, uint256 index) internal pure returns (Value memory) {
|
15
|
+
return arr.inner[index];
|
16
|
+
}
|
17
|
+
|
18
|
+
function set(
|
19
|
+
ValueArray memory arr,
|
20
|
+
uint256 index,
|
21
|
+
Value memory val
|
22
|
+
) internal pure {
|
23
|
+
arr.inner[index] = val;
|
24
|
+
}
|
25
|
+
|
26
|
+
function length(ValueArray memory arr) internal pure returns (uint256) {
|
27
|
+
return arr.inner.length;
|
28
|
+
}
|
29
|
+
|
30
|
+
function push(ValueArray memory arr, Value memory val) internal pure {
|
31
|
+
Value[] memory newInner = new Value[](arr.inner.length + 1);
|
32
|
+
for (uint256 i = 0; i < arr.inner.length; i++) {
|
33
|
+
newInner[i] = arr.inner[i];
|
34
|
+
}
|
35
|
+
newInner[arr.inner.length] = val;
|
36
|
+
arr.inner = newInner;
|
37
|
+
}
|
38
|
+
|
39
|
+
function pop(ValueArray memory arr) internal pure returns (Value memory popped) {
|
40
|
+
popped = arr.inner[arr.inner.length - 1];
|
41
|
+
Value[] memory newInner = new Value[](arr.inner.length - 1);
|
42
|
+
for (uint256 i = 0; i < newInner.length; i++) {
|
43
|
+
newInner[i] = arr.inner[i];
|
44
|
+
}
|
45
|
+
arr.inner = newInner;
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// Copyright 2021-2022, Offchain Labs, Inc.
|
2
|
+
// For license information, see https://github.com/nitro/blob/master/LICENSE
|
3
|
+
// SPDX-License-Identifier: BUSL-1.1
|
4
|
+
|
5
|
+
pragma solidity ^0.8.0;
|
6
|
+
|
7
|
+
import "./Value.sol";
|
8
|
+
import "./ValueArray.sol";
|
9
|
+
|
10
|
+
struct ValueStack {
|
11
|
+
ValueArray proved;
|
12
|
+
bytes32 remainingHash;
|
13
|
+
}
|
14
|
+
|
15
|
+
library ValueStackLib {
|
16
|
+
using ValueLib for Value;
|
17
|
+
using ValueArrayLib for ValueArray;
|
18
|
+
|
19
|
+
function hash(ValueStack memory stack) internal pure returns (bytes32 h) {
|
20
|
+
h = stack.remainingHash;
|
21
|
+
uint256 len = stack.proved.length();
|
22
|
+
for (uint256 i = 0; i < len; i++) {
|
23
|
+
h = keccak256(abi.encodePacked("Value stack:", stack.proved.get(i).hash(), h));
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
function peek(ValueStack memory stack) internal pure returns (Value memory) {
|
28
|
+
uint256 len = stack.proved.length();
|
29
|
+
return stack.proved.get(len - 1);
|
30
|
+
}
|
31
|
+
|
32
|
+
function pop(ValueStack memory stack) internal pure returns (Value memory) {
|
33
|
+
return stack.proved.pop();
|
34
|
+
}
|
35
|
+
|
36
|
+
function push(ValueStack memory stack, Value memory val) internal pure {
|
37
|
+
return stack.proved.push(val);
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// Copyright 2021-2022, Offchain Labs, Inc.
|
2
|
+
// For license information, see https://github.com/nitro/blob/master/LICENSE
|
3
|
+
// SPDX-License-Identifier: BUSL-1.1
|
4
|
+
|
5
|
+
pragma solidity ^0.8.0;
|
6
|
+
|
7
|
+
import "../libraries/CryptographyPrimitives.sol";
|
8
|
+
|
9
|
+
library CryptographyPrimitivesTester {
|
10
|
+
function keccakF(uint256[25] memory input) public pure returns (uint256[25] memory) {
|
11
|
+
return CryptographyPrimitives.keccakF(input);
|
12
|
+
}
|
13
|
+
|
14
|
+
function sha256Block(bytes32[2] memory inputChunk, bytes32 hashState)
|
15
|
+
public
|
16
|
+
pure
|
17
|
+
returns (bytes32)
|
18
|
+
{
|
19
|
+
return
|
20
|
+
bytes32(
|
21
|
+
CryptographyPrimitives.sha256Block(
|
22
|
+
[uint256(inputChunk[0]), uint256(inputChunk[1])],
|
23
|
+
uint256(hashState)
|
24
|
+
)
|
25
|
+
);
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// Copyright 2021-2022, Offchain Labs, Inc.
|
2
|
+
// For license information, see https://github.com/nitro/blob/master/LICENSE
|
3
|
+
// SPDX-License-Identifier: BUSL-1.1
|
4
|
+
|
5
|
+
pragma solidity ^0.8.0;
|
6
|
+
|
7
|
+
import "../bridge/Messages.sol";
|
8
|
+
|
9
|
+
contract MessageTester {
|
10
|
+
function messageHash(
|
11
|
+
uint8 messageType,
|
12
|
+
address sender,
|
13
|
+
uint64 blockNumber,
|
14
|
+
uint64 timestamp,
|
15
|
+
uint256 inboxSeqNum,
|
16
|
+
uint256 gasPriceL1,
|
17
|
+
bytes32 messageDataHash
|
18
|
+
) public pure returns (bytes32) {
|
19
|
+
return
|
20
|
+
Messages.messageHash(
|
21
|
+
messageType,
|
22
|
+
sender,
|
23
|
+
blockNumber,
|
24
|
+
timestamp,
|
25
|
+
inboxSeqNum,
|
26
|
+
gasPriceL1,
|
27
|
+
messageDataHash
|
28
|
+
);
|
29
|
+
}
|
30
|
+
|
31
|
+
function accumulateInboxMessage(bytes32 inbox, bytes32 message) public pure returns (bytes32) {
|
32
|
+
return Messages.accumulateInboxMessage(inbox, message);
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// Copyright 2021-2022, Offchain Labs, Inc.
|
2
|
+
// For license information, see https://github.com/nitro/blob/master/LICENSE
|
3
|
+
// SPDX-License-Identifier: BUSL-1.1
|
4
|
+
|
5
|
+
pragma solidity ^0.8.0;
|
6
|
+
|
7
|
+
import "../state/ValueArray.sol";
|
8
|
+
|
9
|
+
contract ValueArrayTester {
|
10
|
+
using ValueArrayLib for ValueArray;
|
11
|
+
|
12
|
+
function test() external pure {
|
13
|
+
ValueArray memory arr = ValueArray(new Value[](2));
|
14
|
+
require(arr.length() == 2, "START_LEN");
|
15
|
+
arr.set(0, ValueLib.newI32(1));
|
16
|
+
arr.set(1, ValueLib.newI32(2));
|
17
|
+
arr.push(ValueLib.newI32(3));
|
18
|
+
require(arr.length() == 3, "PUSH_LEN");
|
19
|
+
for (uint256 i = 0; i < arr.length(); i++) {
|
20
|
+
Value memory val = arr.get(i);
|
21
|
+
require(val.valueType == ValueType.I32, "PUSH_VAL_TYPE");
|
22
|
+
require(val.contents == i + 1, "PUSH_VAL_CONTENTS");
|
23
|
+
}
|
24
|
+
Value memory popped = arr.pop();
|
25
|
+
require(popped.valueType == ValueType.I32, "POP_RET_TYPE");
|
26
|
+
require(popped.contents == 3, "POP_RET_CONTENTS");
|
27
|
+
require(arr.length() == 2, "POP_LEN");
|
28
|
+
for (uint256 i = 0; i < arr.length(); i++) {
|
29
|
+
Value memory val = arr.get(i);
|
30
|
+
require(val.valueType == ValueType.I32, "POP_VAL_TYPE");
|
31
|
+
require(val.contents == i + 1, "POP_VAL_CONTENTS");
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|