From cf031c575be3098330dcdf4689ece329edbcbebb Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 23 Nov 2023 15:23:44 +0000 Subject: [PATCH] feat: get_block_data.nr --- yarn-project/aztec-nr/aztec/src/abi.nr | 12 ++++++++++++ yarn-project/aztec-nr/aztec/src/oracle.nr | 1 + .../aztec-nr/aztec/src/oracle/get_block_data.nr | 10 ++++++++++ .../liquidity_mining_contract/src/main.nr | 17 ++++++++++++----- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 yarn-project/aztec-nr/aztec/src/oracle/get_block_data.nr diff --git a/yarn-project/aztec-nr/aztec/src/abi.nr b/yarn-project/aztec-nr/aztec/src/abi.nr index 541dc73cf3af..1ef9498469be 100644 --- a/yarn-project/aztec-nr/aztec/src/abi.nr +++ b/yarn-project/aztec-nr/aztec/src/abi.nr @@ -166,6 +166,18 @@ impl HistoricBlockData { ] } + pub fn deserialize(deserialized: [Field; HISTORIC_BLOCK_DATA_LENGTH]) -> Self { + HistoricBlockData { + note_hash_tree_root: deserialized[0], + nullifier_tree_root: deserialized[1], + contract_tree_root: deserialized[2], + l1_to_l2_messages_tree_root: deserialized[3], + blocks_tree_root: deserialized[4], + public_data_tree_root: deserialized[5], + global_variables_hash: deserialized[6], + } + } + pub fn empty() -> Self { Self { note_hash_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 } } diff --git a/yarn-project/aztec-nr/aztec/src/oracle.nr b/yarn-project/aztec-nr/aztec/src/oracle.nr index 03362e631f81..e6a2b544c871 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle.nr @@ -12,6 +12,7 @@ mod get_public_key; mod get_secret_key; mod rand; mod enqueue_public_function_call; +mod get_block_data; mod public_call; mod notes; mod storage; diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_block_data.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_block_data.nr new file mode 100644 index 000000000000..2a36a6076e82 --- /dev/null +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_block_data.nr @@ -0,0 +1,10 @@ +use crate::constants_gen::HISTORIC_BLOCK_DATA_LENGTH; +use crate::abi::HistoricBlockData; + +#[oracle(getBlockData)] +fn get_block_data_oracle(_block_number: Field) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {} + +unconstrained pub fn get_block_data(block_number: Field) -> HistoricBlockData { + let block_data = get_block_data_oracle(block_number); + HistoricBlockData::deserialize(block_data) +} \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/liquidity_mining_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/liquidity_mining_contract/src/main.nr index c8e6d41fbc46..73920e80d7ef 100644 --- a/yarn-project/noir-contracts/src/contracts/liquidity_mining_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/liquidity_mining_contract/src/main.nr @@ -23,9 +23,12 @@ contract LiquidityMining { HISTORIC_BLOCKS_TREE_HEIGHT, GENERATOR_INDEX__BLOCK_HASH, }, - oracle::get_membership_witness::{ - get_membership_witness, - MembershipWitness, + oracle::{ + get_membership_witness::{ + get_membership_witness, + MembershipWitness, + }, + get_block_data::get_block_data, }, // oracle::debug_log::debug_log_format, }; @@ -86,16 +89,20 @@ contract LiquidityMining { #[aztec(private)] fn claim( owner: AztecAddress, + block_number: Field, // The block at which we'll prove that the note exists ) { let balances = storage.balances.at(owner.address); - let ignored_block_number = 0; // Oracle ignores this now and only gets the sibling path at the latest block + let not_ignored_block_number = block_number; + let ignored_block_number = 0; // Sibling path oracle ignores this now and only gets the path at the latest block // 1.c) + let block_data = get_block_data(not_ignored_block_number); + // let block_data = context.block_data; + // TODO: Seems to make sense to move the following to `HistoricBlockData` struct. // TODO: Would make sense to unify the ordering in `HistoricBlockData::serialize` function and the ordering // in the block hash preimage --> This seems to require changes in the circuits. - let block_data = context.block_data; let inputs = [ block_data.global_variables_hash, block_data.note_hash_tree_root,