Skip to content

Clean up per-validator vote data on swap completion#28

Open
paulee wants to merge 1 commit intoentrius:testfrom
paulee:fix/vote-data-cleanup
Open

Clean up per-validator vote data on swap completion#28
paulee wants to merge 1 commit intoentrius:testfrom
paulee:fix/vote-data-cleanup

Conversation

@paulee
Copy link
Copy Markdown

@paulee paulee commented Apr 9, 2026

Problem

During a security audit of the ink! smart contract, I found that per-validator vote entries are never cleaned up, creating dead storage that grows indefinitely.

What happens:

  1. When validators vote on swaps, entries are written to swap_confirm_votes[(swap_id, validator)] and swap_timeout_votes[(swap_id, validator)]
  2. When a swap completes or times out, only the aggregate swap_confirm_vote_count and swap_timeout_vote_count are removed (lines 758-759, 840-841)
  3. The individual per-validator boolean entries are never deleted — they accumulate forever
  4. Same issue in the request voting system: request_votes[(request_id, validator)] entries are never removed by clear_request_data

Over time this creates unbounded dead storage growth proportional to num_swaps × num_validators.

Fix

Track voters per swap/request using Vec<AccountId> mappings, then iterate and remove all per-validator entries on completion:

  • Added swap_confirm_voters, swap_timeout_voters, request_voters storage fields (Mapping<u64, Vec<AccountId>>)
  • Vote recording now appends caller to the voters list
  • New clean_swap_votes helper removes all per-validator entries for both confirm and timeout votes
  • Updated clear_request_data to remove per-validator request_votes entries
  • Both vote_confirm and timeout_swap now call clean_swap_votes at quorum instead of only removing vote counts

Test plan

  • cargo testtest_timeout_cleans_up_vote_data confirms per-validator entries are removed after timeout
  • Verify on testnet that vote data is properly cleaned after swap completion

@paulee paulee force-pushed the fix/vote-data-cleanup branch from 4c7c209 to f29aea3 Compare April 9, 2026 20:35
@paulee paulee force-pushed the fix/vote-data-cleanup branch from f29aea3 to 092304f Compare April 9, 2026 20:41
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.

1 participant