Skip to content

Commit

Permalink
feat: Multi Asset Delegation pallet fuzzing (#856)
Browse files Browse the repository at this point in the history
* feat: Multi Asset Delegation pallet fuzzing

* feat: add more functions to the fuzzing

* doc: add how to run the fuzzer

* feat: add sanity checks

* lints: fix clippy

* fix: reversed balance should be returned on unstake
  • Loading branch information
shekohex authored Dec 24, 2024
1 parent 30acfac commit b1b0084
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ resources/para-2076-wasm
scripts/edg-balances-new.json
*.venv

._*
._*
hfuzz_*/

33 changes: 33 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"pallets/services/rpc",
"pallets/services/rpc/runtime-api",
"pallets/tangle-lst/benchmarking",
"pallets/multi-asset-delegation/fuzzer",
"precompiles/pallet-democracy",
"precompiles/batch",
"precompiles/call-permit",
Expand Down Expand Up @@ -94,6 +95,7 @@ snowbridge-milagro-bls = { git = "https://github.com/Snowfork/milagro_bls", defa
primitive-types = { version = "0.12.2", default-features = false, features = ["scale-info", "serde_no_std"] }
fixed = { version = "1.28.0", default-features = false }
educe = { version = "0.6.0", default-features = false }
honggfuzz = { version = "0.5.55" }

tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
tangle-runtime = { package = "tangle-runtime", path = "runtime/mainnet" }
Expand Down Expand Up @@ -329,9 +331,7 @@ signature = { version = "2.2", default-features = false }
# EVM & Ethereum
# (wasm)
ethereum-types = { version = "0.14.1", default-features = false }
ethereum = { version = "0.15.0", default-features = false, features = [
"with-codec",
] }
ethereum = { version = "0.15.0", default-features = false, features = ["with-codec"] }
evm = { version = "0.41.1", default-features = false }
evm-gasometer = { version = "0.41.0", default-features = false }
evm-runtime = { version = "0.41.0", default-features = false }
Expand Down
21 changes: 19 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
pkgs.openssl
# Needed for rocksdb-sys
pkgs.clang
pkgs.gcc
pkgs.libbfd
pkgs.libunwind
pkgs.libblocksruntime
pkgs.libclang.lib
pkgs.libgcc
pkgs.rustPlatform.bindgenHook
# Mold Linker for faster builds (only on Linux)
(lib.optionals pkgs.stdenv.isLinux pkgs.mold)
Expand All @@ -44,6 +49,8 @@
(lib.optionals pkgs.stdenv.isDarwin
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration)
];
# Fortify causes build failures: 'str*' defined both normally and as 'alias' attribute
hardeningDisable = [ "fortify" ];
buildInputs = [
# Nodejs for test suite
pkgs.nodePackages.typescript-language-server
Expand All @@ -53,16 +60,26 @@
toolchain
pkgs.foundry-bin
];
packages =
[ pkgs.taplo pkgs.harper pkgs.cargo-nextest pkgs.cargo-tarpaulin ];
packages = [
pkgs.taplo
pkgs.harper
pkgs.cargo-nextest
pkgs.cargo-tarpaulin
pkgs.lldb
];
# Environment variables
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
# Needed for running DKG Node.
LD_LIBRARY_PATH = lib.makeLibraryPath [
pkgs.gmp
pkgs.openssl
pkgs.libclang
pkgs.libgcc
pkgs.stdenv.cc.cc
pkgs.libbfd
pkgs.libunwind
pkgs.libblocksruntime
pkgs.libopcodes
];
};
});
Expand Down
161 changes: 113 additions & 48 deletions pallets/multi-asset-delegation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@ itertools = { workspace = true, features = ["use_alloc"] }
serde = { workspace = true, features = ["derive"], optional = true }
hex = { workspace = true, features = ["alloc"] }

# Optional dependencies for fuzzing
ethereum = { workspace = true, features = ["with-codec"], optional = true }
ethers = { version = "2.0", optional = true }
num_enum = { workspace = true, optional = true }
hex-literal = { workspace = true, optional = true }
libsecp256k1 = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
smallvec = { workspace = true, optional = true }
sp-keystore = { workspace = true, optional = true }
fp-account = { workspace = true, optional = true }
fp-consensus = { workspace = true, optional = true }
fp-dynamic-fee = { workspace = true, optional = true }
fp-ethereum = { workspace = true, optional = true }
fp-rpc = { workspace = true, optional = true }
fp-self-contained = { workspace = true, optional = true }
fp-storage = { workspace = true, optional = true }
pallet-base-fee = { workspace = true, optional = true }
pallet-dynamic-fee = { workspace = true, optional = true }
pallet-ethereum = { workspace = true, optional = true }
pallet-evm = { workspace = true, optional = true }
pallet-evm-chain-id = { workspace = true, optional = true }
pallet-evm-precompile-blake2 = { workspace = true, optional = true }
pallet-evm-precompile-bn128 = { workspace = true, optional = true }
pallet-evm-precompile-curve25519 = { workspace = true, optional = true }
pallet-evm-precompile-ed25519 = { workspace = true, optional = true }
pallet-evm-precompile-modexp = { workspace = true, optional = true }
pallet-evm-precompile-sha3fips = { workspace = true, optional = true }
pallet-evm-precompile-simple = { workspace = true, optional = true }
precompile-utils = { workspace = true, optional = true }
sp-keyring = { workspace = true, optional = true }
pallet-timestamp = { workspace = true, optional = true }
pallet-session = { workspace = true, optional = true }
pallet-staking = { workspace = true, optional = true }
sp-staking = { workspace = true, optional = true }
frame-election-provider-support = { workspace = true, optional = true }

[dev-dependencies]
ethereum = { workspace = true, features = ["with-codec"] }
ethers = "2.0"
Expand All @@ -41,33 +77,27 @@ serde_json = { workspace = true }
smallvec = { workspace = true }
sp-io = { workspace = true }
sp-keystore = { workspace = true }

# Frontier Primitive
fp-account = { workspace = true }
fp-consensus = { workspace = true }
fp-dynamic-fee = { workspace = true }
fp-ethereum = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
fp-storage = { workspace = true }

# Frontier FRAME
pallet-base-fee = { workspace = true }
pallet-dynamic-fee = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-chain-id = { workspace = true }

pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-curve25519 = { workspace = true }
pallet-evm-precompile-ed25519 = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }

precompile-utils = { workspace = true }
sp-keyring ={ workspace = true}
sp-keyring = { workspace = true }
pallet-session = { workspace = true }
pallet-staking = { workspace = true }
sp-staking = { workspace = true }
Expand All @@ -76,48 +106,83 @@ frame-election-provider-support = { workspace = true }
[features]
default = ["std"]
std = [
"scale-info/std",
"sp-runtime/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-std/std",
"pallet-balances/std",
"pallet-assets/std",
"tangle-primitives/std",
"ethabi/std",
"log/std",
"fp-evm/std",
"serde/std",
"hex/std",

"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-simple/std",
"pallet-evm-precompile-blake2/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-curve25519/std",
"pallet-evm-precompile-ed25519/std",
"precompile-utils/std",
"pallet-staking/std",
"fp-account/std",
"fp-consensus/std",
"fp-dynamic-fee/std",
"fp-ethereum/std",
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"fp-storage/std",
"ethabi/std",
"sp-keyring/std",
"pallet-ethereum/std"
"scale-info/std",
"sp-runtime/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-std/std",
"pallet-balances/std",
"pallet-assets/std",
"tangle-primitives/std",
"ethabi/std",
"log/std",
"fp-evm/std",
"serde/std",
"hex/std",
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-simple/std",
"pallet-evm-precompile-blake2/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-curve25519/std",
"pallet-evm-precompile-ed25519/std",
"precompile-utils/std",
"pallet-staking/std",
"fp-account/std",
"fp-consensus/std",
"fp-dynamic-fee/std",
"fp-ethereum/std",
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"fp-storage/std",
"ethabi/std",
"sp-keyring/std",
"pallet-ethereum/std",
]
try-runtime = ["frame-support/try-runtime"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
]
fuzzing = [
"ethereum",
"ethers",
"num_enum",
"hex-literal",
"libsecp256k1",
"serde_json",
"smallvec",
"sp-keystore",
"fp-account",
"fp-consensus",
"fp-dynamic-fee",
"fp-ethereum",
"fp-rpc",
"fp-self-contained",
"fp-storage",
"pallet-base-fee",
"pallet-dynamic-fee",
"pallet-ethereum",
"pallet-evm",
"pallet-evm-chain-id",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-curve25519",
"pallet-evm-precompile-ed25519",
"pallet-evm-precompile-modexp",
"pallet-evm-precompile-sha3fips",
"pallet-evm-precompile-simple",
"precompile-utils",
"sp-keyring",
"pallet-timestamp",
"pallet-session",
"pallet-staking",
"sp-staking",
"frame-election-provider-support",
]
33 changes: 33 additions & 0 deletions pallets/multi-asset-delegation/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "pallet-multi-asset-delegation-fuzzer"
version = "2.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "Fuzzer for fixed point arithmetic primitives."
documentation = "https://docs.rs/sp-arithmetic-fuzzer"
publish = false

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
honggfuzz = { workspace = true }

pallet-multi-asset-delegation = { features = ["fuzzing"], workspace = true, default-features = true }

frame-system = { workspace = true, default-features = true }
frame-support = { workspace = true, default-features = true }

sp-runtime = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }

rand = { features = ["small_rng"], workspace = true, default-features = true }
log = { workspace = true, default-features = true }

[[bin]]
name = "mad-fuzzer"
path = "call.rs"
Loading

0 comments on commit b1b0084

Please sign in to comment.