Commit 699fd8f3 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: more cleanup

parent e943ef82
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
...@@ -67,6 +68,26 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -67,6 +68,26 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
portalABI, err := bindings.OptimismPortalMetaData.GetAbi()
if err != nil {
return nil, err
}
// Initialize the OptimismPortal without being paused
data, err := portalABI.Pack("initialize", false)
if err != nil {
return nil, fmt.Errorf("cannot abi encode initialize for OptimismPortal: %w", err)
}
if _, err := upgradeProxy(
backend,
opts,
depsByName["OptimismPortalProxy"].Address,
depsByName["OptimismPortal"].Address,
data,
); err != nil {
return nil, fmt.Errorf("cannot upgrade OptimismPortalProxy: %w", err)
}
sysCfgABI, err := bindings.SystemConfigMetaData.GetAbi() sysCfgABI, err := bindings.SystemConfigMetaData.GetAbi()
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -75,7 +96,13 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -75,7 +96,13 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
if gasLimit == 0 { if gasLimit == 0 {
gasLimit = defaultL2GasLimit gasLimit = defaultL2GasLimit
} }
data, err := sysCfgABI.Pack(
uint128Max, ok := new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
if !ok {
return nil, errors.New("bad uint128Max")
}
data, err = sysCfgABI.Pack(
"initialize", "initialize",
config.FinalSystemOwner, config.FinalSystemOwner,
uint642Big(config.GasPriceOracleOverhead), uint642Big(config.GasPriceOracleOverhead),
...@@ -83,6 +110,14 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -83,6 +110,14 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
config.BatchSenderAddress.Hash(), config.BatchSenderAddress.Hash(),
gasLimit, gasLimit,
config.P2PSequencerAddress, config.P2PSequencerAddress,
bindings.SystemConfigResourceConfig{
MaxResourceLimit: 20_000_000,
ElasticityMultiplier: 10,
BaseFeeMaxChangeDenominator: 8,
MinimumBaseFee: params.GWei,
SystemTxMaxGas: 1_000_000,
MaximumBaseFee: uint128Max,
},
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot abi encode initialize for SystemConfig: %w", err) return nil, fmt.Errorf("cannot abi encode initialize for SystemConfig: %w", err)
...@@ -94,7 +129,7 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -94,7 +129,7 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
depsByName["SystemConfig"].Address, depsByName["SystemConfig"].Address,
data, data,
); err != nil { ); err != nil {
return nil, err return nil, fmt.Errorf("cannot upgrade SystemConfigProxy: %w", err)
} }
l2ooABI, err := bindings.L2OutputOracleMetaData.GetAbi() l2ooABI, err := bindings.L2OutputOracleMetaData.GetAbi()
...@@ -119,24 +154,6 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -119,24 +154,6 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
return nil, err return nil, err
} }
portalABI, err := bindings.OptimismPortalMetaData.GetAbi()
if err != nil {
return nil, err
}
// Initialize the OptimismPortal without being paused
data, err = portalABI.Pack("initialize", false)
if err != nil {
return nil, fmt.Errorf("cannot abi encode initialize for OptimismPortal: %w", err)
}
if _, err := upgradeProxy(
backend,
opts,
depsByName["OptimismPortalProxy"].Address,
depsByName["OptimismPortal"].Address,
data,
); err != nil {
return nil, err
}
l1XDMABI, err := bindings.L1CrossDomainMessengerMetaData.GetAbi() l1XDMABI, err := bindings.L1CrossDomainMessengerMetaData.GetAbi()
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -264,6 +281,7 @@ func deployL1Contracts(config *DeployConfig, backend *backends.SimulatedBackend) ...@@ -264,6 +281,7 @@ func deployL1Contracts(config *DeployConfig, backend *backends.SimulatedBackend)
if gasLimit == 0 { if gasLimit == 0 {
gasLimit = defaultL2GasLimit gasLimit = defaultL2GasLimit
} }
constructors = append(constructors, []deployer.Constructor{ constructors = append(constructors, []deployer.Constructor{
{ {
Name: "SystemConfig", Name: "SystemConfig",
...@@ -297,6 +315,7 @@ func deployL1Contracts(config *DeployConfig, backend *backends.SimulatedBackend) ...@@ -297,6 +315,7 @@ func deployL1Contracts(config *DeployConfig, backend *backends.SimulatedBackend)
predeploys.DevL2OutputOracleAddr, predeploys.DevL2OutputOracleAddr,
config.PortalGuardian, config.PortalGuardian,
true, // _paused true, // _paused
predeploys.DevSystemConfigAddr,
}, },
}, },
{ {
...@@ -362,6 +381,7 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep ...@@ -362,6 +381,7 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
deployment.Args[0].(common.Address), deployment.Args[0].(common.Address),
deployment.Args[1].(common.Address), deployment.Args[1].(common.Address),
deployment.Args[2].(bool), deployment.Args[2].(bool),
deployment.Args[3].(common.Address),
) )
case "L1CrossDomainMessenger": case "L1CrossDomainMessenger":
_, tx, _, err = bindings.DeployL1CrossDomainMessenger( _, tx, _, err = bindings.DeployL1CrossDomainMessenger(
...@@ -421,6 +441,15 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep ...@@ -421,6 +441,15 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
func upgradeProxy(backend *backends.SimulatedBackend, opts *bind.TransactOpts, proxyAddr common.Address, implAddr common.Address, callData []byte) (*types.Transaction, error) { func upgradeProxy(backend *backends.SimulatedBackend, opts *bind.TransactOpts, proxyAddr common.Address, implAddr common.Address, callData []byte) (*types.Transaction, error) {
var tx *types.Transaction var tx *types.Transaction
code, err := backend.CodeAt(context.Background(), implAddr, nil)
if err != nil {
return nil, err
}
if len(code) == 0 {
return nil, fmt.Errorf("no code at %s", implAddr)
}
proxy, err := bindings.NewProxy(proxyAddr, backend) proxy, err := bindings.NewProxy(proxyAddr, backend)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"l1BlockTime": 15, "l1BlockTime": 15,
"l1GenesisBlockNonce": "0x0", "l1GenesisBlockNonce": "0x0",
"cliqueSignerAddress": "0x0000000000000000000000000000000000000000", "cliqueSignerAddress": "0x0000000000000000000000000000000000000000",
"l1GenesisBlockGasLimit": "0xe4e1c0", "l1GenesisBlockGasLimit": "0x1c9c380",
"l1GenesisBlockDifficulty": "0x1", "l1GenesisBlockDifficulty": "0x1",
"finalSystemOwner": "0x0000000000000000000000000000000000000111", "finalSystemOwner": "0x0000000000000000000000000000000000000111",
"portalGuardian": "0x0000000000000000000000000000000000000112", "portalGuardian": "0x0000000000000000000000000000000000000112",
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"l1GenesisBlockTimestamp": "0x0", "l1GenesisBlockTimestamp": "0x0",
"l1GenesisBlockBaseFeePerGas": "0x3b9aca00", "l1GenesisBlockBaseFeePerGas": "0x3b9aca00",
"l2GenesisBlockNonce": "0x0", "l2GenesisBlockNonce": "0x0",
"l2GenesisBlockGasLimit": "0xe4e1c0", "l2GenesisBlockGasLimit": "0x1c9c380",
"l2GenesisBlockDifficulty": "0x1", "l2GenesisBlockDifficulty": "0x1",
"l2GenesisBlockMixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "l2GenesisBlockMixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"l2GenesisBlockNumber": "0x0", "l2GenesisBlockNumber": "0x0",
......
...@@ -45,12 +45,12 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver { ...@@ -45,12 +45,12 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
uint64 internal constant RECEIVE_DEFAULT_GAS_LIMIT = 100_000; uint64 internal constant RECEIVE_DEFAULT_GAS_LIMIT = 100_000;
/** /**
* @notice Address of the L2OutputOracle. * @notice Address of the L2OutputOracle contract.
*/ */
L2OutputOracle public immutable L2_ORACLE; L2OutputOracle public immutable L2_ORACLE;
/** /**
* * @notice Address of the SystemConfig contract.
*/ */
SystemConfig public immutable SYSTEM_CONFIG; SystemConfig public immutable SYSTEM_CONFIG;
...@@ -209,7 +209,7 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver { ...@@ -209,7 +209,7 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
/** /**
* @notice * @notice
*/ */
function resourceConfig() public view override returns (SystemConfig.ResourceConfig memory) { function _resourceConfig() internal view override returns (SystemConfig.ResourceConfig memory) {
return SYSTEM_CONFIG.resourceConfig(); return SYSTEM_CONFIG.resourceConfig();
} }
......
...@@ -64,7 +64,7 @@ abstract contract ResourceMetering is Initializable { ...@@ -64,7 +64,7 @@ abstract contract ResourceMetering is Initializable {
// Update block number and base fee if necessary. // Update block number and base fee if necessary.
uint256 blockDiff = block.number - params.prevBlockNum; uint256 blockDiff = block.number - params.prevBlockNum;
SystemConfig.ResourceConfig memory config = resourceConfig(); SystemConfig.ResourceConfig memory config = _resourceConfig();
int256 targetResourceLimit = int256(uint256(config.maxResourceLimit)) / int256(uint256(config.elasticityMultiplier)); int256 targetResourceLimit = int256(uint256(config.maxResourceLimit)) / int256(uint256(config.elasticityMultiplier));
if (blockDiff > 0) { if (blockDiff > 0) {
...@@ -136,7 +136,7 @@ abstract contract ResourceMetering is Initializable { ...@@ -136,7 +136,7 @@ abstract contract ResourceMetering is Initializable {
/** /**
* @notice * @notice
*/ */
function resourceConfig() public virtual returns (SystemConfig.ResourceConfig memory); function _resourceConfig() internal virtual returns (SystemConfig.ResourceConfig memory);
/** /**
* @notice Sets initial resource parameter values. This function must either be called by the * @notice Sets initial resource parameter values. This function must either be called by the
...@@ -144,10 +144,8 @@ abstract contract ResourceMetering is Initializable { ...@@ -144,10 +144,8 @@ abstract contract ResourceMetering is Initializable {
*/ */
// solhint-disable-next-line func-name-mixedcase // solhint-disable-next-line func-name-mixedcase
function __ResourceMetering_init() internal onlyInitializing { function __ResourceMetering_init() internal onlyInitializing {
SystemConfig.ResourceConfig memory config = resourceConfig();
params = ResourceParams({ params = ResourceParams({
prevBaseFee: config.minimumBaseFee, prevBaseFee: 1 gwei,
prevBoughtGas: 0, prevBoughtGas: 0,
prevBlockNum: uint64(block.number) prevBlockNum: uint64(block.number)
}); });
......
...@@ -238,10 +238,16 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -238,10 +238,16 @@ contract SystemConfig is OwnableUpgradeable, Semver {
} }
} }
/**
* @notice
*/
function resourceConfig() external view returns (ResourceConfig memory) { function resourceConfig() external view returns (ResourceConfig memory) {
return _resourceConfig; return _resourceConfig;
} }
/**
* @notice
*/
function setResourceConfig(ResourceConfig memory _config) external onlyOwner { function setResourceConfig(ResourceConfig memory _config) external onlyOwner {
_setResourceConfig(_config); _setResourceConfig(_config);
...@@ -249,6 +255,9 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -249,6 +255,9 @@ contract SystemConfig is OwnableUpgradeable, Semver {
emit ConfigUpdate(VERSION, UpdateType.RESOURCE_CONFIG, data); emit ConfigUpdate(VERSION, UpdateType.RESOURCE_CONFIG, data);
} }
/**
* @notice
*/
function _setResourceConfig(ResourceConfig memory _config) internal { function _setResourceConfig(ResourceConfig memory _config) internal {
require(_config.minimumBaseFee <= _config.maximumBaseFee); require(_config.minimumBaseFee <= _config.maximumBaseFee);
require(_config.baseFeeMaxChangeDenominator > 0); require(_config.baseFeeMaxChangeDenominator > 0);
...@@ -257,6 +266,9 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -257,6 +266,9 @@ contract SystemConfig is OwnableUpgradeable, Semver {
_resourceConfig = _config; _resourceConfig = _config;
} }
/**
* @notice
*/
function minimumGasLimit() public view returns (uint256) { function minimumGasLimit() public view returns (uint256) {
return _resourceConfig.maxResourceLimit + _resourceConfig.systemTxMaxGas; return _resourceConfig.maxResourceLimit + _resourceConfig.systemTxMaxGas;
} }
......
...@@ -25,7 +25,11 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils { ...@@ -25,7 +25,11 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils {
__ResourceMetering_init(); __ResourceMetering_init();
} }
function resourceConfig() public pure override returns (SystemConfig.ResourceConfig memory) { function resourceConfig() public pure returns (SystemConfig.ResourceConfig memory) {
return _resourceConfig();
}
function _resourceConfig() internal pure override returns (SystemConfig.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({ SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000, maxResourceLimit: 20_000_000,
elasticityMultiplier: 10, elasticityMultiplier: 10,
......
...@@ -1050,7 +1050,7 @@ contract OptimismPortalUpgradeable_Test is Portal_Initializer { ...@@ -1050,7 +1050,7 @@ contract OptimismPortalUpgradeable_Test is Portal_Initializer {
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = p.params(); (uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = p.params();
SystemConfig.ResourceConfig memory rcfg = p.resourceConfig(); SystemConfig.ResourceConfig memory rcfg = systemConfig.resourceConfig();
assertEq(prevBaseFee, rcfg.minimumBaseFee); assertEq(prevBaseFee, rcfg.minimumBaseFee);
assertEq(prevBoughtGas, 0); assertEq(prevBoughtGas, 0);
assertEq(prevBlockNum, initialBlockNum); assertEq(prevBlockNum, initialBlockNum);
......
...@@ -15,7 +15,11 @@ contract MeterUser is ResourceMetering { ...@@ -15,7 +15,11 @@ contract MeterUser is ResourceMetering {
__ResourceMetering_init(); __ResourceMetering_init();
} }
function resourceConfig() public override pure returns (SystemConfig.ResourceConfig memory) { function resourceConfig() public pure returns (SystemConfig.ResourceConfig memory) {
return _resourceConfig();
}
function _resourceConfig() internal override pure returns (SystemConfig.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({ SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000, maxResourceLimit: 20_000_000,
elasticityMultiplier: 10, elasticityMultiplier: 10,
...@@ -180,7 +184,7 @@ contract CustomMeterUser is ResourceMetering { ...@@ -180,7 +184,7 @@ contract CustomMeterUser is ResourceMetering {
}); });
} }
function resourceConfig() public override pure returns (SystemConfig.ResourceConfig memory) { function _resourceConfig() internal override pure returns (SystemConfig.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({ SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000, maxResourceLimit: 20_000_000,
elasticityMultiplier: 10, elasticityMultiplier: 10,
......
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