This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
[zk-token-sdk] Fix transfer with fee edge case error #34314
Merged
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
In the way the transfer with fee proof is currently calculated, it is possible for transfer fee to be greater than the transfer amount. This stems from some edge cases that were missed in the way range proof is used.
transfer_fee * 10_000 - transfer_amount * fee_basis_point
thedelta_fee
. If the fee is calculated correctly, then thedelta_fee
must be in the range0 <= delta_fee < 10_000
. We use range proof to check this. However, since range proof only works for ranges of power-of-two, we require the prover to generate two range proofs: (i)0 <= delta_fee < 16_384
(16384 = 2^14) and (ii)0 <= 10_000 - delta_fee < 16_384
. However, ifdelta_fee = 10_000
, then both conditions (i) and (ii) are satisfied. What we really want for condition (ii) is0 <= 9_999 - delta_fee < 16_384
.#33526
Summary of Changes
transfer_amount - transfer_fee
is a positive 64-bit number. Since the range proofs are batched, this additional condition does not increase the cost or size of the range proof itself.Fixes #