-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
We discovered this issue during the ETHGlobal Singapore Hackathon.
Suppose we want to update a balance based on a certain amount, such that if amount > balance we top up the balance (balance += amount - balance), else we withdraw (balance -= balance - amount). We do this with provable if:
const condition = amount.greaterThan(currBalance);
const diff = Provable.if(
condition,
Balance,
amount.sub(currBalance),
currBalance.sub(amount)
);
const to = Provable.if(
condition,
PublicKey,
address,
addressPool
);
const from = Provable.if(
condition,
PublicKey,
addressPool,
address
);
const d = UInt64.Unsafe.fromField(diff.value);
await this.transfer(tokenId, from, to, d);
(see balances.ts in my fork)
The test fails either when amount > balance or amount < balance. It only passes when amount == balance (see the test at line 50 of balances.test.ts in my fork).
starter-kit commit: ed6ced5
node version: v18.20.4
pnpm version: 9.8.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels