Skip to content

Commit

Permalink
feat: Use constants_gen for constants (#2742)
Browse files Browse the repository at this point in the history
Re exporting globals doesn't quite work ): so I just replaced every use
with constants gen and added a missing generator index
  • Loading branch information
sirasistant authored Oct 9, 2023
1 parent 380bd94 commit 6896db8
Show file tree
Hide file tree
Showing 51 changed files with 249 additions and 359 deletions.
2 changes: 2 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct GeneratorIndexPacker {
int SIGNED_TX_REQUEST = GeneratorIndex::SIGNED_TX_REQUEST;
int GLOBAL_VARIABLES = GeneratorIndex::GLOBAL_VARIABLES;
int PARTIAL_ADDRESS = GeneratorIndex::PARTIAL_ADDRESS;
int BLOCK_HASH = GeneratorIndex::BLOCK_HASH;
int TX_REQUEST = GeneratorIndex::TX_REQUEST;
int SIGNATURE_PAYLOAD = GeneratorIndex::SIGNATURE_PAYLOAD;
int VK = GeneratorIndex::VK;
Expand Down Expand Up @@ -166,6 +167,7 @@ struct GeneratorIndexPacker {
SIGNED_TX_REQUEST,
GLOBAL_VARIABLES,
PARTIAL_ADDRESS,
BLOCK_HASH,
TX_REQUEST,
SIGNATURE_PAYLOAD,
VK,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/aztec/src/constants_gen.nr
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ global GENERATOR_INDEX__PUBLIC_DATA_LEAF = 24;
global GENERATOR_INDEX__SIGNED_TX_REQUEST = 25;
global GENERATOR_INDEX__GLOBAL_VARIABLES = 26;
global GENERATOR_INDEX__PARTIAL_ADDRESS = 27;
global GENERATOR_INDEX__BLOCK_HASH = 28;
global GENERATOR_INDEX__TX_REQUEST = 33;
global GENERATOR_INDEX__SIGNATURE_PAYLOAD = 34;
global GENERATOR_INDEX__VK = 41;
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/cbind/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export enum GeneratorIndex {
SIGNED_TX_REQUEST = 25,
GLOBAL_VARIABLES = 26,
PARTIAL_ADDRESS = 27,
BLOCK_HASH = 28,
TX_REQUEST = 33,
SIGNATURE_PAYLOAD = 34,
VK = 41,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ compiler_version = "0.16.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
aztec = { path="../../../../aztec-nr/aztec" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::private_kernel_lib::constants;
use dep::aztec::constants_gen;
use dep::private_kernel_lib::common;
use dep::private_kernel_lib::mocked::{Proof, AggregationObject,verify_previous_kernel_state};
use dep::private_kernel_lib::abis::private_kernel::private_call_data::PrivateCallData;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl PrivateKernelInputsInit {

// Push an empty nullified commitment too since each nullifier must
// be paired with a nonzero (real or "empty") nullified commitment
public_inputs.end.nullified_commitments = arrays::array_push_field(public_inputs.end.nullified_commitments, constants::misc::EMPTY_NULLIFIED_COMMITMENT);
public_inputs.end.nullified_commitments = arrays::array_push_field(public_inputs.end.nullified_commitments, constants_gen::EMPTY_NULLIFIED_COMMITMENT);

// Note that we do not need to nullify the transaction request nonce anymore.
// Should an account want to additionally use nonces for replay protection or handling cancellations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ compiler_version = "0.16.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
aztec = { path="../../../../aztec-nr/aztec" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::private_kernel_lib::constants::per_transaction::{MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX};
use dep::aztec::constants_gen::{MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX};
use dep::private_kernel_lib::common;
use dep::private_kernel_lib::mocked::{Proof, AggregationObject, verify_previous_kernel_state};
use dep::private_kernel_lib::abis::private_kernel::private_call_data::PrivateCallData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ authors = [""]
compiler_version = "0.16.0"

[dependencies]
aztec = { path="../../../../aztec-nr/aztec" }
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ mod call_stack_item;
mod call_context;

mod public_circuit_public_inputs;
mod private_circuit_public_inputs;
mod private_circuit_public_inputs;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::abis::function_selector::FunctionSelector;
use crate::address::{EthAddress,Address};
use crate::constants;
use dep::aztec::constants_gen;

struct CallContext{
msg_sender : Address,
Expand All @@ -16,7 +16,7 @@ struct CallContext{

impl CallContext {
fn hash(self) -> Field {
let _hash_index = constants::generator_index::CALL_CONTEXT;
let _hash_index = constants_gen::GENERATOR_INDEX__CALL_CONTEXT;
0
}

Expand All @@ -29,4 +29,4 @@ impl CallContext {
assert(self.is_static_call == false);
assert(self.is_contract_deployment == false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::address::Address;
use crate::abis::function_data::FunctionData;
use crate::constants::per_call::{MAX_READ_REQUESTS_PER_CALL};
use dep::aztec::constants_gen::{MAX_READ_REQUESTS_PER_CALL};
use crate::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs;
use crate::abis::public_circuit_public_inputs::PublicCircuitPublicInputs;

Expand Down Expand Up @@ -77,4 +77,4 @@ impl PrivateCallStackItem {
fn function_data(self) -> FunctionData{
self.inner.function_data
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ use crate::abis::new_contract_data::NewContractData;
use crate::abis::optionally_revealed_data::OptionallyRevealedData;
use crate::abis::public_data_update_request::PublicDataUpdateRequest;
use crate::abis::public_data_read::PublicDataRead;
use crate::constants::per_transaction::{MAX_READ_REQUESTS_PER_TX,MAX_NEW_COMMITMENTS_PER_TX,MAX_NEW_NULLIFIERS_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
MAX_NEW_L2_TO_L1_MSGS_PER_TX,MAX_NEW_CONTRACTS_PER_TX,
MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX,MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
MAX_PUBLIC_DATA_READS_PER_TX
};
use crate::constants::misc::NUM_FIELDS_PER_SHA256;
use dep::aztec::constants_gen::{
MAX_READ_REQUESTS_PER_TX,
MAX_NEW_COMMITMENTS_PER_TX,
MAX_NEW_NULLIFIERS_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
MAX_NEW_L2_TO_L1_MSGS_PER_TX,
MAX_NEW_CONTRACTS_PER_TX,
MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX,
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
MAX_PUBLIC_DATA_READS_PER_TX
};
use crate::hash::NUM_FIELDS_PER_SHA256;

struct CombinedAccumulatedData {
aggregation_object : AggregationObject,
Expand Down Expand Up @@ -39,4 +45,4 @@ struct CombinedAccumulatedData {
public_data_update_requests : [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX],

public_data_reads : [PublicDataRead; MAX_PUBLIC_DATA_READS_PER_TX]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ impl CompleteAddress{
partial_address,
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// This is not actually being used anywhere due to Noir not
// resolving import path aliases and re-exports properly.
// If you grep for `ContractLeafPreimage` you can see its usage.
use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage;
use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::mocked::AggregationObject;
use crate::constants::misc::NUM_FIELDS_PER_SHA256;
use crate::constants::per_transaction::{MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX,MAX_NEW_CONTRACTS_PER_TX,MAX_NEW_L2_TO_L1_MSGS_PER_TX,MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,MAX_NEW_NULLIFIERS_PER_TX,MAX_NEW_COMMITMENTS_PER_TX};
use crate::hash::NUM_FIELDS_PER_SHA256;
use dep::aztec::constants_gen::{MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX,MAX_NEW_CONTRACTS_PER_TX,MAX_NEW_L2_TO_L1_MSGS_PER_TX,MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,MAX_NEW_NULLIFIERS_PER_TX,MAX_NEW_COMMITMENTS_PER_TX};
use crate::abis::new_contract_data::NewContractData;
use crate::abis::optionally_revealed_data::OptionallyRevealedData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ impl FunctionData {
fn hash(self) -> Field {
0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::abis::function_selector::FunctionSelector;
use crate::constants;
use dep::aztec::constants_gen;

struct FunctionLeafPreimage {
selector : FunctionSelector,
Expand All @@ -11,7 +11,7 @@ struct FunctionLeafPreimage {

impl FunctionLeafPreimage {
fn hash(self) -> Field {
let _hash_index = constants::generator_index::FUNCTION_LEAF;
let _hash_index = constants_gen::GENERATOR_INDEX__FUNCTION_LEAF;
0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ impl FunctionSelector {
fn to_field(self) -> Field {
self.inner as Field
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ impl HistoricalBlockData {
fn contract_tree_root(self) -> Field {
self.block.contract_tree_root
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ struct KernelCircuitPublicInputsFinal {
// TODO(Jean): Left a note saying that this might need to be a witness
// In the context of Noir, this is already a witness.
is_private : bool,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ impl<N> MembershipWitness<N> {
fn is_empty(self) -> bool {
is_empty_field([self.leaf_index]) && is_empty_field(self.sibling_path)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::address::{Address, EthAddress};
use crate::{constants, utils};
use crate::utils;
use dep::aztec::constants_gen;

struct NewContractData {
contract_address : Address,
Expand All @@ -18,7 +19,7 @@ impl NewContractData {
if self.is_empty() {
0 // We want to return 0 here since the contract_address is zero
} else {
let _hash_index = constants::generator_index::CONTRACT_LEAF;
let _hash_index = constants_gen::GENERATOR_INDEX__CONTRACT_LEAF;

// hash all contents and put in compress method
0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::mocked::{Proof, VerificationKey};
use crate::constants::trees::VK_TREE_HEIGHT;
use dep::aztec::constants_gen::VK_TREE_HEIGHT;
use crate::abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs;

//TODO(sean): left a note saying that this should not be called Previous
Expand All @@ -24,4 +24,4 @@ struct PreviousKernelData {
vk_path : [Field; VK_TREE_HEIGHT],


}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use crate::abis::call_context::CallContext;
use crate::constants;
use crate::constants::misc::RETURN_VALUES_LENGTH;
use crate::constants::per_call::{MAX_READ_REQUESTS_PER_CALL,MAX_NEW_COMMITMENTS_PER_CALL,MAX_NEW_NULLIFIERS_PER_CALL,MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,MAX_NEW_L2_TO_L1_MSGS_PER_CALL};
use crate::constants::misc::{NUM_FIELDS_PER_SHA256};
use dep::aztec::{
constants_gen,
constants_gen::{
MAX_READ_REQUESTS_PER_CALL,
MAX_NEW_COMMITMENTS_PER_CALL,
MAX_NEW_NULLIFIERS_PER_CALL,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
RETURN_VALUES_LENGTH,
}
};
use crate::hash::NUM_FIELDS_PER_SHA256;
use crate::abis::historical_block_data::HistoricalBlockData;
use crate::contrakt::deployment_data::ContractDeploymentData;

Expand Down Expand Up @@ -40,7 +49,7 @@ struct PrivateCircuitPublicInputs{

impl PrivateCircuitPublicInputs{
fn hash(self) -> Field {
let _hash_index = constants::generator_index::PRIVATE_CIRCUIT_PUBLIC_INPUTS;
let _hash_index = constants_gen::GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS;
0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod private_call_data;
mod private_kernel_inputs_init;
mod private_kernel_inputs_init;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ use crate::mocked::{Proof, VerificationKey};

use crate::address::{Address, EthAddress};
use crate::abis::read_request_membership_witness::ReadRequestMembershipWitness;
use crate::constants::per_call::{MAX_READ_REQUESTS_PER_CALL,MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL};
use crate::constants::trees::{CONTRACT_TREE_HEIGHT,FUNCTION_TREE_HEIGHT,PRIVATE_DATA_TREE_HEIGHT};
use dep::aztec::constants_gen::{
MAX_READ_REQUESTS_PER_CALL,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
CONTRACT_TREE_HEIGHT,
FUNCTION_TREE_HEIGHT,
PRIVATE_DATA_TREE_HEIGHT
};
use crate::abis::call_stack_item::PrivateCallStackItem;
use crate::abis::membership_witness::MembershipWitness;

Expand All @@ -24,4 +29,4 @@ struct PrivateCallData {

portal_contract_address : EthAddress,
acir_hash : Field,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ use crate::contrakt::storage_read::StorageRead;
use crate::contrakt::storage_update_request::StorageUpdateRequest;
use crate::address::Address;
use crate::abis::historical_block_data::HistoricalBlockData;
use crate::constants;
use crate::constants::misc::{NUM_FIELDS_PER_SHA256};
use crate::constants::per_call::{MAX_NEW_L2_TO_L1_MSGS_PER_CALL,MAX_NEW_NULLIFIERS_PER_CALL,MAX_NEW_COMMITMENTS_PER_CALL,MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,MAX_PUBLIC_DATA_READS_PER_CALL,MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL};
use crate::constants::misc::{RETURN_VALUES_LENGTH};
use dep::aztec::constants_gen;
use crate::hash::{NUM_FIELDS_PER_SHA256};
use dep::aztec::constants_gen::{
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
MAX_NEW_NULLIFIERS_PER_CALL,
MAX_NEW_COMMITMENTS_PER_CALL,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
MAX_PUBLIC_DATA_READS_PER_CALL,
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
RETURN_VALUES_LENGTH,
};
use crate::abis::call_context::CallContext;

struct PublicCircuitPublicInputs{
Expand Down Expand Up @@ -36,7 +43,7 @@ struct PublicCircuitPublicInputs{

impl PublicCircuitPublicInputs{
fn hash(self) -> Field {
let _hash_index = constants::generator_index::PUBLIC_CIRCUIT_PUBLIC_INPUTS;
let _hash_index = constants_gen::GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS;
0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants;
use dep::aztec::constants_gen;

struct PublicDataRead {
leaf_index : Field,
Expand All @@ -7,12 +7,12 @@ struct PublicDataRead {

impl PublicDataRead {
fn hash(self) -> Field {
let _hash_index = constants::generator_index::PUBLIC_DATA_READ;
let _hash_index = constants_gen::GENERATOR_INDEX__PUBLIC_DATA_READ;
0
}

// TODO(David): explain again why we don't check other fields
fn is_empty(self) -> bool {
self.leaf_index == 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants;
use dep::aztec::constants_gen;

struct PublicDataUpdateRequest {
leaf_index : Field,
Expand All @@ -8,12 +8,12 @@ struct PublicDataUpdateRequest {

impl PublicDataUpdateRequest {
fn hash(self) -> Field {
let _hash_index = constants::generator_index::PUBLIC_DATA_UPDATE_REQUEST;
let _hash_index = constants_gen::GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST;
0
}

// TODO(David): explain why we don't check other fields
fn is_empty(self) -> bool {
self.leaf_index == 0
}
}
}
Loading

0 comments on commit 6896db8

Please sign in to comment.