fix(checkpoint): avoid withdrawal count truncation - #179
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Commit: 92e516d
|
prajwolrg
left a comment
There was a problem hiding this comment.
I think this is incomplete. We still treat VerifiedWithdrawals.remaining_count as u32. I'm not sure what benefit we are getting with the changes here.
| let intents = vec![withdrawal(u32::MAX as u64 + 1)]; | ||
| let err = pool.verify_withdrawals(&intents).unwrap_err(); |
There was a problem hiding this comment.
I don't think this test is doing anything helpful.
The error basically is saying we are trying to withdraw more than in the pool and I don't think this has anything to do with the use of u32. There will be the same error even if we are using withdrawal of 2 sat because we only have 1 sat in the pool.
I suggest having two commits, one where the test is failing because of this issue and the next commit where we fix this.
Motivation
DepositPoolpreviously cast each withdrawal multiple fromu64tou32while accumulatingrequired, causing truncation for very large withdrawals and allowing oversized withdrawals to pass verification. This could lead to the bridge attempting more assignments than available UTXOs and panicking.Description
u64accumulator for the required UTXO count incrates/subprotocols/checkpoint/verification/src/deposit_pool.rsso(amt / denom)is never truncated during accumulation.u64requiredagainstself.count as u64and only cast back tou32after the bounds check when producingVerifiedWithdrawals.remaining_count.large_multi_denomination_intent_does_not_truncate_required_countthat verifies a 1-sat denomination withdrawal ofu32::MAX + 1sats is rejected as insufficient funds instead of being truncated.Testing
cargo test -p strata-checkpoint-verification deposit_pool, and all tests passed (15 passed; 0 failed).cargo fmt --check --package strata-checkpoint-verification, which succeeded.git diff --checkto ensure no whitespace or diff issues, which reported no problems.Codex Task