这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@junxzm1990
Copy link
Contributor

@junxzm1990 junxzm1990 commented Nov 11, 2025

Description

When introducing signed integers, we switched from primitive-types to ethnum as the underneath crate to support our u256 type. This PR adds a harness to differentially fuzz the two crates on their operations that we reuse for u256.

Running the harness can effectively cover the operations we care about. No disparity issues were found.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (aptos fuzz)

Note

Adds a fuzz target to differentially test ethnum::U256 against primitive_types::U256, with a comprehensive dictionary and dependency updates.

  • Fuzzing:
    • Add new target u256_diff_fuzz in testsuite/fuzzer/fuzz/fuzz_targets/u256_diff_fuzz.rs to differentially test ethnum::U256 vs primitive_types::U256 across arithmetic, bitwise, shifts, and conversions.
    • Introduce large fuzz dictionary testsuite/fuzzer/fuzz/dictionaries/u256.dict covering boundary cases for multiple bit-widths.
  • Dependencies:
    • Add workspace dependency ethnum and include primitive-types in the fuzz crate.
    • Bump primitive-types in root Cargo.toml from 0.10 to 0.12.2.

Written by Cursor Bugbot for commit 5216de7. This will update automatically on new commits. Configure here.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@junxzm1990 junxzm1990 force-pushed the jun/add-fuzzer branch 2 times, most recently from d3d4294 to c022e9b Compare November 11, 2025 17:31
@junxzm1990 junxzm1990 marked this pull request as ready for review November 12, 2025 16:11

fuzz_target!(|data: &[u8]| {
if data.len() < 64 {
return;
Copy link
Contributor

@zi0Black zi0Black Nov 12, 2025

Choose a reason for hiding this comment

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

To ensure it's correctly discarded by libFuzzer, return:

Corpus::Reject

Comment on lines +254 to +287
bytes.copy_from_slice(&data[0..32]);
let pri_u256_1 = PrimitiveU256::get_from_le_bytes(&bytes);
let eth_u256_1 = EthnumU256::get_from_le_bytes(&bytes);

bytes.copy_from_slice(&data[32..64]);
let pri_u256_2 = PrimitiveU256::get_from_le_bytes(&bytes);
let eth_u256_2 = EthnumU256::get_from_le_bytes(&bytes);

// Check conversion consistency
assert_eq!(pri_u256_1.turn_to_le_bytes(), eth_u256_1.turn_to_le_bytes());
assert_eq!(pri_u256_2.turn_to_le_bytes(), eth_u256_2.turn_to_le_bytes());

// Check arithmetic operations
let add1 = PrimitiveU256::checked_add(pri_u256_1, pri_u256_2);
let add2 = EthnumU256::checked_add(eth_u256_1, eth_u256_2);
assert_eq!(
add1.map(|x| x.turn_to_le_bytes()),
add2.map(|x| x.turn_to_le_bytes())
);

let sub1 = PrimitiveU256::checked_sub(pri_u256_1, pri_u256_2);
let sub2 = EthnumU256::checked_sub(eth_u256_1, eth_u256_2);
assert_eq!(
sub1.map(|x| x.turn_to_le_bytes()),
sub2.map(|x| x.turn_to_le_bytes())
);

let mul1 = PrimitiveU256::checked_mul(pri_u256_1, pri_u256_2);
let mul2 = EthnumU256::checked_mul(eth_u256_1, eth_u256_2);
assert_eq!(
mul1.map(|x| x.turn_to_le_bytes()),
mul2.map(|x| x.turn_to_le_bytes())
);

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally, it's suggested to split test cases/fuzzers as those are explored better stand-alone. But I guess the fuzzer is quite fast, and we can ignore it.

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.

3 participants