Skip to content

Commit 00b1c59

Browse files
gzeonethyahgwairauljordan
authored
chore: port nitro contracts pr (#401)
Co-authored-by: Chris Buckland <[email protected]> Co-authored-by: Raul Jordan <[email protected]>
1 parent 39444a1 commit 00b1c59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1378
-690
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ contracts/cache
2828
contracts/out
2929
contracts/formatter.sh
3030
contracts/build
31+
contracts/test/storage/*-old.dot
3132

3233
.DS_Store
3334
.env

contracts/src/bridge/Bridge.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
230230
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
231231
bool alreadyEnabled = info.allowed;
232232
emit InboxToggle(inbox, enabled);
233-
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
233+
if (alreadyEnabled == enabled) {
234234
return;
235235
}
236236
if (enabled) {
@@ -252,7 +252,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
252252
InOutInfo storage info = allowedOutboxesMap[outbox];
253253
bool alreadyEnabled = info.allowed;
254254
emit OutboxToggle(outbox, enabled);
255-
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
255+
if (alreadyEnabled == enabled) {
256256
return;
257257
}
258258
if (enabled) {

contracts/src/bridge/ISequencerInbox.sol

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ interface ISequencerInbox is IDelayedMessageProvider {
6969

7070
function isBatchPoster(address) external view returns (bool);
7171

72+
function isSequencer(address) external view returns (bool);
73+
7274
struct DasKeySetInfo {
7375
bool isValidKeyset;
7476
uint64 creationBlock;
7577
}
7678

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);
79+
function maxTimeVariation()
80+
external
81+
view
82+
returns (
83+
uint256,
84+
uint256,
85+
uint256,
86+
uint256
87+
);
88+
89+
function dasKeySetInfo(bytes32) external view returns (bool, uint64);
8090

8191
/// @notice Remove force inclusion delay after a L1 chainId fork
8292
function removeDelayAfterFork() external;
@@ -154,6 +164,14 @@ interface ISequencerInbox is IDelayedMessageProvider {
154164
*/
155165
function invalidateKeysetHash(bytes32 ksHash) external;
156166

167+
/**
168+
* @notice Updates whether an address is authorized to be a sequencer.
169+
* @dev The IsSequencer information is used only off-chain by the nitro node to validate sequencer feed signer.
170+
* @param addr the address
171+
* @param isSequencer_ if the specified address should be authorized as a sequencer
172+
*/
173+
function setIsSequencer(address addr, bool isSequencer_) external;
174+
157175
// ---------- initializer ----------
158176

159177
function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;

contracts/src/bridge/Inbox.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
352352
nonce,
353353
uint256(uint160(address(100))), // ArbSys address
354354
value,
355-
abi.encode(ArbSys.withdrawEth.selector, withdrawTo)
355+
abi.encodeWithSelector(ArbSys.withdrawEth.selector, withdrawTo)
356356
)
357357
);
358358
}

contracts/src/bridge/SequencerInbox.sol

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import "./IInbox.sol";
2727
import "./ISequencerInbox.sol";
2828
import "../rollup/IRollupLogic.sol";
2929
import "./Messages.sol";
30+
import "../precompiles/ArbGasInfo.sol";
31+
import "../precompiles/ArbSys.sol";
3032

3133
import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";
3234
import {GasRefundEnabled, IGasRefunder} from "../libraries/IGasRefunder.sol";
3335
import "../libraries/DelegateCallAware.sol";
36+
import "../libraries/ArbitrumChecker.sol";
3437
import {MAX_DATA_SIZE} from "../libraries/Constants.sol";
3538

3639
/**
@@ -64,6 +67,11 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
6467

6568
uint256 internal immutable deployTimeChainId = block.chainid;
6669

70+
mapping(address => bool) public isSequencer;
71+
72+
// If the chain this SequencerInbox is deployed on is an Arbitrum chain.
73+
bool internal immutable hostChainIsArbitrum = ArbitrumChecker.runningOnArbitrum();
74+
6775
function _chainIdChanged() internal view returns (bool) {
6876
return deployTimeChainId != block.chainid;
6977
}
@@ -385,13 +393,29 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
385393
// this msg isn't included in the current sequencer batch, but instead added to
386394
// the delayed messages queue that is yet to be included
387395
address batchPoster = msg.sender;
388-
bytes memory spendingReportMsg = abi.encodePacked(
389-
block.timestamp,
390-
batchPoster,
391-
dataHash,
392-
seqMessageIndex,
393-
block.basefee
394-
);
396+
bytes memory spendingReportMsg;
397+
if (hostChainIsArbitrum) {
398+
// Include extra gas for the host chain's L1 gas charging
399+
uint256 l1Fees = ArbGasInfo(address(0x6c)).getCurrentTxL1GasFees();
400+
uint256 extraGas = l1Fees / block.basefee;
401+
require(extraGas <= type(uint64).max, "L1_GAS_NOT_UINT64");
402+
spendingReportMsg = abi.encodePacked(
403+
block.timestamp,
404+
batchPoster,
405+
dataHash,
406+
seqMessageIndex,
407+
block.basefee,
408+
uint64(extraGas)
409+
);
410+
} else {
411+
spendingReportMsg = abi.encodePacked(
412+
block.timestamp,
413+
batchPoster,
414+
dataHash,
415+
seqMessageIndex,
416+
block.basefee
417+
);
418+
}
395419
uint256 msgNum = bridge.submitBatchSpendingReport(
396420
batchPoster,
397421
keccak256(spendingReportMsg)
@@ -431,9 +455,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
431455
require(keysetBytes.length < 64 * 1024, "keyset is too large");
432456

433457
if (dasKeySetInfo[ksHash].isValidKeyset) revert AlreadyValidDASKeyset(ksHash);
458+
uint256 creationBlock = block.number;
459+
if (hostChainIsArbitrum) {
460+
creationBlock = ArbSys(address(100)).arbBlockNumber();
461+
}
434462
dasKeySetInfo[ksHash] = DasKeySetInfo({
435463
isValidKeyset: true,
436-
creationBlock: uint64(block.number)
464+
creationBlock: uint64(creationBlock)
437465
});
438466
emit SetValidKeyset(ksHash, keysetBytes);
439467
emit OwnerFunctionCalled(2);
@@ -450,6 +478,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
450478
emit OwnerFunctionCalled(3);
451479
}
452480

481+
/// @inheritdoc ISequencerInbox
482+
function setIsSequencer(address addr, bool isSequencer_) external onlyRollupOwner {
483+
isSequencer[addr] = isSequencer_;
484+
emit OwnerFunctionCalled(4);
485+
}
486+
453487
function isValidKeysetHash(bytes32 ksHash) external view returns (bool) {
454488
return dasKeySetInfo[ksHash].isValidKeyset;
455489
}

contracts/src/libraries/AdminFallbackProxy.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ contract AdminFallbackProxy is Proxy, DoubleLogicERC1967Upgrade {
107107
* Only the `adminAddr` is able to use the `adminLogic` functions
108108
* All other addresses can interact with the `userLogic` functions
109109
*/
110-
constructor(
110+
function _initialize(
111111
address adminLogic,
112112
bytes memory adminData,
113113
address userLogic,
114114
bytes memory userData,
115115
address adminAddr
116-
) payable {
116+
) internal {
117117
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
118118
assert(
119119
_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 "../precompiles/ArbSys.sol";
8+
9+
library ArbitrumChecker {
10+
function runningOnArbitrum() internal view returns (bool) {
11+
(bool ok, bytes memory data) = address(100).staticcall(
12+
abi.encodeWithSelector(ArbSys.arbOSVersion.selector)
13+
);
14+
return ok && data.length == 32;
15+
}
16+
}

contracts/src/libraries/IGasRefunder.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ abstract contract GasRefundEnabled {
2121
uint256 startGasLeft = gasleft();
2222
_;
2323
if (address(gasRefunder) != address(0)) {
24-
uint256 calldataSize;
25-
assembly {
26-
calldataSize := calldatasize()
27-
}
24+
uint256 calldataSize = msg.data.length;
2825
uint256 calldataWords = (calldataSize + 31) / 32;
2926
// account for the CALLDATACOPY cost of the proxy contract, including the memory expansion cost
3027
// memory_expansion_cost = (memory_size_word ** 2) / 512 + (3 * memory_size_word)

contracts/src/mocks/BridgeStub.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ contract BridgeStub is IBridge {
139139
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
140140
bool alreadyEnabled = info.allowed;
141141
emit InboxToggle(inbox, enabled);
142-
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
142+
if (alreadyEnabled == enabled) {
143143
return;
144144
}
145145
if (enabled) {

contracts/src/mocks/Simple.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ contract Simple {
2424
}
2525

2626
function incrementRedeem() external {
27+
require(msg.sender == tx.origin, "SENDER_NOT_ORIGIN");
28+
require(ArbSys(address(0x64)).wasMyCallersAddressAliased(), "NOT_ALIASED");
2729
counter++;
2830
emit RedeemedEvent(msg.sender, ArbRetryableTx(address(110)).getCurrentRedeemer());
2931
}
@@ -37,6 +39,10 @@ contract Simple {
3739
return block.number;
3840
}
3941

42+
function getBlockDifficulty() external view returns (uint256) {
43+
return block.difficulty;
44+
}
45+
4046
function noop() external pure {}
4147

4248
function pleaseRevert() external pure {

0 commit comments

Comments
 (0)