Commit 87abf341 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into ajsutton/update-opgeth

parents 2983babd c0c02964
This diff is collapsed.
......@@ -22,7 +22,10 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
)
var ErrInvalidDeployConfig = errors.New("invalid deploy config")
var (
ErrInvalidDeployConfig = errors.New("invalid deploy config")
ErrInvalidImmutablesConfig = errors.New("invalid immutables config")
)
// DeployConfig represents the deployment configuration for Optimism
type DeployConfig struct {
......@@ -344,12 +347,27 @@ func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error) {
}
// NewL2ImmutableConfig will create an ImmutableConfig given an instance of a
// Hardhat and a DeployConfig.
// DeployConfig and a block.
func NewL2ImmutableConfig(config *DeployConfig, block *types.Block) (immutables.ImmutableConfig, error) {
immutable := make(immutables.ImmutableConfig)
if config.L1StandardBridgeProxy == (common.Address{}) {
return immutable, fmt.Errorf("L1StandardBridgeProxy cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
if config.L1CrossDomainMessengerProxy == (common.Address{}) {
return immutable, fmt.Errorf("L1CrossDomainMessengerProxy cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
if config.L1ERC721BridgeProxy == (common.Address{}) {
return immutable, errors.New("L1ERC721BridgeProxy cannot be address(0)")
return immutable, fmt.Errorf("L1ERC721BridgeProxy cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
if config.SequencerFeeVaultRecipient == (common.Address{}) {
return immutable, fmt.Errorf("SequencerFeeVaultRecipient cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
if config.BaseFeeVaultRecipient == (common.Address{}) {
return immutable, fmt.Errorf("BaseFeeVaultRecipient cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
if config.L1FeeVaultRecipient == (common.Address{}) {
return immutable, fmt.Errorf("L1FeeVaultRecipient cannot be address(0): %w", ErrInvalidImmutablesConfig)
}
immutable["L2StandardBridge"] = immutables.ImmutableValues{
......
......@@ -23,6 +23,8 @@
"l1FeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"sequencerFeeVaultRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"l1ERC721BridgeProxy": "0xff000000000000000000000000000000000000ff",
"l1StandardBridgeProxy": "0xff000000000000000000000000000000000000fd",
"l1CrossDomainMessengerProxy": "0xff000000000000000000000000000000000000dd",
"deploymentWaitConfirmations": 1,
"fundDevAccounts": true
......
package immutables
import (
"errors"
"fmt"
"math/big"
......@@ -24,6 +25,39 @@ type ImmutableValues map[string]any
// contracts.
type ImmutableConfig map[string]ImmutableValues
// Check does a sanity check that the specific values that
// Optimism uses are set inside of the ImmutableConfig.
func (i ImmutableConfig) Check() error {
if _, ok := i["L2CrossDomainMessenger"]["otherMessenger"]; !ok {
return errors.New("L2CrossDomainMessenger otherMessenger not set")
}
if _, ok := i["L2StandardBridge"]["otherBridge"]; !ok {
return errors.New("L2StandardBridge otherBridge not set")
}
if _, ok := i["L2ERC721Bridge"]["messenger"]; !ok {
return errors.New("L2ERC721Bridge messenger not set")
}
if _, ok := i["L2ERC721Bridge"]["otherBridge"]; !ok {
return errors.New("L2ERC721Bridge otherBridge not set")
}
if _, ok := i["OptimismMintableERC721Factory"]["bridge"]; !ok {
return errors.New("OptimismMintableERC20Factory bridge not set")
}
if _, ok := i["OptimismMintableERC721Factory"]["remoteChainId"]; !ok {
return errors.New("OptimismMintableERC20Factory remoteChainId not set")
}
if _, ok := i["SequencerFeeVault"]["recipient"]; !ok {
return errors.New("SequencerFeeVault recipient not set")
}
if _, ok := i["L1FeeVault"]["recipient"]; !ok {
return errors.New("L1FeeVault recipient not set")
}
if _, ok := i["BaseFeeVault"]["recipient"]; !ok {
return errors.New("BaseFeeVault recipient not set")
}
return nil
}
// DeploymentResults represents the output of deploying each of the
// contracts so that the immutables can be set properly in the bytecode.
type DeploymentResults map[string]hexutil.Bytes
......@@ -31,6 +65,10 @@ type DeploymentResults map[string]hexutil.Bytes
// BuildOptimism will deploy the L2 predeploys so that their immutables are set
// correctly.
func BuildOptimism(immutable ImmutableConfig) (DeploymentResults, error) {
if err := immutable.Check(); err != nil {
return DeploymentResults{}, err
}
deployments := []deployer.Constructor{
{
Name: "GasPriceOracle",
......
......@@ -19,9 +19,11 @@ func TestBuildOptimism(t *testing.T) {
},
"L2ERC721Bridge": {
"otherBridge": common.HexToAddress("0x1234567890123456789012345678901234567890"),
"messenger": common.HexToAddress("0x1234567890123456789012345678901234567890"),
},
"OptimismMintableERC721Factory": {
"remoteChainId": big.NewInt(1),
"bridge": common.HexToAddress("0x1234567890123456789012345678901234567890"),
},
"SequencerFeeVault": {
"recipient": common.HexToAddress("0x1234567890123456789012345678901234567890"),
......
......@@ -102,6 +102,10 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams {
GasPriceOracleScalar: 1000_000,
DeploymentWaitConfirmations: 1,
SequencerFeeVaultRecipient: common.Address{19: 1},
BaseFeeVaultRecipient: common.Address{19: 2},
L1FeeVaultRecipient: common.Address{19: 3},
EIP1559Elasticity: 10,
EIP1559Denominator: 50,
......
......@@ -92,6 +92,10 @@ func DefaultSystemConfig(t *testing.T) SystemConfig {
GasPriceOracleOverhead: 2100,
GasPriceOracleScalar: 1_000_000,
SequencerFeeVaultRecipient: common.Address{19: 1},
BaseFeeVaultRecipient: common.Address{19: 2},
L1FeeVaultRecipient: common.Address{19: 3},
DeploymentWaitConfirmations: 1,
EIP1559Elasticity: 2,
......
......@@ -20,6 +20,7 @@ type BlockInfo interface {
MixDigest() common.Hash
BaseFee() *big.Int
ReceiptHash() common.Hash
GasUsed() uint64
}
func InfoToL1BlockRef(info BlockInfo) L1BlockRef {
......@@ -79,6 +80,10 @@ func (h headerBlockInfo) ReceiptHash() common.Hash {
return h.Header.ReceiptHash
}
func (h headerBlockInfo) GasUsed() uint64 {
return h.Header.GasUsed
}
// HeaderBlockInfo returns h as a BlockInfo implementation.
func HeaderBlockInfo(h *types.Header) BlockInfo {
return headerBlockInfo{h}
......
......@@ -46,6 +46,7 @@ type HeaderInfo struct {
baseFee *big.Int
txHash common.Hash
receiptHash common.Hash
gasUsed uint64
}
var _ eth.BlockInfo = (*HeaderInfo)(nil)
......@@ -90,6 +91,10 @@ func (info *HeaderInfo) ReceiptHash() common.Hash {
return info.receiptHash
}
func (info *HeaderInfo) GasUsed() uint64 {
return info.gasUsed
}
type rpcHeader struct {
ParentHash common.Hash `json:"parentHash"`
UncleHash common.Hash `json:"sha3Uncles"`
......@@ -182,6 +187,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo,
baseFee: (*big.Int)(hdr.BaseFee),
txHash: hdr.TxHash,
receiptHash: hdr.ReceiptHash,
gasUsed: uint64(hdr.GasUsed),
}
return &info, nil
}
......
......@@ -21,6 +21,7 @@ type MockBlockInfo struct {
InfoMixDigest [32]byte
InfoBaseFee *big.Int
InfoReceiptRoot common.Hash
InfoGasUsed uint64
}
func (l *MockBlockInfo) Hash() common.Hash {
......@@ -59,6 +60,10 @@ func (l *MockBlockInfo) ReceiptHash() common.Hash {
return l.InfoReceiptRoot
}
func (l *MockBlockInfo) GasUsed() uint64 {
return l.InfoGasUsed
}
func (l *MockBlockInfo) ID() eth.BlockID {
return eth.BlockID{Hash: l.InfoHash, Number: l.InfoNum}
}
......@@ -81,6 +86,7 @@ func RandomBlockInfo(rng *rand.Rand) *MockBlockInfo {
InfoBaseFee: big.NewInt(rng.Int63n(1000_000 * 1e9)), // a million GWEI
InfoReceiptRoot: types.EmptyRootHash,
InfoRoot: RandomHash(rng),
InfoGasUsed: rng.Uint64(),
}
}
......
......@@ -139,29 +139,30 @@ L2ERC721Bridge_Test:test_finalizeBridgeERC721_notFromRemoteMessenger_reverts() (
L2ERC721Bridge_Test:test_finalizeBridgeERC721_notViaLocalMessenger_reverts() (gas: 16148)
L2ERC721Bridge_Test:test_finalizeBridgeERC721_selfToken_reverts() (gas: 17637)
L2ERC721Bridge_Test:test_finalizeBridgeERC721_succeeds() (gas: 168905)
L2OutputOracleTest:test_computeL2Timestamp_succeeds() (gas: 37184)
L2OutputOracleTest:test_constructor_badTimestamp_reverts() (gas: 70717)
L2OutputOracleTest:test_constructor_succeeds() (gas: 33760)
L2OutputOracleTest:test_deleteL2Outputs_afterLatest_reverts() (gas: 211900)
L2OutputOracleTest:test_computeL2Timestamp_succeeds() (gas: 37206)
L2OutputOracleTest:test_constructor_badTimestamp_reverts() (gas: 70767)
L2OutputOracleTest:test_constructor_l2BlockTimeZero_reverts() (gas: 45786)
L2OutputOracleTest:test_constructor_succeeds() (gas: 33695)
L2OutputOracleTest:test_deleteL2Outputs_afterLatest_reverts() (gas: 211855)
L2OutputOracleTest:test_deleteL2Outputs_ifNotChallenger_reverts() (gas: 18883)
L2OutputOracleTest:test_deleteL2Outputs_nonExistent_reverts() (gas: 107292)
L2OutputOracleTest:test_deleteOutputs_multipleOutputs_succeeds() (gas: 302121)
L2OutputOracleTest:test_deleteOutputs_singleOutput_succeeds() (gas: 180656)
L2OutputOracleTest:test_getL2OutputIndexAfter_multipleOutputsExist_succeeds() (gas: 267182)
L2OutputOracleTest:test_getL2OutputIndexAfter_noOutputsExis_reverts() (gas: 17914)
L2OutputOracleTest:test_getL2OutputIndexAfter_previousBlock_succeeds() (gas: 96086)
L2OutputOracleTest:test_getL2OutputIndexAfter_sameBlock_succeeds() (gas: 95994)
L2OutputOracleTest:test_getL2Output_succeeds() (gas: 101699)
L2OutputOracleTest:test_latestBlockNumber_succeeds() (gas: 96983)
L2OutputOracleTest:test_nextBlockNumber_succeeds() (gas: 17468)
L2OutputOracleTest:test_proposeL2Output_emptyOutput_reverts() (gas: 26688)
L2OutputOracleTest:test_proposeL2Output_futureTimetamp_reverts() (gas: 28646)
L2OutputOracleTest:test_proposeL2Output_notProposer_reverts() (gas: 25782)
L2OutputOracleTest:test_proposeL2Output_proposeAnotherOutput_succeeds() (gas: 101027)
L2OutputOracleTest:test_deleteOutputs_multipleOutputs_succeeds() (gas: 302143)
L2OutputOracleTest:test_deleteOutputs_singleOutput_succeeds() (gas: 180700)
L2OutputOracleTest:test_getL2OutputIndexAfter_multipleOutputsExist_succeeds() (gas: 267226)
L2OutputOracleTest:test_getL2OutputIndexAfter_noOutputsExis_reverts() (gas: 17936)
L2OutputOracleTest:test_getL2OutputIndexAfter_previousBlock_succeeds() (gas: 96042)
L2OutputOracleTest:test_getL2OutputIndexAfter_sameBlock_succeeds() (gas: 96016)
L2OutputOracleTest:test_getL2Output_succeeds() (gas: 101721)
L2OutputOracleTest:test_latestBlockNumber_succeeds() (gas: 96960)
L2OutputOracleTest:test_nextBlockNumber_succeeds() (gas: 17490)
L2OutputOracleTest:test_proposeL2Output_emptyOutput_reverts() (gas: 26710)
L2OutputOracleTest:test_proposeL2Output_futureTimetamp_reverts() (gas: 28690)
L2OutputOracleTest:test_proposeL2Output_notProposer_reverts() (gas: 25826)
L2OutputOracleTest:test_proposeL2Output_proposeAnotherOutput_succeeds() (gas: 101049)
L2OutputOracleTest:test_proposeL2Output_unexpectedBlockNumber_reverts() (gas: 28402)
L2OutputOracleTest:test_proposeL2Output_unmatchedBlockhash_reverts() (gas: 29446)
L2OutputOracleTest:test_proposeL2Output_unmatchedBlockhash_reverts() (gas: 29402)
L2OutputOracleTest:test_proposeL2Output_wrongFork_reverts() (gas: 29005)
L2OutputOracleTest:test_proposeWithBlockhashAndHeight_succeeds() (gas: 95296)
L2OutputOracleTest:test_proposeWithBlockhashAndHeight_succeeds() (gas: 95318)
L2OutputOracleUpgradeable_Test:test_initValuesOnProxy_succeeds() (gas: 26093)
L2OutputOracleUpgradeable_Test:test_initializeImpl_alreadyInitialized_reverts() (gas: 15149)
L2OutputOracleUpgradeable_Test:test_initializeProxy_alreadyInitialized_reverts() (gas: 20131)
......
......@@ -73,7 +73,7 @@ contract L2OutputOracle is Initializable, Semver {
event OutputsDeleted(uint256 indexed prevNextOutputIndex, uint256 indexed newNextOutputIndex);
/**
* @custom:semver 1.0.0
* @custom:semver 1.1.0
*
* @param _submissionInterval Interval in blocks at which checkpoints must be submitted.
* @param _l2BlockTime The time per L2 block, in seconds.
......@@ -89,7 +89,13 @@ contract L2OutputOracle is Initializable, Semver {
uint256 _startingTimestamp,
address _proposer,
address _challenger
) Semver(1, 0, 0) {
) Semver(1, 1, 0) {
require(_l2BlockTime > 0, "L2OutputOracle: L2 block time must be greater than 0");
require(
_submissionInterval > _l2BlockTime,
"L2OutputOracle: submission interval must be greater than L2 block time"
);
SUBMISSION_INTERVAL = _submissionInterval;
L2_BLOCK_TIME = _l2BlockTime;
PROPOSER = _proposer;
......
......@@ -44,6 +44,40 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
);
}
function test_constructor_l2BlockTimeZero_reverts() external {
vm.expectRevert("L2OutputOracle: L2 block time must be greater than 0");
new L2OutputOracle(
submissionInterval,
0,
startingBlockNumber,
block.timestamp,
proposer,
owner
);
}
function testFuzz_constructor_submissionIntervalLteL2BlockTime_reverts(
uint256 _submissionInterval,
uint256 _l2BlockTime
) external {
// Bound the _l2blockTime to be in the range of [1, type(uint256).max]
_l2BlockTime = bound(_l2BlockTime, 1, type(uint256).max);
// Roll the block number to _l2blockTime (the starting L2 timestamp must be less than or equal to the current time)
vm.roll(_l2BlockTime);
// Bound _submissionInterval to be less than or equal to _l2BlockTime
_submissionInterval = bound(_submissionInterval, 0, _l2BlockTime);
vm.expectRevert("L2OutputOracle: submission interval must be greater than L2 block time");
new L2OutputOracle(
_submissionInterval,
_l2BlockTime,
startingBlockNumber,
block.timestamp,
proposer,
owner
);
}
/****************
* Getter Tests *
****************/
......
......@@ -5,6 +5,19 @@ import '@nomiclabs/hardhat-ethers'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
if (hre.deployConfig.l2BlockTime === 0) {
throw new Error(
'L2OutputOracle deployment: l2BlockTime must be greater than 0'
)
} else if (
hre.deployConfig.l2OutputOracleSubmissionInterval <=
hre.deployConfig.l2BlockTime
) {
throw new Error(
'L2OutputOracle deployment: submissionInterval must be greater than the l2BlockTime'
)
}
await deploy({
hre,
name: 'L2OutputOracle',
......
......@@ -18,7 +18,7 @@
"build:forge": "forge build",
"build:with-metadata": "FOUNDRY_PROFILE=echidna yarn build:forge",
"build:differential": "tsc scripts/differential-testing.ts --outDir dist --moduleResolution node --esModuleInterop",
"build:fuzz": "go build -o test-case-generator test-case-generator/cmd/fuzz.go",
"build:fuzz": "(cd test-case-generator && go build ./cmd/fuzz.go)",
"prebuild": "yarn ts-node scripts/verify-foundry-install.ts",
"build": "hardhat compile && yarn autogen:artifacts && yarn build:ts && yarn typechain",
"build:ts": "tsc -p tsconfig.build.json",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment