@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.
Files changed (113) hide show
  1. package/.prettierrc +5 -0
  2. package/.solhint.json +18 -0
  3. package/deploy/BridgeStubCreator.js +10 -0
  4. package/deploy/HashProofHelper.js +13 -0
  5. package/deploy/InboxStubCreator.js +17 -0
  6. package/deploy/OneStepProofEntryCreator.js +19 -0
  7. package/deploy/OneStepProver0Creator.js +14 -0
  8. package/deploy/OneStepProverHostIoCreator.js +14 -0
  9. package/deploy/OneStepProverMathCreator.js +14 -0
  10. package/deploy/OneStepProverMemoryCreator.js +14 -0
  11. package/deploy/SequencerInboxStubCreator.js +13 -0
  12. package/deploy/ValueArrayTesterCreator.js +13 -0
  13. package/hardhat.config.ts +47 -0
  14. package/hardhat.prod-config.js +18 -0
  15. package/package.json +49 -0
  16. package/scripts/build.bash +5 -0
  17. package/src/bridge/Bridge.sol +168 -0
  18. package/src/bridge/IBridge.sol +68 -0
  19. package/src/bridge/IInbox.sol +80 -0
  20. package/src/bridge/IMessageProvider.sol +11 -0
  21. package/src/bridge/IOutbox.sol +52 -0
  22. package/src/bridge/ISequencerInbox.sol +85 -0
  23. package/src/bridge/Inbox.sol +414 -0
  24. package/src/bridge/Messages.sol +38 -0
  25. package/src/bridge/Outbox.sol +188 -0
  26. package/src/bridge/SequencerInbox.sol +274 -0
  27. package/src/challenge/ChallengeLib.sol +135 -0
  28. package/src/challenge/ChallengeManager.sol +367 -0
  29. package/src/challenge/IChallengeManager.sol +75 -0
  30. package/src/challenge/IChallengeResultReceiver.sol +13 -0
  31. package/src/libraries/AddressAliasHelper.sol +29 -0
  32. package/src/libraries/AdminFallbackProxy.sol +153 -0
  33. package/src/libraries/ArbitrumProxy.sol +20 -0
  34. package/src/libraries/Constants.sol +10 -0
  35. package/src/libraries/CryptographyPrimitives.sol +323 -0
  36. package/src/libraries/DelegateCallAware.sol +44 -0
  37. package/src/libraries/Error.sol +38 -0
  38. package/src/libraries/IGasRefunder.sol +35 -0
  39. package/src/libraries/MerkleLib.sol +46 -0
  40. package/src/libraries/MessageTypes.sol +14 -0
  41. package/src/libraries/SecondaryLogicUUPSUpgradeable.sol +58 -0
  42. package/src/libraries/UUPSNotUpgradeable.sol +56 -0
  43. package/src/mocks/BridgeStub.sol +115 -0
  44. package/src/mocks/Counter.sol +13 -0
  45. package/src/mocks/ExecutionManager.sol +41 -0
  46. package/src/mocks/InboxStub.sol +131 -0
  47. package/src/mocks/MockResultReceiver.sol +59 -0
  48. package/src/mocks/SequencerInboxStub.sol +42 -0
  49. package/src/mocks/SimpleProxy.sol +19 -0
  50. package/src/node-interface/NodeInterface.sol +50 -0
  51. package/src/osp/HashProofHelper.sol +154 -0
  52. package/src/osp/IOneStepProofEntry.sol +20 -0
  53. package/src/osp/IOneStepProver.sol +27 -0
  54. package/src/osp/OneStepProofEntry.sol +129 -0
  55. package/src/osp/OneStepProver0.sol +566 -0
  56. package/src/osp/OneStepProverHostIo.sol +357 -0
  57. package/src/osp/OneStepProverMath.sol +514 -0
  58. package/src/osp/OneStepProverMemory.sol +313 -0
  59. package/src/precompiles/ArbAddressTable.sol +60 -0
  60. package/src/precompiles/ArbAggregator.sol +62 -0
  61. package/src/precompiles/ArbBLS.sol +53 -0
  62. package/src/precompiles/ArbDebug.sol +39 -0
  63. package/src/precompiles/ArbFunctionTable.sol +29 -0
  64. package/src/precompiles/ArbGasInfo.sol +121 -0
  65. package/src/precompiles/ArbInfo.sol +15 -0
  66. package/src/precompiles/ArbOwner.sol +65 -0
  67. package/src/precompiles/ArbOwnerPublic.sol +18 -0
  68. package/src/precompiles/ArbRetryableTx.sol +89 -0
  69. package/src/precompiles/ArbStatistics.sol +29 -0
  70. package/src/precompiles/ArbSys.sol +134 -0
  71. package/src/precompiles/ArbosActs.sol +41 -0
  72. package/src/precompiles/ArbosTest.sol +14 -0
  73. package/src/rollup/BridgeCreator.sol +120 -0
  74. package/src/rollup/IRollupCore.sol +152 -0
  75. package/src/rollup/IRollupLogic.sol +183 -0
  76. package/src/rollup/Node.sol +99 -0
  77. package/src/rollup/RollupAdminLogic.sol +322 -0
  78. package/src/rollup/RollupCore.sol +627 -0
  79. package/src/rollup/RollupCreator.sol +133 -0
  80. package/src/rollup/RollupEventBridge.sol +46 -0
  81. package/src/rollup/RollupLib.sol +135 -0
  82. package/src/rollup/RollupUserLogic.sol +712 -0
  83. package/src/rollup/ValidatorUtils.sol +243 -0
  84. package/src/rollup/ValidatorWallet.sol +76 -0
  85. package/src/rollup/ValidatorWalletCreator.sol +43 -0
  86. package/src/state/Deserialize.sol +321 -0
  87. package/src/state/GlobalState.sol +44 -0
  88. package/src/state/Instructions.sol +159 -0
  89. package/src/state/Machine.sol +65 -0
  90. package/src/state/MerkleProof.sol +99 -0
  91. package/src/state/Module.sol +33 -0
  92. package/src/state/ModuleMemory.sol +42 -0
  93. package/src/state/PcArray.sol +45 -0
  94. package/src/state/PcStack.sol +32 -0
  95. package/src/state/StackFrame.sol +63 -0
  96. package/src/state/Value.sol +65 -0
  97. package/src/state/ValueArray.sol +47 -0
  98. package/src/state/ValueStack.sol +39 -0
  99. package/src/test-helpers/CryptographyPrimitivesTester.sol +27 -0
  100. package/src/test-helpers/MessageTester.sol +34 -0
  101. package/src/test-helpers/ValueArrayTester.sol +34 -0
  102. package/test/contract/arbRollup.spec.ts +869 -0
  103. package/test/contract/common/challengeLib.ts +43 -0
  104. package/test/contract/common/globalStateLib.ts +17 -0
  105. package/test/contract/common/rolluplib.ts +259 -0
  106. package/test/contract/cryptographyPrimitives.spec.ts +82 -0
  107. package/test/contract/sequencerInboxForceInclude.spec.ts +516 -0
  108. package/test/contract/utils.ts +40 -0
  109. package/test/prover/hash-proofs.ts +75 -0
  110. package/test/prover/one-step-proof.ts +93 -0
  111. package/test/prover/proofs/.gitkeep +0 -0
  112. package/test/prover/value-arrays.ts +11 -0
  113. package/tsconfig.json +13 -0
@@ -0,0 +1,183 @@
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 "./RollupLib.sol";
8
+ import "./IRollupCore.sol";
9
+ import "../bridge/ISequencerInbox.sol";
10
+ import "../bridge/IOutbox.sol";
11
+
12
+ interface IRollupUserAbs is IRollupCore {
13
+ /// @dev the user logic just validated configuration and shouldn't write to state during init
14
+ /// this allows the admin logic to ensure consistency on parameters.
15
+ function initialize(address stakeToken) external view;
16
+
17
+ function isERC20Enabled() external view returns (bool);
18
+
19
+ function returnOldDeposit(address stakerAddress) external;
20
+
21
+ function requireUnresolved(uint256 nodeNum) external view;
22
+
23
+ function requireUnresolvedExists() external view;
24
+
25
+ function countStakedZombies(uint64 nodeNum) external view returns (uint256);
26
+
27
+ function countZombiesStakedOnChildren(uint64 nodeNum) external view returns (uint256);
28
+ }
29
+
30
+ interface IRollupUser is IRollupUserAbs {
31
+ function newStakeOnExistingNode(uint64 nodeNum, bytes32 nodeHash) external payable;
32
+
33
+ function newStakeOnNewNode(
34
+ RollupLib.Assertion calldata assertion,
35
+ bytes32 expectedNodeHash,
36
+ uint256 prevNodeInboxMaxCount
37
+ ) external payable;
38
+ }
39
+
40
+ interface IRollupUserERC20 is IRollupUserAbs {
41
+ function newStakeOnExistingNode(
42
+ uint256 tokenAmount,
43
+ uint64 nodeNum,
44
+ bytes32 nodeHash
45
+ ) external;
46
+
47
+ function newStakeOnNewNode(
48
+ uint256 tokenAmount,
49
+ RollupLib.Assertion calldata assertion,
50
+ bytes32 expectedNodeHash,
51
+ uint256 prevNodeInboxMaxCount
52
+ ) external;
53
+ }
54
+
55
+ interface IRollupAdmin {
56
+ event OwnerFunctionCalled(uint256 indexed id);
57
+
58
+ function initialize(Config calldata config, ContractDependencies calldata connectedContracts)
59
+ external;
60
+
61
+ /**
62
+ * @notice Add a contract authorized to put messages into this rollup's inbox
63
+ * @param _outbox Outbox contract to add
64
+ */
65
+ function setOutbox(IOutbox _outbox) external;
66
+
67
+ /**
68
+ * @notice Disable an old outbox from interacting with the bridge
69
+ * @param _outbox Outbox contract to remove
70
+ */
71
+ function removeOldOutbox(address _outbox) external;
72
+
73
+ /**
74
+ * @notice Enable or disable an inbox contract
75
+ * @param _inbox Inbox contract to add or remove
76
+ * @param _enabled New status of inbox
77
+ */
78
+ function setInbox(address _inbox, bool _enabled) external;
79
+
80
+ /**
81
+ * @notice Pause interaction with the rollup contract
82
+ */
83
+ function pause() external;
84
+
85
+ /**
86
+ * @notice Resume interaction with the rollup contract
87
+ */
88
+ function resume() external;
89
+
90
+ /**
91
+ * @notice Set the addresses of the validator whitelist
92
+ * @dev It is expected that both arrays are same length, and validator at
93
+ * position i corresponds to the value at position i
94
+ * @param _validator addresses to set in the whitelist
95
+ * @param _val value to set in the whitelist for corresponding address
96
+ */
97
+ function setValidator(address[] memory _validator, bool[] memory _val) external;
98
+
99
+ /**
100
+ * @notice Set a new owner address for the rollup proxy
101
+ * @param newOwner address of new rollup owner
102
+ */
103
+ function setOwner(address newOwner) external;
104
+
105
+ /**
106
+ * @notice Set minimum assertion period for the rollup
107
+ * @param newPeriod new minimum period for assertions
108
+ */
109
+ function setMinimumAssertionPeriod(uint256 newPeriod) external;
110
+
111
+ /**
112
+ * @notice Set number of blocks until a node is considered confirmed
113
+ * @param newConfirmPeriod new number of blocks until a node is confirmed
114
+ */
115
+ function setConfirmPeriodBlocks(uint64 newConfirmPeriod) external;
116
+
117
+ /**
118
+ * @notice Set number of extra blocks after a challenge
119
+ * @param newExtraTimeBlocks new number of blocks
120
+ */
121
+ function setExtraChallengeTimeBlocks(uint64 newExtraTimeBlocks) external;
122
+
123
+ /**
124
+ * @notice Set base stake required for an assertion
125
+ * @param newBaseStake maximum avmgas to be used per block
126
+ */
127
+ function setBaseStake(uint256 newBaseStake) external;
128
+
129
+ /**
130
+ * @notice Set the token used for stake, where address(0) == eth
131
+ * @dev Before changing the base stake token, you might need to change the
132
+ * implementation of the Rollup User logic!
133
+ * @param newStakeToken address of token used for staking
134
+ */
135
+ function setStakeToken(address newStakeToken) external;
136
+
137
+ /**
138
+ * @notice Set max time variation from actual time for sequencer inbox
139
+ * @param maxTimeVariation the maximum time variation parameters
140
+ */
141
+ function setSequencerInboxMaxTimeVariation(
142
+ ISequencerInbox.MaxTimeVariation memory maxTimeVariation
143
+ ) external;
144
+
145
+ /**
146
+ * @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
147
+ * @param addr the address
148
+ * @param isBatchPoster if the specified address should be authorized as a batch poster
149
+ */
150
+ function setIsBatchPoster(address addr, bool isBatchPoster) external;
151
+
152
+ /**
153
+ * @notice Upgrades the implementation of a beacon controlled by the rollup
154
+ * @param beacon address of beacon to be upgraded
155
+ * @param newImplementation new address of implementation
156
+ */
157
+ function upgradeBeacon(address beacon, address newImplementation) external;
158
+
159
+ function forceResolveChallenge(address[] memory stackerA, address[] memory stackerB) external;
160
+
161
+ function forceRefundStaker(address[] memory stacker) external;
162
+
163
+ function forceCreateNode(
164
+ uint64 prevNode,
165
+ uint256 prevNodeInboxMaxCount,
166
+ RollupLib.Assertion memory assertion,
167
+ bytes32 expectedNodeHash
168
+ ) external;
169
+
170
+ function forceConfirmNode(
171
+ uint64 nodeNum,
172
+ bytes32 blockHash,
173
+ bytes32 sendRoot
174
+ ) external;
175
+
176
+ function setLoserStakeEscrow(address newLoserStakerEscrow) external;
177
+
178
+ /**
179
+ * @notice Set the proving WASM module root
180
+ * @param newWasmModuleRoot new module root
181
+ */
182
+ function setWasmModuleRoot(bytes32 newWasmModuleRoot) external;
183
+ }
@@ -0,0 +1,99 @@
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
+ struct Node {
8
+ // Hash of the state of the chain as of this node
9
+ bytes32 stateHash;
10
+ // Hash of the data that can be challenged
11
+ bytes32 challengeHash;
12
+ // Hash of the data that will be committed if this node is confirmed
13
+ bytes32 confirmData;
14
+ // Index of the node previous to this one
15
+ uint64 prevNum;
16
+ // Deadline at which this node can be confirmed
17
+ uint64 deadlineBlock;
18
+ // Deadline at which a child of this node can be confirmed
19
+ uint64 noChildConfirmedBeforeBlock;
20
+ // Number of stakers staked on this node. This includes real stakers and zombies
21
+ uint64 stakerCount;
22
+ // Number of stakers staked on a child node. This includes real stakers and zombies
23
+ uint64 childStakerCount;
24
+ // This value starts at zero and is set to a value when the first child is created. After that it is constant until the node is destroyed or the owner destroys pending nodes
25
+ uint64 firstChildBlock;
26
+ // The number of the latest child of this node to be created
27
+ uint64 latestChildNumber;
28
+ // The block number when this node was created
29
+ uint64 createdAtBlock;
30
+ // A hash of all the data needed to determine this node's validity, to protect against reorgs
31
+ bytes32 nodeHash;
32
+ }
33
+
34
+ /**
35
+ * @notice Utility functions for Node
36
+ */
37
+ library NodeLib {
38
+ /**
39
+ * @notice Initialize a Node
40
+ * @param _stateHash Initial value of stateHash
41
+ * @param _challengeHash Initial value of challengeHash
42
+ * @param _confirmData Initial value of confirmData
43
+ * @param _prevNum Initial value of prevNum
44
+ * @param _deadlineBlock Initial value of deadlineBlock
45
+ * @param _nodeHash Initial value of nodeHash
46
+ */
47
+ function createNode(
48
+ bytes32 _stateHash,
49
+ bytes32 _challengeHash,
50
+ bytes32 _confirmData,
51
+ uint64 _prevNum,
52
+ uint64 _deadlineBlock,
53
+ bytes32 _nodeHash
54
+ ) internal view returns (Node memory) {
55
+ Node memory node;
56
+ node.stateHash = _stateHash;
57
+ node.challengeHash = _challengeHash;
58
+ node.confirmData = _confirmData;
59
+ node.prevNum = _prevNum;
60
+ node.deadlineBlock = _deadlineBlock;
61
+ node.noChildConfirmedBeforeBlock = _deadlineBlock;
62
+ node.createdAtBlock = uint64(block.number);
63
+ node.nodeHash = _nodeHash;
64
+ return node;
65
+ }
66
+
67
+ /**
68
+ * @notice Update child properties
69
+ * @param number The child number to set
70
+ */
71
+ function childCreated(Node storage self, uint64 number) internal {
72
+ if (self.firstChildBlock == 0) {
73
+ self.firstChildBlock = uint64(block.number);
74
+ }
75
+ self.latestChildNumber = number;
76
+ }
77
+
78
+ /**
79
+ * @notice Update the child confirmed deadline
80
+ * @param deadline The new deadline to set
81
+ */
82
+ function newChildConfirmDeadline(Node storage self, uint64 deadline) internal {
83
+ self.noChildConfirmedBeforeBlock = deadline;
84
+ }
85
+
86
+ /**
87
+ * @notice Check whether the current block number has met or passed the node's deadline
88
+ */
89
+ function requirePastDeadline(Node memory self) internal view {
90
+ require(block.number >= self.deadlineBlock, "BEFORE_DEADLINE");
91
+ }
92
+
93
+ /**
94
+ * @notice Check whether the current block number has met or passed deadline for children of this node to be confirmed
95
+ */
96
+ function requirePastChildConfirmDeadline(Node memory self) internal view {
97
+ require(block.number >= self.noChildConfirmedBeforeBlock, "CHILD_TOO_RECENT");
98
+ }
99
+ }
@@ -0,0 +1,322 @@
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 {IRollupAdmin, IRollupUser} from "./IRollupLogic.sol";
8
+ import "./RollupCore.sol";
9
+ import "../bridge/IOutbox.sol";
10
+ import "../bridge/ISequencerInbox.sol";
11
+ import "../challenge/IChallengeManager.sol";
12
+ import "../libraries/SecondaryLogicUUPSUpgradeable.sol";
13
+ import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
14
+
15
+ import {NO_CHAL_INDEX} from "../libraries/Constants.sol";
16
+
17
+ contract RollupAdminLogic is RollupCore, IRollupAdmin, SecondaryLogicUUPSUpgradeable {
18
+ function initialize(Config calldata config, ContractDependencies calldata connectedContracts)
19
+ external
20
+ override
21
+ onlyProxy
22
+ initializer
23
+ {
24
+ delayedBridge = connectedContracts.delayedBridge;
25
+ sequencerBridge = connectedContracts.sequencerInbox;
26
+ outbox = connectedContracts.outbox;
27
+ delayedBridge.setOutbox(address(connectedContracts.outbox), true);
28
+ rollupEventBridge = connectedContracts.rollupEventBridge;
29
+ delayedBridge.setInbox(address(connectedContracts.rollupEventBridge), true);
30
+
31
+ rollupEventBridge.rollupInitialized(config.chainId);
32
+ sequencerBridge.addSequencerL2Batch(0, "", 1, IGasRefunder(address(0)));
33
+
34
+ challengeManager = connectedContracts.challengeManager;
35
+
36
+ Node memory node = createInitialNode();
37
+ initializeCore(node);
38
+
39
+ confirmPeriodBlocks = config.confirmPeriodBlocks;
40
+ extraChallengeTimeBlocks = config.extraChallengeTimeBlocks;
41
+ chainId = config.chainId;
42
+ baseStake = config.baseStake;
43
+ wasmModuleRoot = config.wasmModuleRoot;
44
+ // A little over 15 minutes
45
+ minimumAssertionPeriod = 75;
46
+
47
+ // the owner can't access the rollup user facet where escrow is redeemable
48
+ require(config.loserStakeEscrow != _getAdmin(), "INVALID_ESCROW_ADMIN");
49
+ // this next check shouldn't be an issue if the owner controls an AdminProxy
50
+ // that accesses the admin facet, but still seems like a good extra precaution
51
+ require(config.loserStakeEscrow != config.owner, "INVALID_ESCROW_OWNER");
52
+ loserStakeEscrow = config.loserStakeEscrow;
53
+
54
+ stakeToken = config.stakeToken;
55
+
56
+ sequencerBridge.setMaxTimeVariation(config.sequencerInboxMaxTimeVariation);
57
+
58
+ emit RollupInitialized(config.wasmModuleRoot, config.chainId);
59
+ }
60
+
61
+ function createInitialNode() private view returns (Node memory) {
62
+ GlobalState memory emptyGlobalState;
63
+ bytes32 state = RollupLib.stateHashMem(
64
+ RollupLib.ExecutionState(emptyGlobalState, MachineStatus.FINISHED),
65
+ 1 // inboxMaxCount - force the first assertion to read a message
66
+ );
67
+ return
68
+ NodeLib.createNode(
69
+ state,
70
+ 0, // challenge hash (not challengeable)
71
+ 0, // confirm data
72
+ 0, // prev node
73
+ uint64(block.number), // deadline block (not challengeable)
74
+ 0 // initial node has a node hash of 0
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Functions are only to reach this logic contract if the caller is the owner
80
+ * so there is no need for a redundant onlyOwner check
81
+ */
82
+
83
+ /**
84
+ * @notice Add a contract authorized to put messages into this rollup's inbox
85
+ * @param _outbox Outbox contract to add
86
+ */
87
+ function setOutbox(IOutbox _outbox) external override {
88
+ outbox = _outbox;
89
+ delayedBridge.setOutbox(address(_outbox), true);
90
+ emit OwnerFunctionCalled(0);
91
+ }
92
+
93
+ /**
94
+ * @notice Disable an old outbox from interacting with the bridge
95
+ * @param _outbox Outbox contract to remove
96
+ */
97
+ function removeOldOutbox(address _outbox) external override {
98
+ require(_outbox != address(outbox), "CUR_OUTBOX");
99
+ delayedBridge.setOutbox(_outbox, false);
100
+ emit OwnerFunctionCalled(1);
101
+ }
102
+
103
+ /**
104
+ * @notice Enable or disable an inbox contract
105
+ * @param _inbox Inbox contract to add or remove
106
+ * @param _enabled New status of inbox
107
+ */
108
+ function setInbox(address _inbox, bool _enabled) external override {
109
+ delayedBridge.setInbox(address(_inbox), _enabled);
110
+ emit OwnerFunctionCalled(2);
111
+ }
112
+
113
+ /**
114
+ * @notice Pause interaction with the rollup contract.
115
+ * The time spent paused is not incremented in the rollup's timing for node validation.
116
+ */
117
+ function pause() external override {
118
+ _pause();
119
+ emit OwnerFunctionCalled(3);
120
+ }
121
+
122
+ /**
123
+ * @notice Resume interaction with the rollup contract
124
+ */
125
+ function resume() external override {
126
+ _unpause();
127
+ emit OwnerFunctionCalled(4);
128
+ }
129
+
130
+ /// @notice allows the admin to upgrade the primary logic contract (ie rollup admin logic, aka this)
131
+ /// @dev this function doesn't revert as this primary logic contract is only
132
+ /// reachable by the proxy's admin
133
+ function _authorizeUpgrade(address newImplementation) internal override {}
134
+
135
+ /// @notice allows the admin to upgrade the secondary logic contract (ie rollup user logic)
136
+ /// @dev this function doesn't revert as this primary logic contract is only
137
+ /// reachable by the proxy's admin
138
+ function _authorizeSecondaryUpgrade(address newImplementation) internal override {}
139
+
140
+ /**
141
+ * @notice Set the addresses of the validator whitelist
142
+ * @dev It is expected that both arrays are same length, and validator at
143
+ * position i corresponds to the value at position i
144
+ * @param _validator addresses to set in the whitelist
145
+ * @param _val value to set in the whitelist for corresponding address
146
+ */
147
+ function setValidator(address[] calldata _validator, bool[] calldata _val) external override {
148
+ require(_validator.length == _val.length, "WRONG_LENGTH");
149
+
150
+ for (uint256 i = 0; i < _validator.length; i++) {
151
+ isValidator[_validator[i]] = _val[i];
152
+ }
153
+ emit OwnerFunctionCalled(6);
154
+ }
155
+
156
+ /**
157
+ * @notice Set a new owner address for the rollup
158
+ * @dev it is expected that only the rollup admin can use this facet to set a new owner
159
+ * @param newOwner address of new rollup owner
160
+ */
161
+ function setOwner(address newOwner) external override {
162
+ _changeAdmin(newOwner);
163
+ emit OwnerFunctionCalled(7);
164
+ }
165
+
166
+ /**
167
+ * @notice Set minimum assertion period for the rollup
168
+ * @param newPeriod new minimum period for assertions
169
+ */
170
+ function setMinimumAssertionPeriod(uint256 newPeriod) external override {
171
+ minimumAssertionPeriod = newPeriod;
172
+ emit OwnerFunctionCalled(8);
173
+ }
174
+
175
+ /**
176
+ * @notice Set number of blocks until a node is considered confirmed
177
+ * @param newConfirmPeriod new number of blocks
178
+ */
179
+ function setConfirmPeriodBlocks(uint64 newConfirmPeriod) external override {
180
+ confirmPeriodBlocks = newConfirmPeriod;
181
+ emit OwnerFunctionCalled(9);
182
+ }
183
+
184
+ /**
185
+ * @notice Set number of extra blocks after a challenge
186
+ * @param newExtraTimeBlocks new number of blocks
187
+ */
188
+ function setExtraChallengeTimeBlocks(uint64 newExtraTimeBlocks) external override {
189
+ extraChallengeTimeBlocks = newExtraTimeBlocks;
190
+ emit OwnerFunctionCalled(10);
191
+ }
192
+
193
+ /**
194
+ * @notice Set base stake required for an assertion
195
+ * @param newBaseStake minimum amount of stake required
196
+ */
197
+ function setBaseStake(uint256 newBaseStake) external override {
198
+ baseStake = newBaseStake;
199
+ emit OwnerFunctionCalled(12);
200
+ }
201
+
202
+ /**
203
+ * @notice Set the token used for stake, where address(0) == eth
204
+ * @dev Before changing the base stake token, you might need to change the
205
+ * implementation of the Rollup User facet!
206
+ * @param newStakeToken address of token used for staking
207
+ */
208
+ function setStakeToken(address newStakeToken) external override whenPaused {
209
+ /*
210
+ * To change the stake token without breaking consistency one would need to:
211
+ * Pause the system, have all stakers remove their funds,
212
+ * update the user logic to handle ERC20s, change the stake token, then resume.
213
+ *
214
+ * Note: To avoid loss of funds stakers must remove their funds and claim all the
215
+ * available withdrawable funds before the system is paused.
216
+ */
217
+ bool expectERC20Support = newStakeToken != address(0);
218
+ // this assumes the rollup isn't its own admin. if needed, instead use a ProxyAdmin by OZ!
219
+ bool actualERC20Support = IRollupUser(address(this)).isERC20Enabled();
220
+ require(actualERC20Support == expectERC20Support, "NO_USER_LOGIC_SUPPORT");
221
+ require(stakerCount() == 0, "NO_ACTIVE_STAKERS");
222
+ require(totalWithdrawableFunds == 0, "NO_PENDING_WITHDRAW");
223
+ stakeToken = newStakeToken;
224
+ emit OwnerFunctionCalled(13);
225
+ }
226
+
227
+ /**
228
+ * @notice Set max delay for sequencer inbox
229
+ * @param maxTimeVariation the maximum time variation parameters
230
+ */
231
+ function setSequencerInboxMaxTimeVariation(
232
+ ISequencerInbox.MaxTimeVariation calldata maxTimeVariation
233
+ ) external override {
234
+ sequencerBridge.setMaxTimeVariation(maxTimeVariation);
235
+ emit OwnerFunctionCalled(14);
236
+ }
237
+
238
+ /**
239
+ * @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
240
+ * @param addr the address
241
+ * @param isBatchPoster if the specified address should be authorized as a batch poster
242
+ */
243
+ function setIsBatchPoster(address addr, bool isBatchPoster) external override {
244
+ ISequencerInbox(sequencerBridge).setIsBatchPoster(addr, isBatchPoster);
245
+ emit OwnerFunctionCalled(19);
246
+ }
247
+
248
+ /**
249
+ * @notice Upgrades the implementation of a beacon controlled by the rollup
250
+ * @param beacon address of beacon to be upgraded
251
+ * @param newImplementation new address of implementation
252
+ */
253
+ function upgradeBeacon(address beacon, address newImplementation) external override {
254
+ UpgradeableBeacon(beacon).upgradeTo(newImplementation);
255
+ emit OwnerFunctionCalled(20);
256
+ }
257
+
258
+ function forceResolveChallenge(address[] calldata stakerA, address[] calldata stakerB)
259
+ external
260
+ override
261
+ whenPaused
262
+ {
263
+ require(stakerA.length == stakerB.length, "WRONG_LENGTH");
264
+ for (uint256 i = 0; i < stakerA.length; i++) {
265
+ uint64 chall = inChallenge(stakerA[i], stakerB[i]);
266
+
267
+ require(chall != NO_CHAL_INDEX, "NOT_IN_CHALL");
268
+ clearChallenge(stakerA[i]);
269
+ clearChallenge(stakerB[i]);
270
+ challengeManager.clearChallenge(chall);
271
+ }
272
+ emit OwnerFunctionCalled(21);
273
+ }
274
+
275
+ function forceRefundStaker(address[] calldata staker) external override whenPaused {
276
+ for (uint256 i = 0; i < staker.length; i++) {
277
+ reduceStakeTo(staker[i], 0);
278
+ turnIntoZombie(staker[i]);
279
+ }
280
+ emit OwnerFunctionCalled(22);
281
+ }
282
+
283
+ function forceCreateNode(
284
+ uint64 prevNode,
285
+ uint256 prevNodeInboxMaxCount,
286
+ RollupLib.Assertion calldata assertion,
287
+ bytes32 expectedNodeHash
288
+ ) external override whenPaused {
289
+ require(prevNode == latestConfirmed(), "ONLY_LATEST_CONFIRMED");
290
+
291
+ createNewNode(assertion, prevNode, prevNodeInboxMaxCount, expectedNodeHash);
292
+
293
+ emit OwnerFunctionCalled(23);
294
+ }
295
+
296
+ function forceConfirmNode(
297
+ uint64 nodeNum,
298
+ bytes32 blockHash,
299
+ bytes32 sendRoot
300
+ ) external override whenPaused {
301
+ // this skips deadline, staker and zombie validation
302
+ confirmNode(nodeNum, blockHash, sendRoot);
303
+ emit OwnerFunctionCalled(24);
304
+ }
305
+
306
+ function setLoserStakeEscrow(address newLoserStakerEscrow) external override {
307
+ // escrow holder can't be proxy admin, since escrow is only redeemable through
308
+ // the primary user logic contract
309
+ require(newLoserStakerEscrow != _getAdmin(), "INVALID_ESCROW");
310
+ loserStakeEscrow = newLoserStakerEscrow;
311
+ emit OwnerFunctionCalled(25);
312
+ }
313
+
314
+ /**
315
+ * @notice Set the proving WASM module root
316
+ * @param newWasmModuleRoot new module root
317
+ */
318
+ function setWasmModuleRoot(bytes32 newWasmModuleRoot) external override {
319
+ wasmModuleRoot = newWasmModuleRoot;
320
+ emit OwnerFunctionCalled(26);
321
+ }
322
+ }