fix: canonicalize bridge deposit keys and add global completion dedup#1249
Open
ouicate wants to merge 5 commits into
Open
fix: canonicalize bridge deposit keys and add global completion dedup#1249ouicate wants to merge 5 commits into
ouicate wants to merge 5 commits into
Conversation
…etion dedup Normalize MsgBridgeExchange fields before vote-aggregation hashing and record canonical L1 receipt identity before mint or escrow release so split keys cannot double-mint the same deposit.
Normalize receipt identity fields inside the global completion key so legacy split bridge records with leading-zero numeric variants cannot bypass completion dedup.
Author
|
Please take a look @GLiberman |
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.
Summary
This fixes a bridge accounting bug where the same Ethereum deposit could produce multiple independent
BridgeTransactionrecords, and multiple mints or escrow releases, when validators submitted identical L1 events with different string representations (for exampleReceiptsRoothex casing, or leading zeros inBlockNumber/ReceiptIndex/Amount). Vote aggregation keyed off raw strings, while mint/release only guarded completion per record, not per logical deposit.Root Cause
generateSecureBridgeTransactionKeyhashed raw field strings.ContractAddresswas not normalized on ingress in all paths.ReceiptsRoot, numeric fields, andOwnerAddresswere not canonicalized before hashing or storage.ValidateBasicaccepted leading-zero decimal strings (^[0-9]+$). Separately,handleCompletedBridgeTransactiononly checkedBRIDGE_PENDINGon the current record; there was no chain-wide registry keyed by L1 receipt identity, so two storage keys for one deposit could each reach quorum and mint independently.Fix
buildCanonicalBridgeTransactionto normalize all vote-aggregation fields at ingress:ContractAddressandReceiptsRoot-> lowercaseBlockNumber,ReceiptIndex,Amount-> canonical decimal viabig.Int(no leading zeros)OwnerAddress-> canonical bech32 viaAccAddressFromBech32OriginChain-> lowercaseMsgBridgeExchange.ValidateBasic: require valid bech32OwnerAddress, reject leading zeros on numeric fields, validateReceiptsRootas0x+ 32-byte hex.BridgeCompletedDepositEventsKeySet keyed bycanonicalBridgeDepositEventID(chainId|blockNumber|receiptIndex|contract|owner|amount, excludingReceiptsRootstring variants).handleCompletedBridgeTransaction, skip mint/release if the canonical deposit was already completed; mark completed only after successful mint or escrow release.Why This Closes The Vulnerability
The exploit required two conditions: validators could create distinct vote-aggregation keys for the same L1 deposit, and completion/mint was tracked only per key. This PR removes both: equivalent deposit reports collapse to one canonical
BridgeTransactionidentity, and even if a legacy or Byzantine split key reached quorum, the global completion registry ensures at most one mint or escrow release per canonical L1 receipt.Test plan
go test ./x/inference/types/... -run 'Bridge|BridgeExchange|Canonical'go test ./x/inference/keeper/... -run 'Bridge|Canonical'MsgBridgeExchangepayloads differing only inReceiptsRootcasing or leading zeros map to the same aggregation key after fixhandleCompletedBridgeTransactionSupersedes #1196 (closed because the head fork was accidentally deleted; this branch is a clean rebase onto current
main).