From 3d00d34496676d5c342dceea4c1e7d0b3fc4e974 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 19 Dec 2024 07:30:34 -0300 Subject: [PATCH] fix: don't U128::from_integer(u128) (#10865) In Noir we are removing the (private) built-ins `as_field` and `from_field`, which allowed casting any type to and from Field by truncating its bits. This uncovered two bugs where we were doing `U128::from_integer(x)` with `x` itself being a `U128`. That code won't compile anymore (and I think it was incorrect) so I'm doing those changes in this PR. See https://github.com/noir-lang/noir/pull/6845 --- .../noir-contracts/contracts/lending_contract/src/main.nr | 7 ++----- .../noir-contracts/contracts/spam_contract/src/main.nr | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index d9d965cea05..10c46f41891 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -313,11 +313,8 @@ contract Lending { let collateral = storage.collateral.at(owner).read(); let static_debt = storage.static_debt.at(owner).read(); let asset: Asset = storage.assets.at(0).read(); - let debt = debt_value( - U128::from_integer(static_debt), - U128::from_integer(asset.interest_accumulator), - ) - .to_integer(); + let debt = + debt_value(U128::from_integer(static_debt), asset.interest_accumulator).to_integer(); Position { collateral, static_debt, debt } } diff --git a/noir-projects/noir-contracts/contracts/spam_contract/src/main.nr b/noir-projects/noir-contracts/contracts/spam_contract/src/main.nr index fc84d76a768..ff02f27e03a 100644 --- a/noir-projects/noir-contracts/contracts/spam_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/spam_contract/src/main.nr @@ -33,7 +33,7 @@ contract Spam { let amount = U128::from_integer(1); for _ in 0..MAX_NOTE_HASHES_PER_CALL { - storage.balances.at(caller).add(caller, U128::from_integer(amount)).emit( + storage.balances.at(caller).add(caller, amount).emit( encode_and_encrypt_note_unconstrained(&mut context, caller, caller), ); }