From 9e6a4c3f37f7ebc3e91ca124dc6d643f5a16ecf7 Mon Sep 17 00:00:00 2001 From: David Banks <47112877+dbanks12@users.noreply.github.com> Date: Fri, 17 May 2024 03:58:50 -0400 Subject: [PATCH] fix: Asset struct serialization does not match Noir internal serialization (#6494) --- .../contracts/lending_contract/src/asset.nr | 16 +++++++++------- .../contracts/price_feed_contract/src/asset.nr | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr index 7415ec54d92..54585a74eda 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr @@ -13,14 +13,16 @@ struct Asset { oracle: AztecAddress, } -global SERIALIZED_LEN: Field = 4; +global SERIALIZED_LEN: Field = 6; impl Serialize for Asset { fn serialize(Asset: Asset) -> [Field; SERIALIZED_LEN] { [ - Asset.interest_accumulator.to_integer(), + Asset.interest_accumulator.lo, + Asset.interest_accumulator.hi, Asset.last_updated_ts as Field, - Asset.loan_to_value.to_integer(), + Asset.loan_to_value.lo, + Asset.loan_to_value.hi, Asset.oracle.to_field() ] } @@ -30,10 +32,10 @@ impl Deserialize for Asset { // Right now we are wasting so many writes. If changing last_updated_ts // we will end up rewriting all of them, wasting writes. fn deserialize(fields: [Field; SERIALIZED_LEN]) -> Asset { - let interest_accumulator = U128::from_integer(fields[0]); - let last_updated_ts = fields[1] as u64; - let loan_to_value = U128::from_integer(fields[2]); - let oracle = AztecAddress::from_field(fields[3]); + let interest_accumulator = U128 { lo: fields[0], hi: fields[1] }; + let last_updated_ts = fields[2] as u64; + let loan_to_value = U128 { lo: fields[3], hi: fields[4] }; + let oracle = AztecAddress::from_field(fields[5]); Asset { interest_accumulator, diff --git a/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr b/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr index 0f34a0429b1..147c33c0e6c 100644 --- a/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr +++ b/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr @@ -4,17 +4,17 @@ struct Asset { price: U128, } -global ASSET_SERIALIZED_LEN: Field = 1; +global ASSET_SERIALIZED_LEN: Field = 2; impl Serialize for Asset { fn serialize(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] { - [asset.price.to_integer()] + [asset.price.lo, asset.price.hi] } } impl Deserialize for Asset { fn deserialize(fields: [Field; ASSET_SERIALIZED_LEN]) -> Asset { - let price = U128::from_integer(fields[0]); + let price = U128 { lo: fields[0], hi: fields[1] }; Asset { price } } }