Skip to content

Commit

Permalink
feat: first pass removing old public inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasRidhuan committed Nov 25, 2024
1 parent 68fc957 commit d05ccb0
Show file tree
Hide file tree
Showing 51 changed files with 3,180 additions and 3,579 deletions.
25 changes: 22 additions & 3 deletions barretenberg/cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include "binary.pil";
include "constants_gen.pil";
include "constants_misc.pil";
include "gas.pil";
include "kernel.pil";
//include "kernel.pil";
include "bytecode.pil";
include "fixed/powers.pil";
include "gadgets/conversion.pil";
Expand All @@ -16,6 +16,17 @@ include "gadgets/mem_slice.pil";
include "gadgets/merkle_tree.pil";

namespace main(256);
//===== PUBLIC INPUT POLYNOMIALS ======================================
pol public kernel_inputs;
pol public kernel_value_out;
pol public kernel_side_effect_out;
pol public kernel_metadata_out;

pol constant sel_l2_start_gas_kernel_input;
pol constant sel_da_start_gas_kernel_input;
pol constant sel_l2_end_gas_kernel_input;
pol constant sel_da_end_gas_kernel_input;

//===== CONSTANT POLYNOMIALS ==================================================
pol constant clk(i) { i };
pol constant sel_first = [1] + [0]*; // Used mostly to toggle off the first row consisting
Expand Down Expand Up @@ -433,11 +444,19 @@ namespace main(256);
pol SEL_ALL_GADGET = sel_op_radix_be + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak
+ sel_op_ecadd + sel_op_msm;
pol SEL_ALL_MEMORY = sel_op_mov + sel_op_set;
pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_sender
+ sel_op_function_selector + sel_op_transaction_fee + sel_op_chain_id
+ sel_op_version + sel_op_block_number + sel_op_timestamp
+ sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas + sel_op_is_static_call;
pol KERNEL_OUTPUT_SELECTORS = sel_op_note_hash_exists + sel_op_emit_note_hash + sel_op_nullifier_exists
+ sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists + sel_op_emit_unencrypted_log
+ sel_op_emit_l2_to_l1_msg + sel_op_sload + sel_op_sstore;
// Ensure that only one kernel lookup is active when the kernel_in_offset is active
pol OPCODE_SELECTORS = sel_op_fdiv + sel_op_calldata_copy + sel_op_get_contract_instance
+ sel_op_returndata_size + sel_op_returndata_copy + sel_op_debug_log
+ SEL_ALL_ALU + SEL_ALL_BINARY + SEL_ALL_MEMORY + SEL_ALL_GADGET
+ KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS + SEL_ALL_LEFTGAS
+ SEL_ALL_CTRL_FLOW;
+ SEL_ALL_LEFTGAS + SEL_ALL_CTRL_FLOW
+ KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS;

pol CUR_AND_NEXT_ARE_MAIN = sel_execution_row * sel_execution_row';

Expand Down
11 changes: 3 additions & 8 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,17 +955,12 @@ void avm_prove(const std::filesystem::path& calldata_path,
const std::filesystem::path& output_path)
{
std::vector<fr> const calldata = many_from_buffer<fr>(read_file(calldata_path));
std::vector<fr> const public_inputs_vec = many_from_buffer<fr>(read_file(public_inputs_path));
auto const avm_new_public_inputs = AvmPublicInputs::from(read_file(public_inputs_path));
auto const avm_hints = bb::avm_trace::ExecutionHints::from(read_file(hints_path));
// Tmp hack to get the new public inputs
std::filesystem::path new_public_inputs_path = public_inputs_path;
new_public_inputs_path.replace_filename("new_avm_public_inputs.bin");
auto const avm_new_public_inputs = AvmPublicInputs::from(read_file(new_public_inputs_path));

// Using [0] is fine now for the top-level call, but we might need to index by address in future
vinfo("bytecode size: ", avm_hints.all_contract_bytecode[0].bytecode.size());
vinfo("calldata size: ", calldata.size());
vinfo("public_inputs size: ", public_inputs_vec.size());
vinfo("hints.storage_value_hints size: ", avm_hints.storage_value_hints.size());
vinfo("hints.note_hash_exists_hints size: ", avm_hints.note_hash_exists_hints.size());
vinfo("hints.nullifier_exists_hints size: ", avm_hints.nullifier_exists_hints.size());
Expand All @@ -978,8 +973,8 @@ void avm_prove(const std::filesystem::path& calldata_path,
init_bn254_crs(avm_trace::Execution::SRS_SIZE);

// Prove execution and return vk
auto const [verification_key, proof] = AVM_TRACK_TIME_V(
"prove/all", avm_trace::Execution::prove(calldata, public_inputs_vec, avm_new_public_inputs, avm_hints));
auto const [verification_key, proof] =
AVM_TRACK_TIME_V("prove/all", avm_trace::Execution::prove(calldata, avm_new_public_inputs, avm_hints));

std::vector<fr> vk_as_fields = verification_key.to_field_elements();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_dyn_da_gas_op_cost.set_if_valid_index(i, rows[i].main_dyn_da_gas_op_cost);
polys.main_dyn_gas_multiplier.set_if_valid_index(i, rows[i].main_dyn_gas_multiplier);
polys.main_dyn_l2_gas_op_cost.set_if_valid_index(i, rows[i].main_dyn_l2_gas_op_cost);
polys.main_emit_l2_to_l1_msg_write_offset.set_if_valid_index(
i, rows[i].main_emit_l2_to_l1_msg_write_offset);
polys.main_emit_note_hash_write_offset.set_if_valid_index(i, rows[i].main_emit_note_hash_write_offset);
polys.main_emit_nullifier_write_offset.set_if_valid_index(i, rows[i].main_emit_nullifier_write_offset);
polys.main_emit_unencrypted_log_write_offset.set_if_valid_index(
i, rows[i].main_emit_unencrypted_log_write_offset);
polys.main_ia.set_if_valid_index(i, rows[i].main_ia);
polys.main_ib.set_if_valid_index(i, rows[i].main_ib);
polys.main_ic.set_if_valid_index(i, rows[i].main_ic);
Expand All @@ -280,10 +274,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_inv.set_if_valid_index(i, rows[i].main_inv);
polys.main_is_fake_row.set_if_valid_index(i, rows[i].main_is_fake_row);
polys.main_is_gas_accounted.set_if_valid_index(i, rows[i].main_is_gas_accounted);
polys.main_kernel_in_offset.set_if_valid_index(i, rows[i].main_kernel_in_offset);
polys.main_kernel_out_offset.set_if_valid_index(i, rows[i].main_kernel_out_offset);
polys.main_l1_to_l2_msg_exists_write_offset.set_if_valid_index(
i, rows[i].main_l1_to_l2_msg_exists_write_offset);
polys.main_l2_gas_remaining.set_if_valid_index(i, rows[i].main_l2_gas_remaining);
polys.main_l2_gas_u16_r0.set_if_valid_index(i, rows[i].main_l2_gas_u16_r0);
polys.main_l2_gas_u16_r1.set_if_valid_index(i, rows[i].main_l2_gas_u16_r1);
Expand All @@ -292,12 +282,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_mem_addr_b.set_if_valid_index(i, rows[i].main_mem_addr_b);
polys.main_mem_addr_c.set_if_valid_index(i, rows[i].main_mem_addr_c);
polys.main_mem_addr_d.set_if_valid_index(i, rows[i].main_mem_addr_d);
polys.main_note_hash_exist_write_offset.set_if_valid_index(i,
rows[i].main_note_hash_exist_write_offset);
polys.main_nullifier_exists_write_offset.set_if_valid_index(i,
rows[i].main_nullifier_exists_write_offset);
polys.main_nullifier_non_exists_write_offset.set_if_valid_index(
i, rows[i].main_nullifier_non_exists_write_offset);
polys.main_op_err.set_if_valid_index(i, rows[i].main_op_err);
polys.main_opcode_val.set_if_valid_index(i, rows[i].main_opcode_val);
polys.main_pc.set_if_valid_index(i, rows[i].main_pc);
Expand All @@ -311,8 +295,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_calldata.set_if_valid_index(i, rows[i].main_sel_calldata);
polys.main_sel_execution_end.set_if_valid_index(i, rows[i].main_sel_execution_end);
polys.main_sel_execution_row.set_if_valid_index(i, rows[i].main_sel_execution_row);
polys.main_sel_kernel_inputs.set_if_valid_index(i, rows[i].main_sel_kernel_inputs);
polys.main_sel_kernel_out.set_if_valid_index(i, rows[i].main_sel_kernel_out);
polys.main_sel_mem_op_a.set_if_valid_index(i, rows[i].main_sel_mem_op_a);
polys.main_sel_mem_op_b.set_if_valid_index(i, rows[i].main_sel_mem_op_b);
polys.main_sel_mem_op_c.set_if_valid_index(i, rows[i].main_sel_mem_op_c);
Expand Down Expand Up @@ -388,10 +370,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_rng_16.set_if_valid_index(i, rows[i].main_sel_rng_16);
polys.main_sel_rng_8.set_if_valid_index(i, rows[i].main_sel_rng_8);
polys.main_sel_slice_gadget.set_if_valid_index(i, rows[i].main_sel_slice_gadget);
polys.main_side_effect_counter.set_if_valid_index(i, rows[i].main_side_effect_counter);
polys.main_sload_write_offset.set_if_valid_index(i, rows[i].main_sload_write_offset);
polys.main_space_id.set_if_valid_index(i, rows[i].main_space_id);
polys.main_sstore_write_offset.set_if_valid_index(i, rows[i].main_sstore_write_offset);
polys.main_tag_err.set_if_valid_index(i, rows[i].main_tag_err);
polys.main_w_in_tag.set_if_valid_index(i, rows[i].main_w_in_tag);
polys.mem_addr.set_if_valid_index(i, rows[i].mem_addr);
Expand Down Expand Up @@ -831,8 +810,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.lookup_l2_gas_rng_chk_1_counts.set_if_valid_index(i, rows[i].lookup_l2_gas_rng_chk_1_counts);
polys.lookup_da_gas_rng_chk_0_counts.set_if_valid_index(i, rows[i].lookup_da_gas_rng_chk_0_counts);
polys.lookup_da_gas_rng_chk_1_counts.set_if_valid_index(i, rows[i].lookup_da_gas_rng_chk_1_counts);
polys.kernel_output_lookup_counts.set_if_valid_index(i, rows[i].kernel_output_lookup_counts);
polys.lookup_into_kernel_counts.set_if_valid_index(i, rows[i].lookup_into_kernel_counts);
polys.lookup_cd_value_counts.set_if_valid_index(i, rows[i].lookup_cd_value_counts);
polys.lookup_ret_value_counts.set_if_valid_index(i, rows[i].lookup_ret_value_counts);
polys.incl_main_tag_err_counts.set_if_valid_index(i, rows[i].incl_main_tag_err_counts);
Expand Down
Loading

0 comments on commit d05ccb0

Please sign in to comment.