Skip to content

Commit

Permalink
feat: get_block_data.nr
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 23, 2023
1 parent a6a4bca commit cf031c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
12 changes: 12 additions & 0 deletions yarn-project/aztec-nr/aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/aztec/src/oracle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/aztec-nr/aztec/src/oracle/get_block_data.nr
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cf031c5

Please sign in to comment.