Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bare bones for differential fuzzing #421

Merged
merged 8 commits into from May 31, 2021
Merged

Conversation

satyamakgec
Copy link
Contributor

What was wrong?

Needs fuzzing of contracts.

How was it fixed?

It consists of the fuzzing setup for the erc20.fe and erc20.sol and has the rearrangements for the compiler tests as an independent directory to avoid circular dependency and it will also decrease the test execution time as it doesn't require rebuilding the dependencies again.

To run the fuzzer - cd fuzz && cargo +nightly fuzz run erc20_target --features solc-backend

To-Do

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2021

Codecov Report

Merging #421 (52ce86d) into master (1760025) will decrease coverage by 0.20%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #421      +/-   ##
==========================================
- Coverage   86.64%   86.43%   -0.21%     
==========================================
  Files          68       69       +1     
  Lines        4147     4431     +284     
==========================================
+ Hits         3593     3830     +237     
- Misses        554      601      +47     
Impacted Files Coverage Δ
test-utils/src/lib.rs 83.80% <69.23%> (ø)
compiler/src/lowering/names.rs 70.96% <0.00%> (-3.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1760025...52ce86d. Read the comment docs.

@sbillig
Copy link
Collaborator

sbillig commented May 26, 2021

ohh sorry @sbillig I should have mention this in the readme. It only works with the feature flag i.e solc-backend

Ha! Somehow I didn't think of that, despite using --all-features all day long to run other tests. Thanks.

Copy link
Collaborator

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited to see it coming together. Sorry, not a thorough review, I can't squeeze anymore out of the day. Counting on more pairs of 👀 to go over it within the next few hours anyway.

test-utils/src/lib.rs Outdated Show resolved Hide resolved
test-utils/src/lib.rs Outdated Show resolved Hide resolved
# toolchain: stable
# override: true
# - name: Run WASM tests
# run: wasm-pack test --node -- --workspace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess that was temporary disabled during development for some reason. Can we roll it back now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional because now tests are living in a separate library which needs to go under workspace so new changes lead to compile the solc bindings to wasm as well which is not possible right now as wasm32-unknown-unknown is not supporting c++ bindings right now. We did decided to comment the wasm-pack test cases on the CI and to make it work for now and for the releases we will manually run the wasm-pack test cases locally to verify whether everything is good or not.

fuzz/Cargo.toml Outdated Show resolved Hide resolved
fuzz/Cargo.toml Outdated Show resolved Hide resolved
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy)]
pub struct TransferInfo<'a> {
pub to: &'a str,
pub value: u128,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is limiting the set of possible test cases since in reality the value will be a U256. I guess u128 was chosen for convenience since it is the biggest rust integer but I think we should use the U256 type here that we also use elsewhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to implement this for U256 support:

https://docs.rs/arbitrary/1.0.1/arbitrary/trait.Arbitrary.html

}

pub fn fe_erc20_transfer(info: TransferInfo) {
if info.value >= 1000000000000000000000000 as u128 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind that value check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it should be <= so use shouldn't be able to transfer more than the total supply.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected behavior is that the tx reverts, correct? I think we should be validating this.

test-utils/Cargo.toml Outdated Show resolved Hide resolved
fuzz/Cargo.toml Outdated Show resolved Hide resolved
fuzz/src/erc20.rs Outdated Show resolved Hide resolved
&mut executor,
"test-utils/fuzz/fixtures/fe/erc20.fe", // TODO: Need to fix the path
"ERC20",
&[string_token("Fe Coin"), string_token("FE")],
Copy link
Member

@g-r-a-n-t g-r-a-n-t May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but it doesn't test much.

I think what we eventually want is to have two separate deployed contracts/executors that we perform many state-modifying transactions on in a random order. This will get us into edge cases where we might find bugs.

Of course this doesn't need to be included in this PR, I'm just wondering if you've been thinking about this or had a different direction in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about this to have some kind of random order testing. I have a process in mind where we can come up with some mutation testing where we can randomly mutate the contract as well if we want but that is I think one step forward for now, I am thinking to have some kind of prop testing with random ordering.

@sbillig sbillig merged commit 42a5648 into ethereum:master May 31, 2021
if info.value
<= TOTAL_SUPPLY
.parse::<u128>()
.unwrap_or(1000000000000000000000000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just expect here or make TOTAL_SUPPLY a u128.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will add that change in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants