Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
use checked arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Dec 6, 2023
1 parent f68efb4 commit 94e0ca9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions zk-token-sdk/src/instruction/transfer/with_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,22 @@ impl TransferWithFeeProof {
transfer_amount_hi,
TRANSFER_AMOUNT_LO_BITS,
);
let amount_sub_fee = combined_amount - combined_fee_amount;
let amount_sub_fee = combined_amount
.checked_sub(combined_fee_amount)
.ok_or(ProofGenerationError::FeeCalculation)?;
let amount_sub_fee_opening = combined_opening - combined_fee_opening;

let delta_negated = MAX_DELTA_RANGE
.checked_sub(delta_fee)
.ok_or(ProofGenerationError::FeeCalculation)?;

let range_proof = RangeProof::new(
vec![
source_new_balance,
transfer_amount_lo,
transfer_amount_hi,
delta_fee,
MAX_DELTA_RANGE - delta_fee,
delta_negated,
fee_amount_lo,
fee_amount_hi,
amount_sub_fee,
Expand Down

0 comments on commit 94e0ca9

Please sign in to comment.