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
ba5742b5
Unverified
Commit
ba5742b5
authored
Dec 02, 2022
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctb: Make FuzzBurn more robust against overflows
parent
0f8fc58a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
FuzzBurn.sol
packages/contracts-bedrock/contracts/echidna/FuzzBurn.sol
+19
-10
No files found.
packages/contracts-bedrock/contracts/echidna/FuzzBurn.sol
View file @
ba5742b5
pragma solidity 0.8.15;
pragma solidity 0.8.15;
import { Burn } from "../libraries/Burn.sol";
import { Burn } from "../libraries/Burn.sol";
import { StdUtils } from "forge-std/Test.sol";
contract EchidnaFuzzBurn {
contract EchidnaFuzzBurn
is StdUtils
{
bool failedEthBurn;
bool failedEthBurn;
bool failedGasBurn;
bool failedGasBurn;
...
@@ -13,14 +14,16 @@ contract EchidnaFuzzBurn {
...
@@ -13,14 +14,16 @@ contract EchidnaFuzzBurn {
function testBurn(uint256 _value) public {
function testBurn(uint256 _value) public {
// cache the contract's eth balance
// cache the contract's eth balance
uint256 preBurnBalance = address(this).balance;
uint256 preBurnBalance = address(this).balance;
uint256 value = bound(_value, 0, preBurnBalance);
// execute a burn of _value eth
// execute a burn of _value eth
// (may way to add guardrails to this value rather than a truly unbounded uint256)
Burn.eth(value);
Burn.eth(_value);
// check that exactly _value eth was transfered from the contract
// check that exactly value eth was transfered from the contract
if (address(this).balance != preBurnBalance - _value) {
unchecked {
failedEthBurn = true;
if (address(this).balance != preBurnBalance - value) {
failedEthBurn = true;
}
}
}
}
}
...
@@ -30,18 +33,24 @@ contract EchidnaFuzzBurn {
...
@@ -30,18 +33,24 @@ contract EchidnaFuzzBurn {
* by the library
* by the library
*/
*/
function testGas(uint256 _value) public {
function testGas(uint256 _value) public {
// cap the value to the max resource limit
uint256 MAX_RESOURCE_LIMIT = 8_000_000;
uint256 value = bound(_value, 0, MAX_RESOURCE_LIMIT);
// cache the contract's current remaining gas
// cache the contract's current remaining gas
uint256 preBurnGas = gasleft();
uint256 preBurnGas = gasleft();
// execute the gas burn
// execute the gas burn
Burn.gas(
_
value);
Burn.gas(value);
// cache the remaining gas post burn
// cache the remaining gas post burn
uint256 postBurnGas = gasleft();
uint256 postBurnGas = gasleft();
// check that at least _value gas was burnt
// check that at least value gas was burnt (and that there was no underflow)
if (postBurnGas > preBurnGas - _value) {
unchecked {
failedGasBurn = true;
if (postBurnGas - preBurnGas > value || preBurnGas - value > preBurnGas) {
failedGasBurn = true;
}
}
}
}
}
...
...
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