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
a2166dca
Unverified
Commit
a2166dca
authored
Dec 01, 2022
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctb: Add echidna tests for metering
parent
2220fb09
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
late-cameras-jam.md
.changeset/late-cameras-jam.md
+5
-0
config.yml
.circleci/config.yml
+4
-0
FuzzResourceMetering.sol
...tracts-bedrock/contracts/echidna/FuzzResourceMetering.sol
+114
-0
No files found.
.changeset/late-cameras-jam.md
0 → 100644
View file @
a2166dca
---
'
@eth-optimism/contracts-bedrock'
:
patch
---
Add echidna tests for metering
.circleci/config.yml
View file @
a2166dca
...
...
@@ -830,6 +830,10 @@ workflows:
size
:
2xlarge
requires
:
-
bedrock-echidna-build
-
bedrock-echidna-run
:
echidna_target
:
metering
requires
:
-
bedrock-echidna-build
-
op-bindings-build
:
requires
:
-
yarn-monorepo
...
...
packages/contracts-bedrock/contracts/echidna/FuzzResourceMetering.sol
0 → 100644
View file @
a2166dca
pragma solidity 0.8.15;
import { ResourceMetering } from "../L1/ResourceMetering.sol";
contract EchidnaFuzzResourceMetering is ResourceMetering {
bool failedMaxGasPerBlock;
bool failedRaiseBasefee;
bool failedLowerBasefee;
bool failedNeverBelowMinBasefee;
bool failedMaxRaiseBasefeePerBlock;
bool failedMaxLowerBasefeePerBlock;
constructor() {
initialize();
}
function initialize() public initializer {
__ResourceMetering_init();
}
/**
* @notice Takes the necessary parameters to allow us to burn arbitrary amounts of gas to test
* the underlying resource metering/gas market logic
*/
function testBurn(uint256 _gasToBurn, bool _raiseBaseFee) public {
// Part 1: we cache the current param values and do some basic checks on them.
uint256 cachedPrevBaseFee = uint256(params.prevBaseFee);
uint256 cachedPrevBoughtGas = uint256(params.prevBoughtGas);
uint256 cachedPrevBlockNum = uint256(params.prevBlockNum);
uint256 maxBasefeeChange = cachedPrevBaseFee / uint256(BASE_FEE_MAX_CHANGE_DENOMINATOR);
// check that the last block's base fee hasn't dropped below the minimum
if (cachedPrevBaseFee < uint256(MINIMUM_BASE_FEE)) {
failedNeverBelowMinBasefee = true;
}
// check that the last block didn't consume more than the max amount of gas
if (cachedPrevBoughtGas > uint256(MAX_RESOURCE_LIMIT)) {
failedMaxGasPerBlock = true;
}
// Part2: we perform the gas burn
// force the gasToBurn into the correct range based on whether we intend to
// raise or lower the basefee after this block, respectively
uint256 gasToBurn;
if (_raiseBaseFee) {
gasToBurn =
(_gasToBurn % (uint256(MAX_RESOURCE_LIMIT) - uint256(TARGET_RESOURCE_LIMIT))) +
uint256(TARGET_RESOURCE_LIMIT);
} else {
gasToBurn = _gasToBurn % uint256(TARGET_RESOURCE_LIMIT);
}
_burnInternal(uint64(gasToBurn));
// Part 3: we run checks and modify our invariant flags based on the updated params values
// if the last block used more than the target amount of gas (and there were no
// empty blocks in between), ensure this block's basefee increased, but not by
// more than the max amount per block
if (
(cachedPrevBoughtGas > uint256(TARGET_RESOURCE_LIMIT)) &&
(uint256(params.prevBlockNum) - cachedPrevBlockNum == 1)
) {
failedRaiseBasefee = failedRaiseBasefee || (params.prevBaseFee <= cachedPrevBaseFee);
failedMaxRaiseBasefeePerBlock =
failedMaxRaiseBasefeePerBlock ||
((uint256(params.prevBaseFee) - cachedPrevBaseFee) < maxBasefeeChange);
}
// if the last blocked used less than the target amount of gas (and currently,
// that there were no empty blocks in between), ensure this block's basefee decreased,
// but not by more than the max amount
if (
(cachedPrevBoughtGas < uint256(TARGET_RESOURCE_LIMIT)) ||
(uint256(params.prevBlockNum) - cachedPrevBlockNum > 1)
) {
failedLowerBasefee =
failedLowerBasefee ||
(uint256(params.prevBaseFee) > cachedPrevBaseFee);
// TODO: account for empty blocks
if (params.prevBlockNum - cachedPrevBlockNum == 1) {
failedMaxLowerBasefeePerBlock =
failedMaxLowerBasefeePerBlock ||
((cachedPrevBaseFee - uint256(params.prevBaseFee)) < maxBasefeeChange);
}
}
}
function _burnInternal(uint64 _gasToBurn) private metered(_gasToBurn) {}
function echidna_high_usage_raise_basefee() public view returns (bool) {
return !failedRaiseBasefee;
}
function echidna_low_usage_lower_basefee() public view returns (bool) {
return !failedLowerBasefee;
}
function echidna_never_below_min_basefee() public view returns (bool) {
return !failedNeverBelowMinBasefee;
}
function echidna_never_above_max_gas_limit() public view returns (bool) {
return !failedMaxGasPerBlock;
}
function echidna_never_exceed_max_increase() public view returns (bool) {
return !failedMaxRaiseBasefeePerBlock;
}
function echidna_never_exceed_max_decrease() public view returns (bool) {
return !failedMaxLowerBasefeePerBlock;
}
}
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