Skip to content

Commit

Permalink
[Rust/Eth]: Add fuzz tests (#3463)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Oct 6, 2023
1 parent 93c1c1d commit 6f7e78e
Show file tree
Hide file tree
Showing 51 changed files with 3,094 additions and 598 deletions.
80 changes: 5 additions & 75 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/coverage.stats
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90.0
92.0
3 changes: 1 addition & 2 deletions rust/tw_evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ethabi = { version = "18.0.0", features = ["full-serde"] }
itertools = "0.10.5"
lazy_static = "1.4.0"
rlp = "0.5.2"
Expand All @@ -16,7 +15,7 @@ tw_hash = { path = "../tw_hash" }
tw_keypair = { path = "../tw_keypair" }
tw_memory = { path = "../tw_memory" }
tw_misc = { path = "../tw_misc" }
tw_number = { path = "../tw_number", features = ["ethabi"] }
tw_number = { path = "../tw_number" }
tw_proto = { path = "../tw_proto" }

[dev-dependencies]
Expand Down
5 changes: 5 additions & 0 deletions rust/tw_evm/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
corpus
artifacts
coverage
Cargo.lock
54 changes: 54 additions & 0 deletions rust/tw_evm/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[package]
name = "tw_evm-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }
serde_json = "1.0.95"
tw_number = { path = "../../tw_number" }
tw_proto = { path = "../../tw_proto", features = ["fuzz"] }

[dependencies.tw_evm]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "abi_encode_function"
path = "fuzz_targets/abi_encode_function.rs"
test = false
doc = false

[[bin]]
name = "abi_decode_value"
path = "fuzz_targets/abi_decode_value.rs"
test = false
doc = false

[[bin]]
name = "abi_function_decode_input"
path = "fuzz_targets/abi_function_decode_input.rs"
test = false
doc = false

[[bin]]
name = "rlp_encode"
path = "fuzz_targets/rlp_encode.rs"
test = false
doc = false

[[bin]]
name = "sign"
path = "fuzz_targets/sign.rs"
test = false
doc = false
16 changes: 16 additions & 0 deletions rust/tw_evm/fuzz/fuzz_targets/abi_decode_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#![no_main]

use libfuzzer_sys::fuzz_target;
use tw_evm::evm_context::StandardEvmContext;
use tw_evm::modules::abi_encoder::AbiEncoder;
use tw_proto::EthereumAbi::Proto;

fuzz_target!(|input: Proto::ValueDecodingInput<'_>| {
let _ = AbiEncoder::<StandardEvmContext>::decode_value(input);
});
16 changes: 16 additions & 0 deletions rust/tw_evm/fuzz/fuzz_targets/abi_encode_function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#![no_main]

use libfuzzer_sys::fuzz_target;
use tw_evm::evm_context::StandardEvmContext;
use tw_evm::modules::abi_encoder::AbiEncoder;
use tw_proto::EthereumAbi::Proto;

fuzz_target!(|input: Proto::FunctionEncodingInput<'_>| {
let _ = AbiEncoder::<StandardEvmContext>::encode_contract_call(input);
});
16 changes: 16 additions & 0 deletions rust/tw_evm/fuzz/fuzz_targets/abi_function_decode_input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#![no_main]

use libfuzzer_sys::fuzz_target;
use tw_evm::evm_context::StandardEvmContext;
use tw_evm::modules::abi_encoder::AbiEncoder;
use tw_proto::EthereumAbi::Proto;

fuzz_target!(|input: Proto::ParamsDecodingInput<'_>| {
let _ = AbiEncoder::<StandardEvmContext>::decode_params(input);
});
16 changes: 16 additions & 0 deletions rust/tw_evm/fuzz/fuzz_targets/rlp_encode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#![no_main]

use libfuzzer_sys::fuzz_target;
use tw_evm::evm_context::StandardEvmContext;
use tw_evm::modules::rlp_encoder::RlpEncoder;
use tw_proto::EthereumRlp::Proto;

fuzz_target!(|input: Proto::EncodingInput<'_>| {
let _ = RlpEncoder::<StandardEvmContext>::encode_with_proto(input);
});
16 changes: 16 additions & 0 deletions rust/tw_evm/fuzz/fuzz_targets/sign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#![no_main]

use libfuzzer_sys::fuzz_target;
use tw_evm::evm_context::StandardEvmContext;
use tw_evm::modules::signer::Signer;
use tw_proto::Ethereum::Proto;

fuzz_target!(|input: Proto::SigningInput<'_>| {
let _ = Signer::<StandardEvmContext>::sign_proto(input);
});
Loading

0 comments on commit 6f7e78e

Please sign in to comment.