Skip to content

Commit

Permalink
HistoricBlockData::block_hash()
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 24, 2023
1 parent 39fcd1f commit 15856bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
15 changes: 15 additions & 0 deletions yarn-project/aztec-nr/aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::constants_gen::{
CONTRACT_STORAGE_READ_LENGTH,
PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,
PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,
GENERATOR_INDEX__BLOCK_HASH,
GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS,
GENERATOR_INDEX__FUNCTION_DATA,
GENERATOR_INDEX__PUBLIC_DATA_READ,
Expand Down Expand Up @@ -181,6 +182,20 @@ impl HistoricBlockData {
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 }
}

pub fn block_hash(self) -> Field {
// TODO: Unify the ordering in `HistoricBlockData::serialize` function and the ordering
// in the block hash preimage --> This requires changes in the circuits.
let inputs = [
self.global_variables_hash,
self.note_hash_tree_root,
self.nullifier_tree_root,
self.contract_tree_root,
self.l1_to_l2_messages_tree_root,
self.public_data_tree_root
];
pedersen_hash(inputs, GENERATOR_INDEX__BLOCK_HASH)
}
}

struct FunctionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ mod types;

// A demonstration of private liquidity mining.
contract LiquidityMining {
use dep::std::{
merkle::compute_merkle_root,
hash::pedersen_hash_with_separator,
};
use dep::std::merkle::compute_merkle_root;
use dep::aztec::{
state_vars::{
map::Map,
Expand All @@ -21,7 +18,6 @@ contract LiquidityMining {
constants_gen::{
NOTE_HASH_TREE_HEIGHT,
HISTORIC_BLOCKS_TREE_HEIGHT,
GENERATOR_INDEX__BLOCK_HASH,
},
oracle::{
get_membership_witness::{
Expand Down Expand Up @@ -95,22 +91,10 @@ contract LiquidityMining {

// 1.c)
let block_data = get_block_data(block_number);
let block_hash = block_data.block_hash();

// TODO: This should be injected directly from kernel --> GETTING IT FROM ORACLE IS NOT SAFE!
let blocks_tree_root = block_data.blocks_tree_root;

// 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 inputs = [
block_data.global_variables_hash,
block_data.note_hash_tree_root,
block_data.nullifier_tree_root,
block_data.contract_tree_root,
block_data.l1_to_l2_messages_tree_root,
block_data.public_data_tree_root
];
let block_hash = pedersen_hash_with_separator(inputs, GENERATOR_INDEX__BLOCK_HASH);

// 1.d)
let blocks_tree_id = 5;
Expand Down

0 comments on commit 15856bd

Please sign in to comment.