Skip to content

Commit

Permalink
feat(avm): integrate new range and cmp gadgets (#8165)
Browse files Browse the repository at this point in the history
```
time AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode /tmp/bb-dY93DM/tmp-ygXEjA/avm_bytecode.bin --avm-calldata /tmp/bb-dY93DM/tmp-ygXEjA/avm_calldata.bin --avm-public-inputs /tmp/bb-dY93DM/tmp-ygXEjA/avm_public_inputs.bin --avm-hints /tmp/bb-dY93DM/tmp-ygXEjA/avm_hints.bin -o /tmp/bb-dY93DM/tmp-ygXEjA/ -v
bb command is: avm_prove
bytecode size: 38126
calldata size: 6
public_inputs size: 691
hints.storage_value_hints size: 2
hints.note_hash_exists_hints size: 0
hints.nullifier_exists_hints size: 1
hints.l1_to_l2_message_exists_hints size: 0
hints.externalcall_hints size: 0
hints.contract_instance_hints size: 0
initializing crs with size: 1048576
using cached crs of size 33554433 at "/mnt/user-data/ilyas/.bb-crs/bn254_g1.dat"
Deserialized 3322 instructions
------- GENERATING TRACE -------
Trace sizes before padding:
        main_trace_size: 65535
        mem_trace_size: 2084
        alu_trace_size: 410
        range_check_size: 65536
        conv_trace_size: 1
        bin_trace_size: 0
        sha256_trace_size: 0
        poseidon2_trace_size: 0
        pedersen_trace_size: 4
        gas_trace_size: 890
        fixed_gas_table_size: 66
        slice_trace_size: 7
        range_check_trace_size: 4266
        cmp_trace_size: 39
Built trace size: 65536
Number of columns: 696
Number of non-zero elements: 236111/45613056 (0%)
Relation degrees:
        alu: [5°: 2, 4°: 6, 3°: 11, 2°: 24, 1°: 5]
        binary: [3°: 1, 2°: 9]
        cmp: [4°: 3, 3°: 1, 2°: 21, 1°: 2]
        conversion: [2°: 1]
        gas: [4°: 2, 3°: 2, 2°: 2]
        keccakf1600: [2°: 1]
        kernel: [3°: 3, 2°: 41]
        main: [4°: 3, 3°: 7, 2°: 101, 1°: 3]
        mem: [5°: 1, 3°: 8, 2°: 41, 1°: 2]
        mem_slice: [3°: 3, 2°: 7, 1°: 1]
        pedersen: [2°: 1]
        poseidon2: [6°: 256, 2°: 17]
        range_check: [3°: 1, 2°: 15, 1°: 9]
        sha256: [2°: 1]
Trace size after padding: 2^16
------- PROVING EXECUTION -------
vk fields size: 66
circuit size: 0x0000000000000000000000000000000000000000000000000000000000010000
num of pub inputs: 0x0000000000000000000000000000000000000000000000000000000000000000
proof written to: "/tmp/bb-dY93DM/tmp-ygXEjA/proof"
vk written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk"
vk as fields written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk_fields.json"
------- STATS -------
prove/all_ms: 6953
prove/create_composer_ms: 0
prove/create_prover_ms: 1988
prove/create_verifier_ms: 41
prove/execute_log_derivative_inverse_commitments_round_ms: 344
prove/execute_log_derivative_inverse_round_ms: 205
prove/execute_pcs_rounds_ms: 760
prove/execute_relation_check_rounds_ms: 727
prove/execute_wire_commitments_round_ms: 616
prove/gen_trace_ms: 2150

AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode  --avm-calldata        71.13s user 69.17s system 1579% cpu 8.882 total
```
  • Loading branch information
IlyasRidhuan authored and codygunton committed Aug 30, 2024
1 parent 61071df commit 107f34a
Show file tree
Hide file tree
Showing 13 changed files with 870 additions and 949 deletions.
1 change: 1 addition & 0 deletions barretenberg/cpp/pil/avm/alu.pil
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include "gadgets/range_check.pil";
include "gadgets/cmp.pil";
namespace alu(256);

// =============== Table ALU-TR =================================================
Expand Down
30 changes: 11 additions & 19 deletions barretenberg/cpp/pil/avm/gadgets/range_check.pil
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
include "../main.pil";
include "../mem.pil";
include "../fixed/powers.pil";

namespace range_check(256);
// TODO: We should look to rename this to something like rng_idx
Expand Down Expand Up @@ -196,25 +193,20 @@ namespace range_check(256);
// We range check 40 bits in the mem trace
mem_rng_chk * (rng_chk_bits - 40) = 0;

#[PERM_RNG_MEM]
mem_rng_chk {clk, value}
is
mem.sel_rng_chk {mem.tsp, mem.diff};

// ===== GAS TRACE RANGE CHECKS =====
pol commit gas_l2_rng_chk;
pol commit gas_da_rng_chk;
// We range check 32 bits in the gas trace
gas_l2_rng_chk * (rng_chk_bits - 32) = 0;
gas_da_rng_chk * (rng_chk_bits - 32) = 0;

#[PERM_RNG_GAS_L2]
gas_l2_rng_chk {clk, value}
is
main.sel_execution_row {main.clk, main.abs_l2_rem_gas };

#[PERM_RNG_GAS_DA]
gas_da_rng_chk {clk, value}
is
main.sel_execution_row {main.clk, main.abs_da_rem_gas };
gas_l2_rng_chk * (rng_chk_bits - 32) = 0;
gas_da_rng_chk * (rng_chk_bits - 32) = 0;

// ==== CMP TRACE RANGE CHECKS =====
pol commit cmp_lo_bits_rng_chk;
pol commit cmp_hi_bits_rng_chk;
// We range check 128 bits in the cmp trace
cmp_lo_bits_rng_chk * (rng_chk_bits - 128) = 0;
cmp_hi_bits_rng_chk * (rng_chk_bits - 128) = 0;

// ==== ALU TRACE RANGE CHECKS ====
pol commit alu_rng_chk;
13 changes: 13 additions & 0 deletions barretenberg/cpp/pil/avm/gas.pil
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ namespace main(256);
sel_execution_row {opcode_val, base_l2_gas_op_cost, base_da_gas_op_cost, dyn_l2_gas_op_cost, dyn_da_gas_op_cost}
in
gas.sel_gas_cost {clk, gas.base_l2_gas_fixed_table, gas.base_da_gas_fixed_table, gas.dyn_l2_gas_fixed_table, gas.dyn_da_gas_fixed_table};

// ========= Initialize Range Check Gadget ===============================
// We range check that the absolute value of the differences between each row of l2 and da gas are 32 bits.
#[PERM_RNG_GAS_L2]
range_check.gas_l2_rng_chk {range_check.clk, range_check.value}
is
main.sel_execution_row {main.clk, main.abs_l2_rem_gas };

#[PERM_RNG_GAS_DA]
range_check.gas_da_rng_chk {range_check.clk, range_check.value}
is
main.sel_execution_row {main.clk, main.abs_da_rem_gas };

1 change: 0 additions & 1 deletion barretenberg/cpp/pil/avm/mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace mem(256);

// Helper columns
pol commit one_min_inv; // Extra value to prove r_in_tag != tag with error handling
// pol DIFF:
pol commit diff; // 40-bit difference between two consecutive timestamps or two consecutive addresses

// Type constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.poseidon2_mem_addr_write_d[i] = rows[i].poseidon2_mem_addr_write_d;
polys.poseidon2_output_addr[i] = rows[i].poseidon2_output_addr;
polys.poseidon2_sel_poseidon_perm[i] = rows[i].poseidon2_sel_poseidon_perm;
polys.range_check_alu_rng_chk[i] = rows[i].range_check_alu_rng_chk;
polys.range_check_clk[i] = rows[i].range_check_clk;
polys.range_check_cmp_hi_bits_rng_chk[i] = rows[i].range_check_cmp_hi_bits_rng_chk;
polys.range_check_cmp_lo_bits_rng_chk[i] = rows[i].range_check_cmp_lo_bits_rng_chk;
polys.range_check_dyn_diff[i] = rows[i].range_check_dyn_diff;
polys.range_check_dyn_rng_chk_bits[i] = rows[i].range_check_dyn_rng_chk_bits;
polys.range_check_dyn_rng_chk_pow_2[i] = rows[i].range_check_dyn_rng_chk_pow_2;
Expand Down
Loading

0 comments on commit 107f34a

Please sign in to comment.