Skip to content

chore: fuzz test expansion#40

Merged
romanzac merged 83 commits into
mainfrom
chore-add-fuzz-tests
Nov 7, 2025
Merged

chore: fuzz test expansion#40
romanzac merged 83 commits into
mainfrom
chore-add-fuzz-tests

Conversation

@romanzac
Copy link
Copy Markdown
Contributor

@romanzac romanzac commented Sep 26, 2025

Description

Add smart contract with invariants to run Echidna simulation. It is a complement to existing unit tests to simulate contract behavior with large values.

Tests added

EchidnaTest contract with invariants:

  • echidna_rate_commitments_range_correct
  • echidna_merkle_proof_valid
  • echidna_total_rate_limit_correct
  • echidna_max_total_rate_limit_valid
  • echidna_merkle_inserts_integrity
  • echidna_merkle_erasures_integrity

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Added natspec comments?
  • Ran pnpm adorno?

@romanzac romanzac marked this pull request as ready for review October 3, 2025 01:12
@romanzac romanzac requested review from 0x-r4bbit and stubbsta October 3, 2025 01:13
Copy link
Copy Markdown
Contributor

@stubbsta stubbsta left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment thread test/WakuRlnV2.fuzz.t.sol Outdated
uint256(w.activeDurationForNewMemberships()) + uint256(w.gracePeriodDurationForNewMemberships()) + 1;
vm.warp(block.timestamp + minDelta);

uint256[] memory idCommitments = _buildIdsFromMask(subsetMask);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't we want to ensure that the length of idCommitments is at least 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Length of idCommitments cannot be 0. This is guaranteed by subsetMask > 0 invm.assume(subsetMask > 0 && subsetMask < 16). I can add assert(idCommitments.length >= 1) if you want ? Here is the complete output set:

subsetMask (dec) | subsetMask (bin) | idCommitments
1 | 0001 | [1]
2 | 0010 | [2]
3 | 0011 | [1,2]
4 | 0100 | [3]
5 | 0101 | [1,3]
6 | 0110 | [2,3]
7 | 0111 | [1,2,3]
8 | 1000 | [4]
9 | 1001 | [1,4]
10 | 1010 | [2,4]
11 | 1011 | [1,2,4]
12 | 1100 | [3,4]
13 | 1101 | [1,3,4]
14 | 1110 | [2,3,4]
15 | 1111 | [1,2,3,4]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

oh yeah you are right, I missed the subsetMask < 16

@romanzac romanzac merged commit f5fff5c into main Nov 7, 2025
4 checks passed
@romanzac romanzac deleted the chore-add-fuzz-tests branch November 7, 2025 01:20
romanzac added a commit that referenced this pull request Nov 14, 2025
* test: malicious upgrade drains funds

* fix: formatting

* test: show success when unauthorized upgrade after malicious

* test: offchain proof post lazy erase
- multi-user erase reuse race

* fix: line length

* fix: remove offchain lazy erase test - rate limit still applies

* test: timestamp manipulation

* fix: rename tests

* test: front running for registration

* fix: unused variables

* test: register during spam conditions

* fix: delete failing tests
- test_MaliciousUpgradeDrainsFunds
- testFrontrunning_RegistrationRevertsForVictim
- testFrontrunning_SetFillingSpam

* fix: delete MaliciousImplementation

* fix: formatting with a new Foundry version

* test: testEraseAndReuse with Echidna

* fix: remove limit check

* fix: remove test_MultiUserEraseReuseRace
- test_TimestampManipulationRaces

* fix: skip Echidna contract during forge test

* test: Echidna contract with invariants
- registerMembership
- attemptExtensionRace
- attemptErasureRace

* fix: tune config file

* fix: run and cleanup scripts for echidna

* test: Echidna test replay

* fix: Solidity version

* fix: test_attemptExtensionRace_WakuRLN

* fix: invalid commitment in test_attemptExtensionRace_WakuRLN

* fix: invalid commitments in
test_attemptErasureRace_WakuRLN

* fix: line length

* fix: skip all Echidna tests in CI

* chore: fuzz test expansion (#40)

* test: register invalid

* test: multiple registers

* fix: increase max rejects

* test: erasure with fullErase idCommitments

* fix: reduce cyclomatic complexity

* fix: reduce complexity one step less

* fix: run tests in parallel

* fix: undo run tests in parallel - default already

* test: invalid extension with extreme values

* fix: line length

* test: set MaxTotalRateLimit

* test: set ActiveDuration

* test: Merkle inserts

* test: Merkle erasures

* test: GetRateCommitmentsRange

* test: GetMerkleProof

* fix: optimized MerkleInsert MerkleErasures

* fix: update gas snapshot

* test: malicious upgrade drains funds

* fix: formatting

* test: show success when unauthorized upgrade after malicious

* test: offchain proof post lazy erase
- multi-user erase reuse race

* fix: line length

* fix: remove offchain lazy erase test - rate limit still applies

* fix: remove fuzz tests from CI run

* fix: formatting

* fix: formatting coverage

* test: timestamp manipulation

* fix: rename tests

* test: front running for registration

* fix: unused variables

* test: register during spam conditions

* fix: delete failing tests
- test_MaliciousUpgradeDrainsFunds
- testFrontrunning_RegistrationRevertsForVictim
- testFrontrunning_SetFillingSpam

* fix: delete MaliciousImplementation

* fix: formatting with a new Foundry version

* test: testEraseAndReuse with Echidna

* fix: remove limit check

* fix: remove test_MultiUserEraseReuseRace
- test_TimestampManipulationRaces

* fix: skip Echidna contract during forge test

* test: Echidna contract with invariants
- registerMembership
- attemptExtensionRace
- attemptErasureRace

* fix: tune config file

* fix: run and cleanup scripts for echidna

* test: Echidna test replay

* fix: Solidity version

* fix: test_attemptExtensionRace_WakuRLN

* fix: invalid commitment in test_attemptExtensionRace_WakuRLN

* fix: invalid commitments in
test_attemptErasureRace_WakuRLN

* fix: line length

* fix: skip all Echidna tests in CI

* test: register invalid

* test: multiple registers

* fix: increase max rejects

* test: erasure with fullErase idCommitments

* fix: reduce cyclomatic complexity

* fix: reduce complexity one step less

* test: invalid extension with extreme values

* fix: line length

* test: set MaxTotalRateLimit

* test: set ActiveDuration

* test: Merkle inserts

* test: Merkle erasures

* test: GetRateCommitmentsRange

* test: GetMerkleProof

* fix: optimized MerkleInsert MerkleErasures

* fix: update gas snapshot

* fix: formatting

* fix: remove tests with high overlap

* fix: remove all tests originally meant for fuzzing

* fix: rename merged Echidna tests

* fix: formatting

* test: fuzzing for essential invariants

* test: EchidnaTest contract

* fix: remove unnecessary imports

* fix: remove unnecessary helpers

* fix: remove bounds from invariants

* fix: change test mode to property

* fix: update run script

* fix: max_test_rejects back to the original value

* fix: remove unused local variables

* test: malicious upgrade drains funds

* fix: formatting

* test: show success when unauthorized upgrade after malicious

* test: offchain proof post lazy erase
- multi-user erase reuse race

* fix: line length

* fix: remove offchain lazy erase test - rate limit still applies

* test: timestamp manipulation

* fix: rename tests

* test: front running for registration

* fix: unused variables

* test: register during spam conditions

* fix: delete failing tests
- test_MaliciousUpgradeDrainsFunds
- testFrontrunning_RegistrationRevertsForVictim
- testFrontrunning_SetFillingSpam

* fix: delete MaliciousImplementation

* fix: remove test_MultiUserEraseReuseRace
- test_TimestampManipulationRaces

* test: Echidna test replay

* fix: Solidity version

* fix: test_attemptExtensionRace_WakuRLN

* fix: invalid commitment in test_attemptExtensionRace_WakuRLN

* fix: invalid commitments in
test_attemptErasureRace_WakuRLN

* fix: line length

* fix: cleanup after rebase

* fix: remove redundant file

* fix: formatting

* fix: formatting

* fix: adorno + archive EchidnaReplayRaces.t.sol

* test: focus on erasures with timestamps

* fix: remove isolated test

* test: Echidna tests for races
- add dynamic assertions before operation
- untrack erased IDs

* fix: remove unused replay test
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.

4 participants