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

[FUZZER] Multiple utils and library refactor, fuzzers #15176

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 156 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions testsuite/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ edition = "2021"
license = { workspace = true }

[dependencies]
aptos-framework = { workspace = true }
aptos-types = { workspace = true }
bcs = { workspace = true }
clap = "4.5.20"
move-core-types = { workspace = true }
22 changes: 21 additions & 1 deletion testsuite/fuzzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ The script includes several functions to manage and execute fuzz tests:
```bash
./fuzz.sh build-oss-fuzz <target_dir>
```

- `coverage`: Generates coverage report in HTML format
```bash
./fuzz.sh coverage <fuzz_target>
```
- `coverage-cleanup`:
```bash
./fuzz.sh clean-coverage <fuzz_target|all>
```
- `degub`: Run fuzzer with GDB and pass test_case as input
```bash
./fuzz.sh debug <fuzz_target> <test_case>
```
- `flamegraph`: Generates flamegraph report (might requires addition setups on the os)
```
./fuzz.sh flamegraph <fuzz_target> <test_case>
```
- `list`: List all existing fuzz targets.
```bash
./fuzz.sh list
Expand Down Expand Up @@ -97,6 +112,11 @@ When building in the OSS-Fuzz environment, `fuzz.sh` will place the corpus archi
- **Error Handling:** Implement robust error handling to intercept crashes or unwanted/unexpected behavior.
- **Performance Optimization:** Optimize for performance to enable more iterations and deeper fuzzing.

## fuzzer CLI
`cargo run fuzzer <command>`
Copy link
Contributor

Choose a reason for hiding this comment

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

will this replace fuzz.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can; I haven't decided about it yet. So far, it’s helpful for accessing data structures and functionalities of other suites in Rust. Thought, most of the utilities would basically call other binaries.

Copy link
Contributor

Choose a reason for hiding this comment

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

it may be confusing having two different utilities for the same purpose. can the functionality here be included in fuzz.sh ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can call It from the script, but it seems a bit layered, let me think about it.


A CLI that introduces helpful commands to build fuzzers, focusing on static code generation and corpus preparation.

## References
- [Rust Fuzz Book](https://rust-fuzz.github.io/book/)
- [Google OSS-Fuzz](https://google.github.io/oss-fuzz/)
Expand Down
1 change: 1 addition & 0 deletions testsuite/fuzzer/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/build
16 changes: 16 additions & 0 deletions testsuite/fuzzer/data/install-federated-jwks/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "install-federated-jwks"
version = "1.0.0"
authors = []

[addresses]
named_addr = "0xFED"

[dev-addresses]

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"

[dev-dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
script {
use aptos_framework::jwks;
use std::string::utf8;
fun main(account: &signer) {{
let iss = b"test.oidc.provider";
let kid = utf8(b"RSA");
let alg = utf8(b"RS256");
let e = utf8(b"AQAB");
let n = utf8(b"6S7asUuzq5Q_3U9rbs-PkDVIdjgmtgWreG5qWPsC9xXZKiMV1AiV9LXyqQsAYpCqEDM3XbfmZqGb48yLhb_XqZaKgSYaC_h2DjM7lgrIQAp9902Rr8fUmLN2ivr5tnLxUUOnMOc2SQtr9dgzTONYW5Zu3PwyvAWk5D6ueIUhLtYzpcB-etoNdL3Ir2746KIy_VUsDwAM7dhrqSK8U2xFCGlau4ikOTtvzDownAMHMrfE7q1B6WZQDAQlBmxRQsyKln5DIsKv6xauNsHRgBAKctUxZG8M4QJIx3S6Aughd3RZC4Ca5Ae9fd8L8mlNYBCrQhOZ7dS0f4at4arlLcajtw");
jwks::update_federated_jwk_set(
account,
iss,
vector[kid],
vector[alg],
vector[e],
vector[n]
);
}}
}
7 changes: 1 addition & 6 deletions testsuite/fuzzer/fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,9 @@ function flamegraph() {
error "$testcase does not exist"
fi
info "Generating flamegraph for $fuzz_target with $testcase"
# find the binary
binary=$(find ./target -name $fuzz_target -type f -perm /111)
if [ -z "$binary" ]; then
error "Could not find binary for $fuzz_target. Run `./fuzz.sh build $fuzz_target` first"
fi
# run the binary with cargo-flamegraph
time=$(date +%s)
cargo flamegraph -o "${fuzz_target}_${time}.svg" --bin "$binary" "$testcase -- -runs=1"
cargo flamegraph -o "${fuzz_target}_${time}.svg" --root -p="fuzzer-fuzz" --bin="$fuzz_target" -- "$testcase" "-- -runs=1"
}

function run() {
Expand Down
56 changes: 26 additions & 30 deletions testsuite/fuzzer/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aptos-language-e2e-tests = { workspace = true, features = ["fuzzing"] }
aptos-types = { workspace = true, features = ["fuzzing"] }
aptos-vm = { workspace = true }
arbitrary = { workspace = true, features = ["derive"] }
base64 = { workspace = true }
bcs = { workspace = true }
libfuzzer-sys = "0.4"
move-binary-format = { workspace = true, features = ["fuzzing"] }
Expand All @@ -23,12 +24,10 @@ move-core-types = { workspace = true, features = ["fuzzing"] }
move-vm-types = { workspace = true, features = ["fuzzing"] }
once_cell = { workspace = true }
rayon = { workspace = true }
ring = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }

[features]
disabled = []

[[bin]]
name = "move_bytecode_verifier_code_unit"
path = "fuzz_targets/move/bytecode_verifier_code_unit.rs"
Expand All @@ -41,6 +40,30 @@ path = "fuzz_targets/move/bytecode_verifier_mixed.rs"
test = false
doc = false

[[bin]]
name = "move_value_deserialize"
path = "fuzz_targets/move/value_deserialize.rs"
test = false
doc = false

[[bin]]
name = "move_move_value_deserialize"
path = "fuzz_targets/move/move_value_deserialize.rs"
test = false
doc = false

[[bin]]
name = "move_move_value_decorate"
path = "fuzz_targets/move/move_value_decorate.rs"
test = false
doc = false

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

[[bin]]
name = "move_aptosvm_publish_and_run"
path = "fuzz_targets/move/aptosvm_publish_and_run.rs"
Expand All @@ -58,30 +81,3 @@ name = "move_aptosvm_authenticators"
path = "fuzz_targets/move/aptosvm_authenticators.rs"
test = false
doc = false

#[[bin]]#name = "move_value_deserialize"
#path = "fuzz_targets/move/value_deserialize.rs"
#test = false
#doc = false
#required-features = ["disabled"]

#[[bin]]
#name = "move_move_value_deserialize"
#path = "fuzz_targets/move/move_value_deserialize.rs"
#test = false
#doc = false
#required-features = ["disabled"]

#[[bin]]
#name = "move_move_value_decorate"
#path = "fuzz_targets/move/move_value_decorate.rs"
#test = false
#doc = false
#required-features = ["disabled"]

#[[bin]]
#name = "signed_transaction_deserialize"
#path = "fuzz_targets/signed_transaction_deserialize.rs"
#test = false
#doc = false
#required-features = ["disabled"]
Loading
Loading