Skip to content

Commit

Permalink
feat\!: remove hash opcodes from AVM
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Oct 22, 2024
1 parent 28392d5 commit facad97
Show file tree
Hide file tree
Showing 108 changed files with 9,292 additions and 11,919 deletions.
8 changes: 1 addition & 7 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,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 @@ -170,14 +167,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 @@ -963,7 +963,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 @@ -89,9 +88,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 @@ -250,9 +247,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 @@ -421,8 +416,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 @@ -546,11 +541,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 @@ -559,16 +553,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
Loading

0 comments on commit facad97

Please sign in to comment.