Clean up per-validator vote data on swap completion#28
Open
paulee wants to merge 1 commit intoentrius:testfrom
Open
Clean up per-validator vote data on swap completion#28paulee wants to merge 1 commit intoentrius:testfrom
paulee wants to merge 1 commit intoentrius:testfrom
Conversation
4c7c209 to
f29aea3
Compare
f29aea3 to
092304f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
swap_confirm_votes[(swap_id, validator)]andswap_timeout_votes[(swap_id, validator)]swap_confirm_vote_countandswap_timeout_vote_countare removed (lines 758-759, 840-841)request_votes[(request_id, validator)]entries are never removed byclear_request_dataOver 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:swap_confirm_voters,swap_timeout_voters,request_votersstorage fields (Mapping<u64, Vec<AccountId>>)clean_swap_voteshelper removes all per-validator entries for both confirm and timeout votesclear_request_datato remove per-validatorrequest_votesentriesvote_confirmandtimeout_swapnow callclean_swap_votesat quorum instead of only removing vote countsTest plan
cargo test—test_timeout_cleans_up_vote_dataconfirms per-validator entries are removed after timeout