Skip to content

Commit

Permalink
feat!: remove hash opcodes from AVM (#9209)
Browse files Browse the repository at this point in the history
Resolves #9208
  • Loading branch information
dbanks12 authored Oct 22, 2024
1 parent 465f88e commit e6db535
Show file tree
Hide file tree
Showing 38 changed files with 929 additions and 2,037 deletions.
8 changes: 1 addition & 7 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ pub enum AvmOpcode {
// Misc
DEBUGLOG,
// Gadgets
KECCAK,
POSEIDON2,
SHA256COMPRESSION,
KECCAKF1600,
PEDERSEN, // temp - may be removed, but alot of contracts rely on it
ECADD,
MSM,
PEDERSENCOMMITMENT, // temp
// Conversions
TORADIXLE,
}
Expand Down Expand Up @@ -168,14 +165,11 @@ impl AvmOpcode {
AvmOpcode::DEBUGLOG => "DEBUGLOG",

// Gadgets
AvmOpcode::KECCAK => "KECCAK",
AvmOpcode::KECCAKF1600 => "KECCAKF1600",
AvmOpcode::POSEIDON2 => "POSEIDON2",
AvmOpcode::SHA256COMPRESSION => "SHA256COMPRESSION",
AvmOpcode::PEDERSEN => "PEDERSEN",
AvmOpcode::KECCAKF1600 => "KECCAKF1600",
AvmOpcode::ECADD => "ECADD",
AvmOpcode::MSM => "MSM",
AvmOpcode::PEDERSENCOMMITMENT => "PEDERSENCOMMITMENT",
// Conversions
AvmOpcode::TORADIXLE => "TORADIXLE",
}
Expand Down
2 changes: 1 addition & 1 deletion avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ fn generate_mov_instruction(
}
}

/// Black box functions, for the meantime only covers pedersen operations as the blackbox function api suits our current needs.
/// Black box functions
/// (array goes in -> field element comes out)
fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &BlackBoxOp) {
match operation {
Expand Down
11 changes: 0 additions & 11 deletions barretenberg/cpp/pil/avm/gadgets/pedersen.pil

This file was deleted.

33 changes: 11 additions & 22 deletions barretenberg/cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ include "gadgets/conversion.pil";
include "gadgets/sha256.pil";
include "gadgets/poseidon2.pil";
include "gadgets/keccakf1600.pil";
include "gadgets/pedersen.pil";
include "gadgets/mem_slice.pil";

namespace main(256);
Expand Down Expand Up @@ -88,9 +87,7 @@ namespace main(256);
pol commit sel_op_sha256;
pol commit sel_op_poseidon2;
pol commit sel_op_keccak;
pol commit sel_op_pedersen;
pol commit sel_op_ecadd;
pol commit sel_op_pedersen_commit;
pol commit sel_op_msm;

//===== Memory Slice Gadget Selectors =========================================
Expand Down Expand Up @@ -248,9 +245,7 @@ namespace main(256);
sel_op_sha256 * (1 - sel_op_sha256) = 0;
sel_op_poseidon2 * (1 - sel_op_poseidon2) = 0;
sel_op_keccak * (1 - sel_op_keccak) = 0;
sel_op_pedersen * (1 - sel_op_pedersen) = 0;
sel_op_ecadd * (1 - sel_op_ecadd) = 0;
sel_op_pedersen_commit * (1 - sel_op_pedersen_commit) = 0;
sel_op_msm * (1 - sel_op_msm) = 0;

sel_op_add * (1 - sel_op_add) = 0;
Expand Down Expand Up @@ -419,8 +414,8 @@ namespace main(256);
pol SEL_ALL_ALU = SEL_ALU_R_TAG + SEL_ALU_W_TAG;
pol SEL_ALL_LEFTGAS = sel_op_dagasleft + sel_op_l2gasleft;
pol SEL_ALL_BINARY = sel_op_and + sel_op_or + sel_op_xor;
pol SEL_ALL_GADGET = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak + sel_op_pedersen
+ sel_op_ecadd + sel_op_pedersen_commit + sel_op_msm;
pol SEL_ALL_GADGET = sel_op_radix_le + 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 OPCODE_SELECTORS = sel_op_fdiv + sel_op_calldata_copy + sel_op_get_contract_instance
+ SEL_ALL_ALU + SEL_ALL_BINARY + SEL_ALL_MEMORY + SEL_ALL_GADGET
Expand Down Expand Up @@ -544,11 +539,10 @@ namespace main(256);
is
conversion.sel_to_radix_le {conversion.clk, conversion.input, conversion.radix, conversion.num_limbs, conversion.output_bits};

// This will be enabled when we migrate just to sha256Compression, as getting sha256 to work with it is tricky.
// #[PERM_MAIN_SHA256]
// sel_op_sha256 {clk, ia, ib, ic}
// is
// sha256.sel_sha256_compression {sha256.clk, sha256.state, sha256.input, sha256.output};
#[PERM_MAIN_SHA256]
sel_op_sha256 {clk, ia, ib, ic}
is
sha256.sel_sha256_compression {sha256.clk, sha256.state, sha256.input, sha256.output};

// Mem_addr_a points to the start of the input array of length 4
// Mem_addr_b points to the start of the output array of length 4
Expand All @@ -557,16 +551,11 @@ namespace main(256);
is
poseidon2.sel_poseidon_perm {poseidon2.clk, poseidon2.space_id, poseidon2.input_addr, poseidon2.output_addr};

// This will be enabled when we migrate just to keccakf1600, as getting keccak to work with it is tricky.
// #[PERM_MAIN_KECCAK]
// sel_op_keccak {clk, ia, ic}
// is
// keccakf1600.sel_keccakf1600 {keccakf1600.clk, keccakf1600.input, keccakf1600.output};

#[PERM_MAIN_PEDERSEN]
sel_op_pedersen {clk, ia}
is
pedersen.sel_pedersen {pedersen.clk, pedersen.input};
// TODO: re-enable this. Should have worked when we migrated just to keccakf1600, but it didn't.
//#[PERM_MAIN_KECCAK]
//sel_op_keccak {clk, ia, ic}
//is
//keccakf1600.sel_keccakf1600 {keccakf1600.clk, keccakf1600.input, keccakf1600.output};

#[PERM_MAIN_SLICE]
sel_slice_gadget {clk, space_id, ia, ib, mem_addr_c, sel_op_calldata_copy, sel_op_external_return}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_op_note_hash_exists.set_if_valid_index(i, rows[i].main_sel_op_note_hash_exists);
polys.main_sel_op_nullifier_exists.set_if_valid_index(i, rows[i].main_sel_op_nullifier_exists);
polys.main_sel_op_or.set_if_valid_index(i, rows[i].main_sel_op_or);
polys.main_sel_op_pedersen.set_if_valid_index(i, rows[i].main_sel_op_pedersen);
polys.main_sel_op_pedersen_commit.set_if_valid_index(i, rows[i].main_sel_op_pedersen_commit);
polys.main_sel_op_poseidon2.set_if_valid_index(i, rows[i].main_sel_op_poseidon2);
polys.main_sel_op_radix_le.set_if_valid_index(i, rows[i].main_sel_op_radix_le);
polys.main_sel_op_sender.set_if_valid_index(i, rows[i].main_sel_op_sender);
Expand Down Expand Up @@ -351,10 +349,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.mem_tsp.set_if_valid_index(i, rows[i].mem_tsp);
polys.mem_val.set_if_valid_index(i, rows[i].mem_val);
polys.mem_w_in_tag.set_if_valid_index(i, rows[i].mem_w_in_tag);
polys.pedersen_clk.set_if_valid_index(i, rows[i].pedersen_clk);
polys.pedersen_input.set_if_valid_index(i, rows[i].pedersen_input);
polys.pedersen_output.set_if_valid_index(i, rows[i].pedersen_output);
polys.pedersen_sel_pedersen.set_if_valid_index(i, rows[i].pedersen_sel_pedersen);
polys.poseidon2_B_10_0.set_if_valid_index(i, rows[i].poseidon2_B_10_0);
polys.poseidon2_B_10_1.set_if_valid_index(i, rows[i].poseidon2_B_10_1);
polys.poseidon2_B_10_2.set_if_valid_index(i, rows[i].poseidon2_B_10_2);
Expand Down
Loading

0 comments on commit e6db535

Please sign in to comment.