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
85dfa9fe
Unverified
Commit
85dfa9fe
authored
Dec 01, 2022
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctb: Add echidna tests for encoding
parent
b34d4ff1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
0 deletions
+78
-0
new-mayflies-shave.md
.changeset/new-mayflies-shave.md
+6
-0
config.yml
.circleci/config.yml
+5
-0
FuzzEncoding.sol
...ages/contracts-bedrock/contracts/echidna/FuzzEncoding.sol
+67
-0
No files found.
.changeset/new-mayflies-shave.md
0 → 100644
View file @
85dfa9fe
---
'
@eth-optimism/ci-builder'
:
patch
'
@eth-optimism/contracts-bedrock'
:
patch
---
Add echidna tests for encoding
.circleci/config.yml
View file @
85dfa9fe
...
@@ -833,6 +833,11 @@ workflows:
...
@@ -833,6 +833,11 @@ workflows:
size
:
2xlarge
size
:
2xlarge
requires
:
requires
:
-
bedrock-echidna-build
-
bedrock-echidna-build
-
bedrock-echidna-run
:
name
:
Bedrock Echidna Encoding Test
echidna_target
:
encoding
requires
:
-
bedrock-echidna-build
-
bedrock-echidna-run
:
-
bedrock-echidna-run
:
name
:
Bedrock Echidna Metering Test
name
:
Bedrock Echidna Metering Test
echidna_target
:
metering
echidna_target
:
metering
...
...
packages/contracts-bedrock/contracts/echidna/FuzzEncoding.sol
0 → 100644
View file @
85dfa9fe
pragma solidity 0.8.15;
import { Encoding } from "../libraries/Encoding.sol";
contract EchidnaFuzzEncoding {
bool failedRoundtripAToB;
bool failedRoundtripBToA;
/**
* @notice Takes a pair of integers to be encoded into a versioned nonce with the
* Encoding library and then decoded and updates the test contract's state
* indicating if the round trip encoding failed.
*/
function testRoundTripAToB(uint240 _nonce, uint16 _version) public {
// Encode the nonce and version
uint256 encodedVersionedNonce = Encoding.encodeVersionedNonce(_nonce, _version);
// Decode the nonce and version
uint240 decodedNonce;
uint16 decodedVersion;
(decodedNonce, decodedVersion) = Encoding.decodeVersionedNonce(encodedVersionedNonce);
// If our round trip encoding did not return the original result, set our state.
if ((decodedNonce != _nonce) || (decodedVersion != _version)) {
failedRoundtripAToB = true;
}
}
/**
* @notice Takes an integer representing a packed version and nonce and attempts
* to decode them using the Encoding library before re-encoding and updates
* the test contract's state indicating if the round trip encoding failed.
*/
function testRoundTripBToA(uint256 _versionedNonce) public {
// Decode the nonce and version
uint240 decodedNonce;
uint16 decodedVersion;
(decodedNonce, decodedVersion) = Encoding.decodeVersionedNonce(_versionedNonce);
// Encode the nonce and version
uint256 encodedVersionedNonce = Encoding.encodeVersionedNonce(decodedNonce, decodedVersion);
// If our round trip encoding did not return the original result, set our state.
if (encodedVersionedNonce != _versionedNonce) {
failedRoundtripBToA = true;
}
}
/**
* @notice Verifies that testRoundTripAToB did not ever fail.
*/
function echidna_round_trip_encoding_AToB() public view returns (bool) {
// ASSERTION: The round trip encoding done in testRoundTripAToB(...)
return !failedRoundtripAToB;
}
/**
* @notice Verifies that testRoundTripBToA did not ever fail.
*/
function echidna_round_trip_encoding_BToA() public view returns (bool) {
// ASSERTION: The round trip encoding done in testRoundTripBToA should never
// fail.
return !failedRoundtripBToA;
}
}
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