Skip to content

Commit

Permalink
Merge commit '51cd559' into stylus-master-152b9ff
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Jun 20, 2023
2 parents edb6279 + 51cd559 commit 55cab43
Show file tree
Hide file tree
Showing 33 changed files with 396 additions and 297 deletions.
5 changes: 5 additions & 0 deletions .clabot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"contributors": "https://api.github.com/repos/OffchainLabs/clabot-config/contents/nitro-contributors.json",
"message": "We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please sign the linked documents below to get yourself added. https://na3.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=b15c81cc-b5ea-42a6-9107-3992526f2898&env=na3&acct=6e152afc-6284-44af-a4c1-d8ef291db402&v=2",
"label": "s"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ For the token bridge contracts see https://github.com/OffchainLabs/token-bridge-
Compile these contracts locally by running

```bash
git clone https://github.com/offchainlabs/rollup-contracts
cd rollup-contracts
git clone https://github.com/offchainlabs/nitro-contracts
cd nitro-contracts
yarn install
yarn build
```
4 changes: 2 additions & 2 deletions src/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
bool alreadyEnabled = info.allowed;
emit InboxToggle(inbox, enabled);
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
if (alreadyEnabled == enabled) {
return;
}
if (enabled) {
Expand All @@ -252,7 +252,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
InOutInfo storage info = allowedOutboxesMap[outbox];
bool alreadyEnabled = info.allowed;
emit OutboxToggle(outbox, enabled);
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
if (alreadyEnabled == enabled) {
return;
}
if (enabled) {
Expand Down
24 changes: 21 additions & 3 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ interface ISequencerInbox is IDelayedMessageProvider {

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

function isSequencer(address) external view returns (bool);

struct DasKeySetInfo {
bool isValidKeyset;
uint64 creationBlock;
}

// https://github.com/ethereum/solidity/issues/11826
// function maxTimeVariation() external view returns (MaxTimeVariation calldata);
// function dasKeySetInfo(bytes32) external view returns (DasKeySetInfo calldata);
function maxTimeVariation()
external
view
returns (
uint256,
uint256,
uint256,
uint256
);

function dasKeySetInfo(bytes32) external view returns (bool, uint64);

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

/**
* @notice Updates whether an address is authorized to be a sequencer.
* @dev The IsSequencer information is used only off-chain by the nitro node to validate sequencer feed signer.
* @param addr the address
* @param isSequencer_ if the specified address should be authorized as a sequencer
*/
function setIsSequencer(address addr, bool isSequencer_) external;

// ---------- initializer ----------

function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;
Expand Down
20 changes: 19 additions & 1 deletion src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import "./IInbox.sol";
import "./ISequencerInbox.sol";
import "../rollup/IRollupLogic.sol";
import "./Messages.sol";
import "../precompiles/ArbGasInfo.sol";

import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";
import {GasRefundEnabled, IGasRefunder} from "../libraries/IGasRefunder.sol";
import "../libraries/DelegateCallAware.sol";
import "../libraries/ArbitrumChecker.sol";
import {MAX_DATA_SIZE} from "../libraries/Constants.sol";

/**
Expand Down Expand Up @@ -64,6 +66,11 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox

uint256 internal immutable deployTimeChainId = block.chainid;

mapping(address => bool) public isSequencer;

// If the chain this SequencerInbox is deployed on is an Arbitrum chain.
bool internal immutable hostChainIsArbitrum = ArbitrumChecker.runningOnArbitrum();

function _chainIdChanged() internal view returns (bool) {
return deployTimeChainId != block.chainid;
}
Expand Down Expand Up @@ -385,12 +392,17 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
// this msg isn't included in the current sequencer batch, but instead added to
// the delayed messages queue that is yet to be included
address batchPoster = msg.sender;
uint256 dataCost = block.basefee;
if (hostChainIsArbitrum) {
// Include extra cost for the host chain's L1 gas charging
dataCost += ArbGasInfo(address(0x6c)).getL1BaseFeeEstimate();
}
bytes memory spendingReportMsg = abi.encodePacked(
block.timestamp,
batchPoster,
dataHash,
seqMessageIndex,
block.basefee
dataCost
);
uint256 msgNum = bridge.submitBatchSpendingReport(
batchPoster,
Expand Down Expand Up @@ -450,6 +462,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
emit OwnerFunctionCalled(3);
}

/// @inheritdoc ISequencerInbox
function setIsSequencer(address addr, bool isSequencer_) external onlyRollupOwner {
isSequencer[addr] = isSequencer_;
emit OwnerFunctionCalled(4);
}

function isValidKeysetHash(bytes32 ksHash) external view returns (bool) {
return dasKeySetInfo[ksHash].isValidKeyset;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/AdminFallbackProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ contract AdminFallbackProxy is Proxy, DoubleLogicERC1967Upgrade {
* Only the `adminAddr` is able to use the `adminLogic` functions
* All other addresses can interact with the `userLogic` functions
*/
constructor(
function _initialize(
address adminLogic,
bytes memory adminData,
address userLogic,
bytes memory userData,
address adminAddr
) payable {
) internal {
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
assert(
_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/ArbitrumChecker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import "../precompiles/ArbSys.sol";

library ArbitrumChecker {
function runningOnArbitrum() internal view returns (bool) {
(bool ok, bytes memory data) = address(100).staticcall(
abi.encodeWithSelector(ArbSys.arbOSVersion.selector)
);
return ok && data.length == 32;
}
}
5 changes: 1 addition & 4 deletions src/libraries/IGasRefunder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ abstract contract GasRefundEnabled {
uint256 startGasLeft = gasleft();
_;
if (address(gasRefunder) != address(0)) {
uint256 calldataSize;
assembly {
calldataSize := calldatasize()
}
uint256 calldataSize = msg.data.length;
uint256 calldataWords = (calldataSize + 31) / 32;
// account for the CALLDATACOPY cost of the proxy contract, including the memory expansion cost
startGasLeft += calldataWords * 6 + (calldataWords**2) / 512;
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/BridgeStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ contract BridgeStub is IBridge {
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
bool alreadyEnabled = info.allowed;
emit InboxToggle(inbox, enabled);
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
if (alreadyEnabled == enabled) {
return;
}
if (enabled) {
Expand Down
4 changes: 4 additions & 0 deletions src/mocks/Simple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ contract Simple {
return block.number;
}

function getBlockDifficulty() external view returns (uint256) {
return block.difficulty;
}

function noop() external pure {}

function pleaseRevert() external pure {
Expand Down
1 change: 1 addition & 0 deletions src/osp/IOneStepProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pragma solidity ^0.8.0;
import "../state/Machine.sol";
import "../state/Module.sol";
import "../state/Instructions.sol";
import "../state/GlobalState.sol";
import "../bridge/ISequencerInbox.sol";
import "../bridge/IBridge.sol";

Expand Down
1 change: 1 addition & 0 deletions src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../state/Value.sol";
import "../state/Machine.sol";
import "../state/MerkleProof.sol";
import "../state/Deserialize.sol";
import "../state/ModuleMemory.sol";
import "./IOneStepProver.sol";
import "../bridge/Messages.sol";
import "../bridge/IBridge.sol";
Expand Down
1 change: 1 addition & 0 deletions src/osp/OneStepProverMemory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pragma solidity ^0.8.0;
import "../state/Value.sol";
import "../state/Machine.sol";
import "../state/Deserialize.sol";
import "../state/ModuleMemory.sol";
import "./IOneStepProver.sol";

contract OneStepProverMemory is IOneStepProver {
Expand Down
43 changes: 43 additions & 0 deletions src/rollup/Config.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import "../state/GlobalState.sol";
import "../state/Machine.sol";
import "../bridge/ISequencerInbox.sol";
import "../bridge/IBridge.sol";
import "../bridge/IOutbox.sol";
import "../bridge/IInbox.sol";
import "./IRollupEventInbox.sol";
import "./IRollupLogic.sol";
import "../challenge/IChallengeManager.sol";

struct Config {
uint64 confirmPeriodBlocks;
uint64 extraChallengeTimeBlocks;
address stakeToken;
uint256 baseStake;
bytes32 wasmModuleRoot;
address owner;
address loserStakeEscrow;
uint256 chainId;
string chainConfig;
uint64 genesisBlockNum;
ISequencerInbox.MaxTimeVariation sequencerInboxMaxTimeVariation;
}

struct ContractDependencies {
IBridge bridge;
ISequencerInbox sequencerInbox;
IInbox inbox;
IOutbox outbox;
IRollupEventInbox rollupEventInbox;
IChallengeManager challengeManager;
address rollupAdminLogic;
IRollupUser rollupUserLogic;
// misc contracts that are useful when interacting with the rollup
address validatorUtils;
address validatorWalletCreator;
}
Loading

0 comments on commit 55cab43

Please sign in to comment.