Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove hash opcodes from AVM #9209

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
dbanks12 marked this conversation as resolved.
Show resolved Hide resolved
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
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
Loading