Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
f3654da7
Commit
f3654da7
authored
Mar 23, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contracts-bedrock: code review fixes
parent
1f7dc086
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
123 additions
and
118 deletions
+123
-118
systemconfig.go
op-bindings/bindings/systemconfig.go
+15
-15
systemconfig_more.go
op-bindings/bindings/systemconfig_more.go
+1
-1
layer_one.go
op-chain-ops/genesis/layer_one.go
+13
-6
OptimismPortal.sol
packages/contracts-bedrock/contracts/L1/OptimismPortal.sol
+1
-1
ResourceMetering.sol
packages/contracts-bedrock/contracts/L1/ResourceMetering.sol
+32
-3
SystemConfig.sol
packages/contracts-bedrock/contracts/L1/SystemConfig.sol
+7
-38
SystemDictator.sol
...contracts-bedrock/contracts/deployment/SystemDictator.sol
+3
-2
FuzzOptimismPortal.sol
...ontracts-bedrock/contracts/echidna/FuzzOptimismPortal.sol
+2
-1
FuzzResourceMetering.sol
...tracts-bedrock/contracts/echidna/FuzzResourceMetering.sol
+4
-5
Constants.sol
packages/contracts-bedrock/contracts/libraries/Constants.sol
+18
-0
CommonTest.t.sol
packages/contracts-bedrock/contracts/test/CommonTest.t.sol
+2
-1
OptimismPortal.t.sol
...ges/contracts-bedrock/contracts/test/OptimismPortal.t.sol
+2
-2
ResourceMetering.t.sol
...s/contracts-bedrock/contracts/test/ResourceMetering.t.sol
+12
-28
SystemConfig.t.sol
packages/contracts-bedrock/contracts/test/SystemConfig.t.sol
+8
-7
SystemConfig.t.sol
...acts-bedrock/contracts/test/invariants/SystemConfig.t.sol
+3
-8
No files found.
op-bindings/bindings/systemconfig.go
View file @
f3654da7
This diff is collapsed.
Click to expand it.
op-bindings/bindings/systemconfig_more.go
View file @
f3654da7
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
)
)
const
SystemConfigStorageLayoutJSON
=
"{
\"
storage
\"
:[{
\"
astId
\"
:1000,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_initialized
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
0
\"
,
\"
type
\"
:
\"
t_uint8
\"
},{
\"
astId
\"
:1001,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_initializing
\"
,
\"
offset
\"
:1,
\"
slot
\"
:
\"
0
\"
,
\"
type
\"
:
\"
t_bool
\"
},{
\"
astId
\"
:1002,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
__gap
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
1
\"
,
\"
type
\"
:
\"
t_array(t_uint256)1011_storage
\"
},{
\"
astId
\"
:1003,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_owner
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
51
\"
,
\"
type
\"
:
\"
t_address
\"
},{
\"
astId
\"
:1004,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
__gap
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
52
\"
,
\"
type
\"
:
\"
t_array(t_uint256)1010_storage
\"
},{
\"
astId
\"
:1005,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
overhead
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
101
\"
,
\"
type
\"
:
\"
t_uint256
\"
},{
\"
astId
\"
:1006,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
scalar
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
102
\"
,
\"
type
\"
:
\"
t_uint256
\"
},{
\"
astId
\"
:1007,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
batcherHash
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
103
\"
,
\"
type
\"
:
\"
t_bytes32
\"
},{
\"
astId
\"
:1008,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
gasLimit
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
104
\"
,
\"
type
\"
:
\"
t_uint64
\"
},{
\"
astId
\"
:1009,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_resourceConfig
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
105
\"
,
\"
type
\"
:
\"
t_struct(ResourceConfig)1012_storage
\"
}],
\"
types
\"
:{
\"
t_address
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
address
\"
,
\"
numberOfBytes
\"
:
\"
20
\"
},
\"
t_array(t_uint256)1010_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256[49]
\"
,
\"
numberOfBytes
\"
:
\"
1568
\"
},
\"
t_array(t_uint256)1011_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256[50]
\"
,
\"
numberOfBytes
\"
:
\"
1600
\"
},
\"
t_bool
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
bool
\"
,
\"
numberOfBytes
\"
:
\"
1
\"
},
\"
t_bytes32
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
bytes32
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_struct(ResourceConfig)1012_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
struct
SystemConfi
g.ResourceConfig
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_uint128
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint128
\"
,
\"
numberOfBytes
\"
:
\"
16
\"
},
\"
t_uint256
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_uint32
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint32
\"
,
\"
numberOfBytes
\"
:
\"
4
\"
},
\"
t_uint64
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint64
\"
,
\"
numberOfBytes
\"
:
\"
8
\"
},
\"
t_uint8
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint8
\"
,
\"
numberOfBytes
\"
:
\"
1
\"
}}}"
const
SystemConfigStorageLayoutJSON
=
"{
\"
storage
\"
:[{
\"
astId
\"
:1000,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_initialized
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
0
\"
,
\"
type
\"
:
\"
t_uint8
\"
},{
\"
astId
\"
:1001,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_initializing
\"
,
\"
offset
\"
:1,
\"
slot
\"
:
\"
0
\"
,
\"
type
\"
:
\"
t_bool
\"
},{
\"
astId
\"
:1002,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
__gap
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
1
\"
,
\"
type
\"
:
\"
t_array(t_uint256)1011_storage
\"
},{
\"
astId
\"
:1003,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_owner
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
51
\"
,
\"
type
\"
:
\"
t_address
\"
},{
\"
astId
\"
:1004,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
__gap
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
52
\"
,
\"
type
\"
:
\"
t_array(t_uint256)1010_storage
\"
},{
\"
astId
\"
:1005,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
overhead
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
101
\"
,
\"
type
\"
:
\"
t_uint256
\"
},{
\"
astId
\"
:1006,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
scalar
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
102
\"
,
\"
type
\"
:
\"
t_uint256
\"
},{
\"
astId
\"
:1007,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
batcherHash
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
103
\"
,
\"
type
\"
:
\"
t_bytes32
\"
},{
\"
astId
\"
:1008,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
gasLimit
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
104
\"
,
\"
type
\"
:
\"
t_uint64
\"
},{
\"
astId
\"
:1009,
\"
contract
\"
:
\"
contracts/L1/SystemConfig.sol:SystemConfig
\"
,
\"
label
\"
:
\"
_resourceConfig
\"
,
\"
offset
\"
:0,
\"
slot
\"
:
\"
105
\"
,
\"
type
\"
:
\"
t_struct(ResourceConfig)1012_storage
\"
}],
\"
types
\"
:{
\"
t_address
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
address
\"
,
\"
numberOfBytes
\"
:
\"
20
\"
},
\"
t_array(t_uint256)1010_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256[49]
\"
,
\"
numberOfBytes
\"
:
\"
1568
\"
},
\"
t_array(t_uint256)1011_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256[50]
\"
,
\"
numberOfBytes
\"
:
\"
1600
\"
},
\"
t_bool
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
bool
\"
,
\"
numberOfBytes
\"
:
\"
1
\"
},
\"
t_bytes32
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
bytes32
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_struct(ResourceConfig)1012_storage
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
struct
ResourceMeterin
g.ResourceConfig
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_uint128
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint128
\"
,
\"
numberOfBytes
\"
:
\"
16
\"
},
\"
t_uint256
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint256
\"
,
\"
numberOfBytes
\"
:
\"
32
\"
},
\"
t_uint32
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint32
\"
,
\"
numberOfBytes
\"
:
\"
4
\"
},
\"
t_uint64
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint64
\"
,
\"
numberOfBytes
\"
:
\"
8
\"
},
\"
t_uint8
\"
:{
\"
encoding
\"
:
\"
inplace
\"
,
\"
label
\"
:
\"
uint8
\"
,
\"
numberOfBytes
\"
:
\"
1
\"
}}}"
var
SystemConfigStorageLayout
=
new
(
solc
.
StorageLayout
)
var
SystemConfigStorageLayout
=
new
(
solc
.
StorageLayout
)
...
...
op-chain-ops/genesis/layer_one.go
View file @
f3654da7
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
)
)
var
(
var
(
// proxies represents the set of proxies in front of contracts.
proxies
=
[]
string
{
proxies
=
[]
string
{
"SystemConfigProxy"
,
"SystemConfigProxy"
,
"L2OutputOracleProxy"
,
"L2OutputOracleProxy"
,
...
@@ -32,12 +33,15 @@ var (
...
@@ -32,12 +33,15 @@ var (
"OptimismPortalProxy"
,
"OptimismPortalProxy"
,
"OptimismMintableERC20FactoryProxy"
,
"OptimismMintableERC20FactoryProxy"
,
}
}
// portalMeteringSlot is the storage slot containing the metering params.
portalMeteringSlot
=
common
.
Hash
{
31
:
0x01
}
portalMeteringSlot
=
common
.
Hash
{
31
:
0x01
}
zeroHash
=
common
.
Hash
{}
// zeroHash represents the zero value for a hash.
uint128Max
=
new
(
big
.
Int
)
zeroHash
=
common
.
Hash
{}
// uint128Max is type(uint128).max and is set in the init function.
defaultResourceConfig
=
bindings
.
SystemConfigResourceConfig
{
uint128Max
=
new
(
big
.
Int
)
// The default values for the ResourceConfig, used as part of
// an EIP-1559 curve for deposit gas.
defaultResourceConfig
=
bindings
.
ResourceMeteringResourceConfig
{
MaxResourceLimit
:
20
_000_000
,
MaxResourceLimit
:
20
_000_000
,
ElasticityMultiplier
:
10
,
ElasticityMultiplier
:
10
,
BaseFeeMaxChangeDenominator
:
8
,
BaseFeeMaxChangeDenominator
:
8
,
...
@@ -52,9 +56,12 @@ func init() {
...
@@ -52,9 +56,12 @@ func init() {
if
!
ok
{
if
!
ok
{
panic
(
"bad uint128Max"
)
panic
(
"bad uint128Max"
)
}
}
// Set the maximum base fee on the default config.
defaultResourceConfig
.
MaximumBaseFee
=
uint128Max
defaultResourceConfig
.
MaximumBaseFee
=
uint128Max
}
}
// BuildL1DeveloperGenesis will create a L1 genesis block after creating
// all of the state required for an Optimism network to function.
func
BuildL1DeveloperGenesis
(
config
*
DeployConfig
)
(
*
core
.
Genesis
,
error
)
{
func
BuildL1DeveloperGenesis
(
config
*
DeployConfig
)
(
*
core
.
Genesis
,
error
)
{
if
config
.
L2OutputOracleStartingTimestamp
!=
-
1
{
if
config
.
L2OutputOracleStartingTimestamp
!=
-
1
{
return
nil
,
errors
.
New
(
"l2oo starting timestamp must be -1"
)
return
nil
,
errors
.
New
(
"l2oo starting timestamp must be -1"
)
...
@@ -369,7 +376,7 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
...
@@ -369,7 +376,7 @@ func l1Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
deployment
.
Args
[
3
]
.
(
common
.
Hash
),
deployment
.
Args
[
3
]
.
(
common
.
Hash
),
deployment
.
Args
[
4
]
.
(
uint64
),
deployment
.
Args
[
4
]
.
(
uint64
),
deployment
.
Args
[
5
]
.
(
common
.
Address
),
deployment
.
Args
[
5
]
.
(
common
.
Address
),
deployment
.
Args
[
6
]
.
(
bindings
.
SystemConfi
gResourceConfig
),
deployment
.
Args
[
6
]
.
(
bindings
.
ResourceMeterin
gResourceConfig
),
)
)
case
"L2OutputOracle"
:
case
"L2OutputOracle"
:
_
,
tx
,
_
,
err
=
bindings
.
DeployL2OutputOracle
(
_
,
tx
,
_
,
err
=
bindings
.
DeployL2OutputOracle
(
...
...
packages/contracts-bedrock/contracts/L1/OptimismPortal.sol
View file @
f3654da7
...
@@ -210,7 +210,7 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
...
@@ -210,7 +210,7 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
* @notice Getter for the resource config. Used internally by the ResourceMetering
* @notice Getter for the resource config. Used internally by the ResourceMetering
* contract. The SystemConfig is the source of truth for the resource config.
* contract. The SystemConfig is the source of truth for the resource config.
*/
*/
function _resourceConfig() internal view override returns (
SystemConfi
g.ResourceConfig memory) {
function _resourceConfig() internal view override returns (
ResourceMeterin
g.ResourceConfig memory) {
return SYSTEM_CONFIG.resourceConfig();
return SYSTEM_CONFIG.resourceConfig();
}
}
...
...
packages/contracts-bedrock/contracts/L1/ResourceMetering.sol
View file @
f3654da7
...
@@ -5,7 +5,6 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable
...
@@ -5,7 +5,6 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { Burn } from "../libraries/Burn.sol";
import { Burn } from "../libraries/Burn.sol";
import { Arithmetic } from "../libraries/Arithmetic.sol";
import { Arithmetic } from "../libraries/Arithmetic.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
/**
/**
* @custom:upgradeable
* @custom:upgradeable
...
@@ -28,6 +27,36 @@ abstract contract ResourceMetering is Initializable {
...
@@ -28,6 +27,36 @@ abstract contract ResourceMetering is Initializable {
uint64 prevBlockNum;
uint64 prevBlockNum;
}
}
/**
* @notice Represents the configuration for the EIP-1559 based curve for the deposit gas
* market. These values should be set with care as it is possible to set them in
* a way that breaks the deposit gas market. The target resource limit is defined as
* maxResourceLimit / elasticityMultiplier. This struct was designed to fit within a
* single word. There is additional space for additions in the future.
*
* @custom:field maxResourceLimit Represents the maximum amount of deposit gas that
* can be purchased per block.
* @custom:field elasticityMultiplier Determines the target resource limit along with
* the resource limit.
* @custom:field baseFeeMaxChangeDenominator Determines max change on fee per block.
* @custom:field minimumBaseFee The min deposit base fee, it is clamped to this value.
* @custom:field systemTxMaxGas The amount of gas supplied to the system
* transaction. This should be set to the same number
* that the op-node sets as the gas limit for the
* system transaction.
* @custom:field maximumBaseFee The max deposit base fee, it is clamped to this
* value.
*/
struct ResourceConfig {
uint32 maxResourceLimit;
uint8 elasticityMultiplier;
uint8 baseFeeMaxChangeDenominator;
uint32 minimumBaseFee;
uint32 systemTxMaxGas;
uint128 maximumBaseFee;
}
/**
/**
* @notice EIP-1559 style gas parameters.
* @notice EIP-1559 style gas parameters.
*/
*/
...
@@ -64,7 +93,7 @@ abstract contract ResourceMetering is Initializable {
...
@@ -64,7 +93,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();
ResourceConfig memory config = _resourceConfig();
int256 targetResourceLimit = int256(uint256(config.maxResourceLimit)) /
int256 targetResourceLimit = int256(uint256(config.maxResourceLimit)) /
int256(uint256(config.elasticityMultiplier));
int256(uint256(config.elasticityMultiplier));
...
@@ -138,7 +167,7 @@ abstract contract ResourceMetering is Initializable {
...
@@ -138,7 +167,7 @@ abstract contract ResourceMetering is Initializable {
* @notice Virtual function that returns the resource config. Contracts that inherit this
* @notice Virtual function that returns the resource config. Contracts that inherit this
* contract must implement this function.
* contract must implement this function.
*/
*/
function _resourceConfig() internal virtual returns (
SystemConfig.
ResourceConfig memory);
function _resourceConfig() internal virtual returns (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
...
...
packages/contracts-bedrock/contracts/L1/SystemConfig.sol
View file @
f3654da7
...
@@ -5,6 +5,7 @@ import {
...
@@ -5,6 +5,7 @@ import {
OwnableUpgradeable
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Semver } from "../universal/Semver.sol";
import { Semver } from "../universal/Semver.sol";
import { ResourceMetering } from "./ResourceMetering.sol";
/**
/**
* @title SystemConfig
* @title SystemConfig
...
@@ -29,38 +30,6 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -29,38 +30,6 @@ contract SystemConfig is OwnableUpgradeable, Semver {
UNSAFE_BLOCK_SIGNER
UNSAFE_BLOCK_SIGNER
}
}
/**
* @notice Represents the configuration for the EIP-1559 based curve for
* the deposit gas market. These values should be set with care
* as it is possible to set them in a way that breaks the deposit
* gas market. The target resource limit is defined as
* maxResourceLimit / elasticityMultiplier.
* This struct was designed to fit within a single word. There is
* additional space for additions in the future.
*
* @custom:field maxResourceLimit Represents the maximum amount of deposit
* gas that can be purchased per block.
* @custom:field elasticityMultiplier Determines the target resource limit
* along with the resource limit.
* @custom:field baseFeeMaxChangeDenominator Determines max change on fee per block.
* @custom:field minimumBaseFee The min deposit base fee, it is clamped to this
* value.
* @custom:field systemTxMaxGas The amount of gas supplied to the system
* transaction. This should be set to the same number
* that the op-node sets as the gas limit for the
* system transaction.
* @custom:field maximumBaseFee The max deposit base fee, it is clamped to this
* value.
*/
struct ResourceConfig {
uint32 maxResourceLimit;
uint8 elasticityMultiplier;
uint8 baseFeeMaxChangeDenominator;
uint32 minimumBaseFee;
uint32 systemTxMaxGas;
uint128 maximumBaseFee;
}
/**
/**
* @notice Version identifier, used for upgrades.
* @notice Version identifier, used for upgrades.
*/
*/
...
@@ -106,7 +75,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -106,7 +75,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
* to meter the cost of buying L2 gas on L1. Set as internal and wrapped with a getter
* to meter the cost of buying L2 gas on L1. Set as internal and wrapped with a getter
* so that the struct is returned instead of a tuple.
* so that the struct is returned instead of a tuple.
*/
*/
ResourceConfig internal _resourceConfig;
Resource
Metering.Resource
Config internal _resourceConfig;
/**
/**
* @notice Emitted when configuration is updated
* @notice Emitted when configuration is updated
...
@@ -135,7 +104,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -135,7 +104,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
bytes32 _batcherHash,
bytes32 _batcherHash,
uint64 _gasLimit,
uint64 _gasLimit,
address _unsafeBlockSigner,
address _unsafeBlockSigner,
ResourceConfig memory _config
Resource
Metering.Resource
Config memory _config
) Semver(1, 1, 0) {
) Semver(1, 1, 0) {
initialize({
initialize({
_owner: _owner,
_owner: _owner,
...
@@ -167,7 +136,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -167,7 +136,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
bytes32 _batcherHash,
bytes32 _batcherHash,
uint64 _gasLimit,
uint64 _gasLimit,
address _unsafeBlockSigner,
address _unsafeBlockSigner,
ResourceConfig memory _config
Resource
Metering.Resource
Config memory _config
) public initializer {
) public initializer {
__Ownable_init();
__Ownable_init();
transferOwnership(_owner);
transferOwnership(_owner);
...
@@ -279,7 +248,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -279,7 +248,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*
*
* @return ResourceConfig
* @return ResourceConfig
*/
*/
function resourceConfig() external view returns (ResourceConfig memory) {
function resourceConfig() external view returns (Resource
Metering.Resource
Config memory) {
return _resourceConfig;
return _resourceConfig;
}
}
...
@@ -290,7 +259,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -290,7 +259,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*
*
* @param _config The new resource config values.
* @param _config The new resource config values.
*/
*/
function setResourceConfig(ResourceConfig memory _config) external onlyOwner {
function setResourceConfig(Resource
Metering.Resource
Config memory _config) external onlyOwner {
_setResourceConfig(_config);
_setResourceConfig(_config);
}
}
...
@@ -300,7 +269,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
...
@@ -300,7 +269,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*
*
* @param _config The new resource config
* @param _config The new resource config
*/
*/
function _setResourceConfig(ResourceConfig memory _config) internal {
function _setResourceConfig(Resource
Metering.Resource
Config memory _config) internal {
// min base fee must be less than or equal to max base fee
// min base fee must be less than or equal to max base fee
require(
require(
_config.minimumBaseFee <= _config.maximumBaseFee,
_config.minimumBaseFee <= _config.maximumBaseFee,
...
...
packages/contracts-bedrock/contracts/deployment/SystemDictator.sol
View file @
f3654da7
...
@@ -16,6 +16,7 @@ import { ProxyAdmin } from "../universal/ProxyAdmin.sol";
...
@@ -16,6 +16,7 @@ import { ProxyAdmin } from "../universal/ProxyAdmin.sol";
import { OptimismMintableERC20Factory } from "../universal/OptimismMintableERC20Factory.sol";
import { OptimismMintableERC20Factory } from "../universal/OptimismMintableERC20Factory.sol";
import { PortalSender } from "./PortalSender.sol";
import { PortalSender } from "./PortalSender.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
/**
/**
* @title SystemDictator
* @title SystemDictator
...
@@ -79,7 +80,7 @@ contract SystemDictator is OwnableUpgradeable {
...
@@ -79,7 +80,7 @@ contract SystemDictator is OwnableUpgradeable {
bytes32 batcherHash;
bytes32 batcherHash;
uint64 gasLimit;
uint64 gasLimit;
address unsafeBlockSigner;
address unsafeBlockSigner;
SystemConfi
g.ResourceConfig resourceConfig;
ResourceMeterin
g.ResourceConfig resourceConfig;
}
}
/**
/**
...
@@ -161,7 +162,7 @@ contract SystemDictator is OwnableUpgradeable {
...
@@ -161,7 +162,7 @@ contract SystemDictator is OwnableUpgradeable {
* initialized upon deployment.
* initialized upon deployment.
*/
*/
constructor() {
constructor() {
SystemConfig.ResourceConfig memory rcfg = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory rcfg = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
...
packages/contracts-bedrock/contracts/echidna/FuzzOptimismPortal.sol
View file @
f3654da7
...
@@ -4,13 +4,14 @@ import { OptimismPortal } from "../L1/OptimismPortal.sol";
...
@@ -4,13 +4,14 @@ import { OptimismPortal } from "../L1/OptimismPortal.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { AddressAliasHelper } from "../vendor/AddressAliasHelper.sol";
import { AddressAliasHelper } from "../vendor/AddressAliasHelper.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
contract EchidnaFuzzOptimismPortal {
contract EchidnaFuzzOptimismPortal {
OptimismPortal internal portal;
OptimismPortal internal portal;
bool internal failedToComplete;
bool internal failedToComplete;
constructor() {
constructor() {
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
...
packages/contracts-bedrock/contracts/echidna/FuzzResourceMetering.sol
View file @
f3654da7
pragma solidity 0.8.15;
pragma solidity 0.8.15;
import { ResourceMetering } from "../L1/ResourceMetering.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { Arithmetic } from "../libraries/Arithmetic.sol";
import { Arithmetic } from "../libraries/Arithmetic.sol";
import { StdUtils } from "forge-std/Test.sol";
import { StdUtils } from "forge-std/Test.sol";
...
@@ -25,12 +24,12 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils {
...
@@ -25,12 +24,12 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils {
__ResourceMetering_init();
__ResourceMetering_init();
}
}
function resourceConfig() public pure returns (
SystemConfi
g.ResourceConfig memory) {
function resourceConfig() public pure returns (
ResourceMeterin
g.ResourceConfig memory) {
return _resourceConfig();
return _resourceConfig();
}
}
function _resourceConfig() internal pure override returns (
SystemConfi
g.ResourceConfig memory) {
function _resourceConfig() internal pure override returns (
ResourceMeterin
g.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -51,7 +50,7 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils {
...
@@ -51,7 +50,7 @@ contract EchidnaFuzzResourceMetering is ResourceMetering, StdUtils {
uint256 cachedPrevBoughtGas = uint256(params.prevBoughtGas);
uint256 cachedPrevBoughtGas = uint256(params.prevBoughtGas);
uint256 cachedPrevBlockNum = uint256(params.prevBlockNum);
uint256 cachedPrevBlockNum = uint256(params.prevBlockNum);
SystemConfi
g.ResourceConfig memory rcfg = resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = resourceConfig();
uint256 targetResourceLimit = uint256(rcfg.maxResourceLimit) /
uint256 targetResourceLimit = uint256(rcfg.maxResourceLimit) /
uint256(rcfg.elasticityMultiplier);
uint256(rcfg.elasticityMultiplier);
...
...
packages/contracts-bedrock/contracts/libraries/Constants.sol
View file @
f3654da7
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.0;
import { ResourceMetering } from "../L1/ResourceMetering.sol";
/**
/**
* @title Constants
* @title Constants
* @notice Constants is a library for storing constants. Simple! Don't put everything in here, just
* @notice Constants is a library for storing constants. Simple! Don't put everything in here, just
...
@@ -24,4 +26,20 @@ library Constants {
...
@@ -24,4 +26,20 @@ library Constants {
* non-zero to reduce the gas cost of message passing transactions.
* non-zero to reduce the gas cost of message passing transactions.
*/
*/
address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD;
address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD;
/**
* @notice Returns the default values for the ResourceConfig. These are the recommended values
* for a production network.
*/
function DEFAULT_RESOURCE_CONFIG() internal pure returns (ResourceMetering.ResourceConfig memory) {
ResourceMetering.ResourceConfig memory config = ResourceMetering.ResourceConfig({
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: 1 gwei,
systemTxMaxGas: 1_000_000,
maximumBaseFee: type(uint128).max
});
return config;
}
}
}
packages/contracts-bedrock/contracts/test/CommonTest.t.sol
View file @
f3654da7
...
@@ -29,6 +29,7 @@ import { IL1ChugSplashDeployer } from "../legacy/L1ChugSplashProxy.sol";
...
@@ -29,6 +29,7 @@ import { IL1ChugSplashDeployer } from "../legacy/L1ChugSplashProxy.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { LegacyMintableERC20 } from "../legacy/LegacyMintableERC20.sol";
import { LegacyMintableERC20 } from "../legacy/LegacyMintableERC20.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
contract CommonTest is Test {
contract CommonTest is Test {
address alice = address(128);
address alice = address(128);
...
@@ -171,7 +172,7 @@ contract Portal_Initializer is L2OutputOracle_Initializer {
...
@@ -171,7 +172,7 @@ contract Portal_Initializer is L2OutputOracle_Initializer {
function setUp() public virtual override {
function setUp() public virtual override {
super.setUp();
super.setUp();
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
...
packages/contracts-bedrock/contracts/test/OptimismPortal.t.sol
View file @
f3654da7
...
@@ -9,7 +9,7 @@ import { OptimismPortal } from "../L1/OptimismPortal.sol";
...
@@ -9,7 +9,7 @@ import { OptimismPortal } from "../L1/OptimismPortal.sol";
import { Types } from "../libraries/Types.sol";
import { Types } from "../libraries/Types.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Proxy } from "../universal/Proxy.sol";
import { Proxy } from "../universal/Proxy.sol";
import {
SystemConfig } from "../L1/SystemConfi
g.sol";
import {
ResourceMetering } from "../L1/ResourceMeterin
g.sol";
contract OptimismPortal_Test is Portal_Initializer {
contract OptimismPortal_Test is Portal_Initializer {
event Paused(address);
event Paused(address);
...
@@ -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();
SystemConfi
g.ResourceConfig memory rcfg = systemConfig.resourceConfig();
ResourceMeterin
g.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);
...
...
packages/contracts-bedrock/contracts/test/ResourceMetering.t.sol
View file @
f3654da7
...
@@ -3,8 +3,8 @@ pragma solidity 0.8.15;
...
@@ -3,8 +3,8 @@ pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { Test } from "forge-std/Test.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { Proxy } from "../universal/Proxy.sol";
import { Proxy } from "../universal/Proxy.sol";
import { Constants } from "../libraries/Constants.sol";
contract MeterUser is ResourceMetering {
contract MeterUser is ResourceMetering {
constructor() {
constructor() {
...
@@ -15,20 +15,12 @@ contract MeterUser is ResourceMetering {
...
@@ -15,20 +15,12 @@ contract MeterUser is ResourceMetering {
__ResourceMetering_init();
__ResourceMetering_init();
}
}
function resourceConfig() public pure returns (
SystemConfi
g.ResourceConfig memory) {
function resourceConfig() public pure returns (
ResourceMeterin
g.ResourceConfig memory) {
return _resourceConfig();
return _resourceConfig();
}
}
function _resourceConfig() internal pure override returns (SystemConfig.ResourceConfig memory) {
function _resourceConfig() internal pure override returns (ResourceMetering.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
return Constants.DEFAULT_RESOURCE_CONFIG();
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: 1 gwei,
systemTxMaxGas: 1_000_000,
maximumBaseFee: type(uint128).max
});
return config;
}
}
function use(uint64 _amount) public metered(_amount) {}
function use(uint64 _amount) public metered(_amount) {}
...
@@ -62,7 +54,7 @@ contract ResourceMetering_Test is Test {
...
@@ -62,7 +54,7 @@ contract ResourceMetering_Test is Test {
function test_meter_initialResourceParams_succeeds() external {
function test_meter_initialResourceParams_succeeds() external {
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = meter.params();
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = meter.params();
SystemConfi
g.ResourceConfig memory rcfg = meter.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = meter.resourceConfig();
assertEq(prevBaseFee, rcfg.minimumBaseFee);
assertEq(prevBaseFee, rcfg.minimumBaseFee);
assertEq(prevBoughtGas, 0);
assertEq(prevBoughtGas, 0);
...
@@ -111,7 +103,7 @@ contract ResourceMetering_Test is Test {
...
@@ -111,7 +103,7 @@ contract ResourceMetering_Test is Test {
}
}
function test_meter_updateNoGasDelta_succeeds() external {
function test_meter_updateNoGasDelta_succeeds() external {
SystemConfi
g.ResourceConfig memory rcfg = meter.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = meter.resourceConfig();
uint256 target = uint256(rcfg.maxResourceLimit) / uint256(rcfg.elasticityMultiplier);
uint256 target = uint256(rcfg.maxResourceLimit) / uint256(rcfg.elasticityMultiplier);
meter.use(uint64(target));
meter.use(uint64(target));
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = meter.params();
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = meter.params();
...
@@ -122,7 +114,7 @@ contract ResourceMetering_Test is Test {
...
@@ -122,7 +114,7 @@ contract ResourceMetering_Test is Test {
}
}
function test_meter_useMax_succeeds() external {
function test_meter_useMax_succeeds() external {
SystemConfi
g.ResourceConfig memory rcfg = meter.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = meter.resourceConfig();
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
...
@@ -138,7 +130,7 @@ contract ResourceMetering_Test is Test {
...
@@ -138,7 +130,7 @@ contract ResourceMetering_Test is Test {
}
}
function test_meter_useMoreThanMax_reverts() external {
function test_meter_useMoreThanMax_reverts() external {
SystemConfi
g.ResourceConfig memory rcfg = meter.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = meter.resourceConfig();
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
...
@@ -153,7 +145,7 @@ contract ResourceMetering_Test is Test {
...
@@ -153,7 +145,7 @@ contract ResourceMetering_Test is Test {
// At 12 seconds per block, this number is effectively unreachable.
// At 12 seconds per block, this number is effectively unreachable.
vm.assume(_blockDiff < 433576281058164217753225238677900874458691);
vm.assume(_blockDiff < 433576281058164217753225238677900874458691);
SystemConfi
g.ResourceConfig memory rcfg = meter.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = meter.resourceConfig();
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 target = uint64(rcfg.maxResourceLimit) / uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
uint64 elasticityMultiplier = uint64(rcfg.elasticityMultiplier);
...
@@ -184,16 +176,8 @@ contract CustomMeterUser is ResourceMetering {
...
@@ -184,16 +176,8 @@ contract CustomMeterUser is ResourceMetering {
});
});
}
}
function _resourceConfig() internal pure override returns (SystemConfig.ResourceConfig memory) {
function _resourceConfig() internal pure override returns (ResourceMetering.ResourceConfig memory) {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
return Constants.DEFAULT_RESOURCE_CONFIG();
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: 1 gwei,
systemTxMaxGas: 1_000_000,
maximumBaseFee: type(uint128).max
});
return config;
}
}
function use(uint64 _amount) public returns (uint256) {
function use(uint64 _amount) public returns (uint256) {
...
@@ -238,7 +222,7 @@ contract ArtifactResourceMetering_Test is Test {
...
@@ -238,7 +222,7 @@ contract ArtifactResourceMetering_Test is Test {
vm.roll(1_000_000);
vm.roll(1_000_000);
MeterUser base = new MeterUser();
MeterUser base = new MeterUser();
SystemConfi
g.ResourceConfig memory rcfg = base.resourceConfig();
ResourceMeterin
g.ResourceConfig memory rcfg = base.resourceConfig();
minimumBaseFee = uint128(rcfg.minimumBaseFee);
minimumBaseFee = uint128(rcfg.minimumBaseFee);
maximumBaseFee = rcfg.maximumBaseFee;
maximumBaseFee = rcfg.maximumBaseFee;
maxResourceLimit = uint64(rcfg.maxResourceLimit);
maxResourceLimit = uint64(rcfg.maxResourceLimit);
...
...
packages/contracts-bedrock/contracts/test/SystemConfig.t.sol
View file @
f3654da7
...
@@ -3,6 +3,7 @@ pragma solidity 0.8.15;
...
@@ -3,6 +3,7 @@ pragma solidity 0.8.15;
import { CommonTest } from "./CommonTest.t.sol";
import { CommonTest } from "./CommonTest.t.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
import { ResourceMetering } from "../L1/ResourceMetering.sol";
contract SystemConfig_Init is CommonTest {
contract SystemConfig_Init is CommonTest {
SystemConfig sysConf;
SystemConfig sysConf;
...
@@ -10,7 +11,7 @@ contract SystemConfig_Init is CommonTest {
...
@@ -10,7 +11,7 @@ contract SystemConfig_Init is CommonTest {
function setUp() public virtual override {
function setUp() public virtual override {
super.setUp();
super.setUp();
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -35,7 +36,7 @@ contract SystemConfig_Initialize_TestFail is SystemConfig_Init {
...
@@ -35,7 +36,7 @@ contract SystemConfig_Initialize_TestFail is SystemConfig_Init {
function test_initialize_lowGasLimit_reverts() external {
function test_initialize_lowGasLimit_reverts() external {
uint64 minimumGasLimit = sysConf.minimumGasLimit();
uint64 minimumGasLimit = sysConf.minimumGasLimit();
SystemConfig.ResourceConfig memory cfg = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory cfg = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -80,7 +81,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
...
@@ -80,7 +81,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
function test_setResourceConfig_notOwner_reverts() external {
function test_setResourceConfig_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert("Ownable: caller is not the owner");
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -92,7 +93,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
...
@@ -92,7 +93,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
}
}
function test_setResourceConfig_badMinMax_reverts() external {
function test_setResourceConfig_badMinMax_reverts() external {
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -106,7 +107,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
...
@@ -106,7 +107,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
}
}
function test_setResourceConfig_zeroDenominator_reverts() external {
function test_setResourceConfig_zeroDenominator_reverts() external {
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 0,
baseFeeMaxChangeDenominator: 0,
...
@@ -122,7 +123,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
...
@@ -122,7 +123,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
function test_setResourceConfig_lowGasLimit_reverts() external {
function test_setResourceConfig_lowGasLimit_reverts() external {
uint64 gasLimit = sysConf.gasLimit();
uint64 gasLimit = sysConf.gasLimit();
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: uint32(gasLimit),
maxResourceLimit: uint32(gasLimit),
elasticityMultiplier: 10,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
@@ -136,7 +137,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
...
@@ -136,7 +137,7 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
}
}
function test_setResourceConfig_badPrecision_reverts() external {
function test_setResourceConfig_badPrecision_reverts() external {
SystemConfig.ResourceConfig memory config = SystemConfi
g.ResourceConfig({
ResourceMetering.ResourceConfig memory config = ResourceMeterin
g.ResourceConfig({
maxResourceLimit: 20_000_000,
maxResourceLimit: 20_000_000,
elasticityMultiplier: 11,
elasticityMultiplier: 11,
baseFeeMaxChangeDenominator: 8,
baseFeeMaxChangeDenominator: 8,
...
...
packages/contracts-bedrock/contracts/test/invariants/SystemConfig.t.sol
View file @
f3654da7
...
@@ -2,19 +2,14 @@ pragma solidity 0.8.15;
...
@@ -2,19 +2,14 @@ pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { Test } from "forge-std/Test.sol";
import { SystemConfig } from "../../L1/SystemConfig.sol";
import { SystemConfig } from "../../L1/SystemConfig.sol";
import { ResourceMetering } from "../../L1/ResourceMetering.sol";
import { Constants } from "../../libraries/Constants.sol";
contract SystemConfig_GasLimitLowerBound_Invariant is Test {
contract SystemConfig_GasLimitLowerBound_Invariant is Test {
SystemConfig public config;
SystemConfig public config;
function setUp() public {
function setUp() public {
SystemConfig.ResourceConfig memory cfg = SystemConfig.ResourceConfig({
ResourceMetering.ResourceConfig memory cfg = Constants.DEFAULT_RESOURCE_CONFIG();
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: 1 gwei,
systemTxMaxGas: 1_000_000,
maximumBaseFee: type(uint128).max
});
config = new SystemConfig({
config = new SystemConfig({
_owner: address(0xbeef),
_owner: address(0xbeef),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment