test: add asset lock/unlock validation fuzz targets#7168
test: add asset lock/unlock validation fuzz targets#7168thepastaclaw wants to merge 6 commits intodashpay:developfrom
Conversation
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThis pull request adds a new fuzz test source (src/test/fuzz/asset_lock_unlock.cpp) and registers it in the test Makefile. The new file provides helper generators and three fuzz targets—asset_lock_tx, asset_lock_tx_raw, and asset_unlock_fee—that construct, mutate, deserialize, and validate asset lock/unlock transactions and compute related fees using existing validation utilities (e.g., CheckAssetLockTx, GetAssetUnlockFee) under regtest parameters. Sequence Diagram(s)sequenceDiagram
participant Fuzzer
participant Builder as Tx Builder
participant Deserializer as Tx Deserializer
participant Validator as CheckAssetLockTx / GetAssetUnlockFee
participant State as TxValidationState
Fuzzer->>Builder: generate scripts, amounts, payloads, signatures, u256 values
Builder->>Builder: construct asset-lock or asset-unlock transaction (various mutation cases)
alt raw deserialization path
Fuzzer->>Deserializer: provide fuzzed byte stream
Deserializer->>Validator: parsed transaction
else constructed transaction path
Builder->>Validator: constructed transaction
end
Validator->>State: validate transaction / compute unlock fee
State-->>Validator: validation result / fee value
Validator-->>Fuzzer: return result (asserts or exits on invalid states)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/test/fuzz/asset_lock_unlock.cpp (1)
60-70:ConsumeUInt256: consider usingstd::copyfor clarity.The manual iterator loop works correctly but could be simplified.
♻️ Optional simplification
uint256 ConsumeUInt256(FuzzedDataProvider& fuzzed_data_provider) { uint256 value; - auto it = value.begin(); const std::vector<uint8_t> bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(32); - for (uint8_t b : bytes) { - *it = b; - ++it; - } + std::copy(bytes.begin(), bytes.end(), value.begin()); return value; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/fuzz/asset_lock_unlock.cpp` around lines 60 - 70, The manual loop in ConsumeUInt256 can be simplified by copying the consumed bytes into the uint256 buffer; replace the for-loop that assigns via iterator with a single std::copy from bytes.begin()/bytes.end() to value.begin() (or use std::memcpy) to make the intent clearer and reduce boilerplate—update the function ConsumeUInt256 (types: uint256, FuzzedDataProvider, and std::vector<uint8_t> bytes) accordingly and ensure <algorithm> is included if using std::copy.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Makefile.test.include`:
- Around line 280-282: The file list in src/Makefile.test.include is out of
alphabetical order: test/fuzz/asset_lock_unlock.cpp is placed between
test/fuzz/asmap.cpp and test/fuzz/asmap_direct.cpp; move the entry for
asset_lock_unlock.cpp so that the sequence is alphabetically sorted (i.e., place
test/fuzz/asset_lock_unlock.cpp after test/fuzz/asmap_direct.cpp) ensuring the
fuzz source list maintains correct lexicographic order.
---
Nitpick comments:
In `@src/test/fuzz/asset_lock_unlock.cpp`:
- Around line 60-70: The manual loop in ConsumeUInt256 can be simplified by
copying the consumed bytes into the uint256 buffer; replace the for-loop that
assigns via iterator with a single std::copy from bytes.begin()/bytes.end() to
value.begin() (or use std::memcpy) to make the intent clearer and reduce
boilerplate—update the function ConsumeUInt256 (types: uint256,
FuzzedDataProvider, and std::vector<uint8_t> bytes) accordingly and ensure
<algorithm> is included if using std::copy.
Move asset_lock_unlock.cpp after asmap_direct.cpp to maintain alphabetical ordering in the fuzz source list.
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/Makefile.test.include`:
- Around line 280-283: The alphabetical ordering issue has been resolved: ensure
the entries in test_fuzz_fuzz_SOURCES keep lexicographic order by verifying
asmap_direct.cpp appears before asset_lock_unlock.cpp (and maintain the overall
ordering of test/fuzz/asmap.cpp, test/fuzz/asmap_direct.cpp,
test/fuzz/asset_lock_unlock.cpp, test/fuzz/autofile.cpp); no code changes
required other than preserving this ordering in future edits.
Required for clang-format CI enforcement on Dash-specific files.
test/util/data/non-backported.txt
Outdated
| src/stats/*.h | ||
| src/test/block_reward_reallocation_tests.cpp | ||
| src/test/bls_tests.cpp | ||
| src/test/fuzz/asset_lock_unlock.cppsrc/test/bls_tests.cpp |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/util/data/non-backported.txt (1)
52-54:src/test/fuzz/asset_lock_unlock.cppentry is out of alphabetical order.The entry on Line 53 is inserted between
src/test/block_reward_reallocation_tests.cppandsrc/test/bls_tests.cpp, butfuzz/sorts after allb-prefixed filenames. It should sit after Line 54 (src/test/bls_tests.cpp).♻️ Proposed reorder
src/test/block_reward_reallocation_tests.cpp -src/test/fuzz/asset_lock_unlock.cpp src/test/bls_tests.cpp src/test/coinjoin_*.cpp src/test/dip0020opcodes_tests.cpp src/test/dynamic_activation*.cpp src/test/evo*.cpp +src/test/fuzz/asset_lock_unlock.cpp src/test/llmq*.cppBased on learnings,
test/util/data/non-backported.txtis used to run clang-format on C/C++ files; the.cppextension is correct and the entry is required for this new Dash-specific file. Only the placement is off.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/util/data/non-backported.txt` around lines 52 - 54, The entry "src/test/fuzz/asset_lock_unlock.cpp" in test/util/data/non-backported.txt is out of alphabetical order; move that line so it appears after "src/test/bls_tests.cpp" (i.e., place the fuzz/ entry after the b-prefixed entries) to restore correct alphabetical ordering within the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/util/data/non-backported.txt`:
- Around line 52-54: The entry "src/test/fuzz/asset_lock_unlock.cpp" in
test/util/data/non-backported.txt is out of alphabetical order; move that line
so it appears after "src/test/bls_tests.cpp" (i.e., place the fuzz/ entry after
the b-prefixed entries) to restore correct alphabetical ordering within the
file.
f7b7f93 to
3c4073c
Compare
|
Re: missing newlines — fixed in 0fcd955, pushed right around when you commented. |
Summary
Add fuzz targets for asset lock/unlock validation — the L1↔L2 credit pool bridge (DIP-27). This covers
CheckAssetLockTx()andGetAssetUnlockFee(), both consensus-critical functions that process untrusted transaction data.Part of the Dash Core Fuzzing Initiative (Phase 3 — functional targets). Tracker: thepastaclaw/tracker#108.
Fuzz Targets
asset_lock_tx— Structured CheckAssetLockTx fuzzingUses
FuzzedDataProviderto construct well-formed asset lock transactions, then systematically mutates them through 12 scenarios covering every validation branch:asset_lock_tx_raw— Raw deserialization CheckAssetLockTx fuzzingDeserializes a
CTransactionfrom raw fuzz bytes and passes it directly toCheckAssetLockTx(). Catches edge cases that structured fuzzing misses (e.g., unusual serialization states, version combinations).asset_unlock_fee— Structured GetAssetUnlockFee fuzzingConstructs
CAssetUnlockPayloadwith fuzzed fields (version, index, fee, requestedHeight, quorumHash, quorumSig), then optionally corrupts the payload or zeroes the fee to exercise all validation paths.Invariant Checks
All targets assert
result == state.IsValid()— verifying that the validation functions maintain consistency between their return value and the validation state object.Validation
--enable-fuzz(clang++, no warnings)PRINT_ALL_FUZZ_TARGETS_AND_ABORToutput--enable-fuzz --disable-wallet --with-gui=no