From 1823bde2b486827f33a87899074594f811cfbef4 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:06:13 +0100 Subject: [PATCH] chore!: remove pedersen commitment (#9107) This PR removes the pedersen hash opcode as it's not currently possible to emit these from noir code. --- avm-transpiler/src/transpile.rs | 25 ---- .../dsl/acir_format/acir_format.cpp | 8 - .../dsl/acir_format/acir_format.hpp | 4 - .../dsl/acir_format/acir_format.test.cpp | 8 +- .../dsl/acir_format/acir_format_mocks.cpp | 4 - .../acir_format/acir_to_constraint_buf.cpp | 10 -- .../acir_format/bigint_constraint.test.cpp | 5 - .../dsl/acir_format/block_constraint.test.cpp | 3 - .../dsl/acir_format/ec_operations.test.cpp | 2 - .../dsl/acir_format/ecdsa_secp256k1.test.cpp | 3 - .../dsl/acir_format/ecdsa_secp256r1.test.cpp | 4 - .../honk_recursion_constraint.test.cpp | 1 - .../dsl/acir_format/multi_scalar_mul.test.cpp | 1 - .../barretenberg/dsl/acir_format/pedersen.cpp | 33 ----- .../barretenberg/dsl/acir_format/pedersen.hpp | 39 ----- .../acir_format/poseidon2_constraint.test.cpp | 1 - .../acir_format/recursion_constraint.test.cpp | 2 - .../dsl/acir_format/serde/acir.hpp | 137 ------------------ .../acir_format/sha256_constraint.test.cpp | 1 - .../noir-repo/acvm-repo/acir/codegen/acir.cpp | 112 +------------- .../acir/src/circuit/black_box_functions.rs | 4 - .../opcodes/black_box_function_call.rs | 13 -- .../acir/tests/test_program_serialization.rs | 8 +- .../acvm-repo/acvm/src/pwg/blackbox/mod.rs | 5 - .../acvm/src/pwg/blackbox/pedersen.rs | 29 ---- .../acvm_js/test/shared/multi_scalar_mul.ts | 6 +- .../src/curve_specific_solver.rs | 13 -- .../bn254_blackbox_solver/src/lib.rs | 17 --- .../acvm-repo/brillig/src/black_box.rs | 6 - .../acvm-repo/brillig_vm/src/black_box.rs | 20 --- .../brillig/brillig_gen/brillig_black_box.rs | 19 --- .../noirc_evaluator/src/brillig/brillig_ir.rs | 7 - .../src/brillig/brillig_ir/debug_show.rs | 9 -- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 25 ---- .../ssa/acir_gen/acir_ir/generated_acir.rs | 13 +- .../src/ssa/ir/instruction/call.rs | 2 +- .../src/ssa/ir/instruction/call/blackbox.rs | 14 +- noir/noir-repo/noir_stdlib/src/hash/mod.nr | 14 -- noir/noir-repo/tooling/lsp/src/solver.rs | 8 - .../tooling/profiler/src/opcode_formatter.rs | 2 - 40 files changed, 17 insertions(+), 620 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp delete mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp delete mode 100644 noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index e441f2cf8ae..f0888b22a46 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -1125,31 +1125,6 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B ..Default::default() }); } - // Temporary while we dont have efficient noir implementations (again) - BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { - let input_offset = inputs.pointer.to_usize(); - let input_size_offset = inputs.size.to_usize(); - let index_offset = domain_separator.to_usize(); - let output_offset = output.pointer.to_usize(); - avm_instrs.push(AvmInstruction { - opcode: AvmOpcode::PEDERSENCOMMITMENT, - indirect: Some( - AddressingModeBuilder::default() - .indirect_operand(&inputs.pointer) - .indirect_operand(&output.pointer) - .direct_operand(&inputs.size) - .direct_operand(domain_separator) - .build(), - ), - operands: vec![ - AvmOperand::U32 { value: input_offset as u32 }, - AvmOperand::U32 { value: output_offset as u32 }, - AvmOperand::U32 { value: input_size_offset as u32 }, - AvmOperand::U32 { value: index_offset as u32 }, - ], - ..Default::default() - }); - } _ => panic!("Transpiler doesn't know how to process {:?}", operation), } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index eebb644e390..7b08678ad71 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -156,14 +156,6 @@ void build_constraints(Builder& builder, constraint_system.original_opcode_indices.keccak_permutations[i]); } - // Add pedersen constraints - for (size_t i = 0; i < constraint_system.pedersen_constraints.size(); ++i) { - const auto& constraint = constraint_system.pedersen_constraints.at(i); - create_pedersen_constraint(builder, constraint); - gate_counter.track_diff(constraint_system.gates_per_opcode, - constraint_system.original_opcode_indices.pedersen_constraints.at(i)); - } - for (size_t i = 0; i < constraint_system.poseidon2_constraints.size(); ++i) { const auto& constraint = constraint_system.poseidon2_constraints.at(i); create_poseidon2_permutations(builder, constraint); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 29046a8d1ab..79a750b2e89 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -19,7 +19,6 @@ #include "keccak_constraint.hpp" #include "logic_constraint.hpp" #include "multi_scalar_mul.hpp" -#include "pedersen.hpp" #include "poseidon2_constraint.hpp" #include "range_constraint.hpp" #include "recursion_constraint.hpp" @@ -48,7 +47,6 @@ struct AcirFormatOriginalOpcodeIndices { std::vector blake2s_constraints; std::vector blake3_constraints; std::vector keccak_permutations; - std::vector pedersen_constraints; std::vector poseidon2_constraints; std::vector multi_scalar_mul_constraints; std::vector ec_add_constraints; @@ -94,7 +92,6 @@ struct AcirFormat { std::vector blake2s_constraints; std::vector blake3_constraints; std::vector keccak_permutations; - std::vector pedersen_constraints; std::vector poseidon2_constraints; std::vector multi_scalar_mul_constraints; std::vector ec_add_constraints; @@ -144,7 +141,6 @@ struct AcirFormat { blake2s_constraints, blake3_constraints, keccak_permutations, - pedersen_constraints, poseidon2_constraints, multi_scalar_mul_constraints, ec_add_constraints, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 0c2855652c8..199bfac3ca6 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -52,7 +52,6 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -174,7 +173,6 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -255,7 +253,6 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -362,7 +359,6 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -421,6 +417,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } + TEST_F(AcirFormatTests, TestKeccakPermutation) { Keccakf1600 @@ -471,7 +468,6 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = { keccak_permutation }, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -546,7 +542,6 @@ TEST_F(AcirFormatTests, TestCollectsGateCounts) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -673,7 +668,6 @@ TEST_F(AcirFormatTests, TestBigAdd) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp index 0e1471506d7..fdf5a363532 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp @@ -13,7 +13,6 @@ acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indice .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -64,9 +63,6 @@ void mock_opcode_indices(acir_format::AcirFormat& constraint_system) for (size_t i = 0; i < constraint_system.keccak_permutations.size(); i++) { constraint_system.original_opcode_indices.keccak_permutations.push_back(current_opcode++); } - for (size_t i = 0; i < constraint_system.pedersen_constraints.size(); i++) { - constraint_system.original_opcode_indices.pedersen_constraints.push_back(current_opcode++); - } for (size_t i = 0; i < constraint_system.poseidon2_constraints.size(); i++) { constraint_system.original_opcode_indices.poseidon2_constraints.push_back(current_opcode++); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index cb6ff105e1c..bf7eb2dd8de 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -572,16 +572,6 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, }); af.original_opcode_indices.schnorr_constraints.push_back(opcode_index); af.constrained_witness.insert(af.schnorr_constraints.back().result); - } else if constexpr (std::is_same_v) { - af.pedersen_constraints.push_back(PedersenConstraint{ - .scalars = map(arg.inputs, [](auto& e) { return get_witness_from_function_input(e); }), - .hash_index = arg.domain_separator, - .result_x = arg.outputs[0].value, - .result_y = arg.outputs[1].value, - }); - af.constrained_witness.insert(af.pedersen_constraints.back().result_x); - af.constrained_witness.insert(af.pedersen_constraints.back().result_y); - af.original_opcode_indices.pedersen_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.ecdsa_k1_constraints.push_back(EcdsaSecp256k1Constraint{ .hashed_message = diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp index 029af4828bf..295b66cdba7 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp @@ -185,7 +185,6 @@ TEST_F(BigIntTests, TestBigIntConstraintMultiple) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -259,7 +258,6 @@ TEST_F(BigIntTests, TestBigIntConstraintSimple) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -317,7 +315,6 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -380,7 +377,6 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse2) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -464,7 +460,6 @@ TEST_F(BigIntTests, TestBigIntDIV) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index e9688e613b9..8aec43aa612 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -153,7 +153,6 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -205,7 +204,6 @@ TEST_F(MegaHonk, Databus) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -312,7 +310,6 @@ TEST_F(MegaHonk, DatabusReturn) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp index da3797330e4..193388efb3b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp @@ -75,7 +75,6 @@ TEST_F(EcOperations, TestECOperations) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = { ec_add_constraint }, @@ -212,7 +211,6 @@ TEST_F(EcOperations, TestECMultiScalarMul) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = { msm_constrain }, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index d035aae8cec..041c925122a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -107,7 +107,6 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -162,7 +161,6 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -212,7 +210,6 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index d86dab894e2..b6d29989d83 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -141,7 +141,6 @@ TEST(ECDSASecp256r1, test_hardcoded) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -198,7 +197,6 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -253,7 +251,6 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -304,7 +301,6 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp index 467c1b4c4c4..3914ef1c38b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp @@ -103,7 +103,6 @@ class AcirHonkRecursionConstraint : public ::testing::Test { .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.test.cpp index 6326d7a7d3a..bc8dd7d8c90 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.test.cpp @@ -75,7 +75,6 @@ TEST_F(MSMTests, TestMSM) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = { msm_constrain }, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp deleted file mode 100644 index 183ef5e6951..00000000000 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "pedersen.hpp" -#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" -#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" -#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" -#include "barretenberg/stdlib/primitives/field/field.hpp" - -namespace acir_format { - -using namespace bb; - -template void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input) -{ - using field_ct = stdlib::field_t; - - std::vector scalars; - - for (const auto& scalar : input.scalars) { - // convert input indices to field_ct - field_ct scalar_as_field = field_ct::from_witness_index(&builder, scalar); - scalars.push_back(scalar_as_field); - } - - auto point = stdlib::pedersen_commitment::commit(scalars, input.hash_index); - - builder.assert_equal(point.x.witness_index, input.result_x); - builder.assert_equal(point.y.witness_index, input.result_y); -} - -template void create_pedersen_constraint(UltraCircuitBuilder& builder, - const PedersenConstraint& input); -template void create_pedersen_constraint(MegaCircuitBuilder& builder, - const PedersenConstraint& input); -} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp deleted file mode 100644 index dcef6bfa1d8..00000000000 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "barretenberg/common/serialize.hpp" -#include -#include - -namespace acir_format { - -// P = xG + bH -struct PedersenConstraint { - std::vector scalars; - uint32_t hash_index; - - uint32_t result_x; - uint32_t result_y; - - friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default; -}; - -template void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input); - -template inline void read(B& buf, PedersenConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.scalars); - read(buf, constraint.hash_index); - read(buf, constraint.result_x); - read(buf, constraint.result_y); -} - -template inline void write(B& buf, PedersenConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.scalars); - write(buf, constraint.hash_index); - write(buf, constraint.result_x); - write(buf, constraint.result_y); -} - -} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp index 14a05a2f358..9c07431abe8 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp @@ -55,7 +55,6 @@ TEST_F(Poseidon2Tests, TestPoseidon2Permutation) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = { poseidon2_constraint }, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 3446cfd5021..301bd915005 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -100,7 +100,6 @@ Builder create_inner_circuit() .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, @@ -262,7 +261,6 @@ Builder create_outer_circuit(std::vector& inner_circuits) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index f4bacef6c0c..7fc66d2af01 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -330,16 +330,6 @@ struct BlackBoxOp { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct PedersenCommitment { - Program::HeapVector inputs; - Program::MemoryAddress domain_separator; - Program::HeapArray output; - - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); - std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); - }; - struct MultiScalarMul { Program::HeapVector points; Program::HeapVector scalars; @@ -461,7 +451,6 @@ struct BlackBoxOp { EcdsaSecp256k1, EcdsaSecp256r1, SchnorrVerify, - PedersenCommitment, MultiScalarMul, EmbeddedCurveAdd, BigIntAdd, @@ -879,16 +868,6 @@ struct BlackBoxFuncCall { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct PedersenCommitment { - std::vector inputs; - uint32_t domain_separator; - std::array outputs; - - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); - std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); - }; - struct EcdsaSecp256k1 { std::array public_key_x; std::array public_key_y; @@ -1040,7 +1019,6 @@ struct BlackBoxFuncCall { Blake2s, Blake3, SchnorrVerify, - PedersenCommitment, EcdsaSecp256k1, EcdsaSecp256r1, MultiScalarMul, @@ -3041,64 +3019,6 @@ Program::BlackBoxFuncCall::SchnorrVerify serde::Deserializable BlackBoxFuncCall::PedersenCommitment::bincodeSerialize() const -{ - auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); - return std::move(serializer).bytes(); -} - -inline BlackBoxFuncCall::PedersenCommitment BlackBoxFuncCall::PedersenCommitment::bincodeDeserialize( - std::vector input) -{ - auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); - if (deserializer.get_buffer_offset() < input.size()) { - throw_or_abort("Some input bytes were not read"); - } - return value; -} - -} // end of namespace Program - -template <> -template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::PedersenCommitment& obj, Serializer& serializer) -{ - serde::Serializable::serialize(obj.inputs, serializer); - serde::Serializable::serialize(obj.domain_separator, serializer); - serde::Serializable::serialize(obj.outputs, serializer); -} - -template <> -template -Program::BlackBoxFuncCall::PedersenCommitment serde::Deserializable< - Program::BlackBoxFuncCall::PedersenCommitment>::deserialize(Deserializer& deserializer) -{ - Program::BlackBoxFuncCall::PedersenCommitment obj; - obj.inputs = serde::Deserializable::deserialize(deserializer); - obj.domain_separator = serde::Deserializable::deserialize(deserializer); - obj.outputs = serde::Deserializable::deserialize(deserializer); - return obj; -} - -namespace Program { - inline bool operator==(const BlackBoxFuncCall::EcdsaSecp256k1& lhs, const BlackBoxFuncCall::EcdsaSecp256k1& rhs) { if (!(lhs.public_key_x == rhs.public_key_x)) { @@ -4392,63 +4312,6 @@ Program::BlackBoxOp::SchnorrVerify serde::Deserializable BlackBoxOp::PedersenCommitment::bincodeSerialize() const -{ - auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); - return std::move(serializer).bytes(); -} - -inline BlackBoxOp::PedersenCommitment BlackBoxOp::PedersenCommitment::bincodeDeserialize(std::vector input) -{ - auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); - if (deserializer.get_buffer_offset() < input.size()) { - throw_or_abort("Some input bytes were not read"); - } - return value; -} - -} // end of namespace Program - -template <> -template -void serde::Serializable::serialize( - const Program::BlackBoxOp::PedersenCommitment& obj, Serializer& serializer) -{ - serde::Serializable::serialize(obj.inputs, serializer); - serde::Serializable::serialize(obj.domain_separator, serializer); - serde::Serializable::serialize(obj.output, serializer); -} - -template <> -template -Program::BlackBoxOp::PedersenCommitment serde::Deserializable::deserialize( - Deserializer& deserializer) -{ - Program::BlackBoxOp::PedersenCommitment obj; - obj.inputs = serde::Deserializable::deserialize(deserializer); - obj.domain_separator = serde::Deserializable::deserialize(deserializer); - obj.output = serde::Deserializable::deserialize(deserializer); - return obj; -} - -namespace Program { - inline bool operator==(const BlackBoxOp::MultiScalarMul& lhs, const BlackBoxOp::MultiScalarMul& rhs) { if (!(lhs.points == rhs.points)) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp index e85f5927449..b057ee17493 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp @@ -50,7 +50,6 @@ TEST_F(Sha256Tests, TestSha256Compression) .blake2s_constraints = {}, .blake3_constraints = {}, .keccak_permutations = {}, - .pedersen_constraints = {}, .poseidon2_constraints = {}, .multi_scalar_mul_constraints = {}, .ec_add_constraints = {}, diff --git a/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp b/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp index 6468f8e1732..637ac2ce201 100644 --- a/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp +++ b/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp @@ -330,16 +330,6 @@ namespace Program { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct PedersenCommitment { - Program::HeapVector inputs; - Program::MemoryAddress domain_separator; - Program::HeapArray output; - - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); - std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); - }; - struct MultiScalarMul { Program::HeapVector points; Program::HeapVector scalars; @@ -454,7 +444,7 @@ namespace Program { static ToRadix bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); std::vector bincodeSerialize() const; @@ -840,16 +830,6 @@ namespace Program { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct PedersenCommitment { - std::vector inputs; - uint32_t domain_separator; - std::array outputs; - - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); - std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); - }; - struct EcdsaSecp256k1 { std::array public_key_x; std::array public_key_y; @@ -994,7 +974,7 @@ namespace Program { static Sha256Compression bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; @@ -2716,50 +2696,6 @@ Program::BlackBoxFuncCall::SchnorrVerify serde::Deserializable BlackBoxFuncCall::PedersenCommitment::bincodeSerialize() const { - auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); - return std::move(serializer).bytes(); - } - - inline BlackBoxFuncCall::PedersenCommitment BlackBoxFuncCall::PedersenCommitment::bincodeDeserialize(std::vector input) { - auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); - if (deserializer.get_buffer_offset() < input.size()) { - throw serde::deserialization_error("Some input bytes were not read"); - } - return value; - } - -} // end of namespace Program - -template <> -template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::PedersenCommitment &obj, Serializer &serializer) { - serde::Serializable::serialize(obj.inputs, serializer); - serde::Serializable::serialize(obj.domain_separator, serializer); - serde::Serializable::serialize(obj.outputs, serializer); -} - -template <> -template -Program::BlackBoxFuncCall::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { - Program::BlackBoxFuncCall::PedersenCommitment obj; - obj.inputs = serde::Deserializable::deserialize(deserializer); - obj.domain_separator = serde::Deserializable::deserialize(deserializer); - obj.outputs = serde::Deserializable::deserialize(deserializer); - return obj; -} - namespace Program { inline bool operator==(const BlackBoxFuncCall::EcdsaSecp256k1 &lhs, const BlackBoxFuncCall::EcdsaSecp256k1 &rhs) { @@ -3750,50 +3686,6 @@ Program::BlackBoxOp::SchnorrVerify serde::Deserializable BlackBoxOp::PedersenCommitment::bincodeSerialize() const { - auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); - return std::move(serializer).bytes(); - } - - inline BlackBoxOp::PedersenCommitment BlackBoxOp::PedersenCommitment::bincodeDeserialize(std::vector input) { - auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); - if (deserializer.get_buffer_offset() < input.size()) { - throw serde::deserialization_error("Some input bytes were not read"); - } - return value; - } - -} // end of namespace Program - -template <> -template -void serde::Serializable::serialize(const Program::BlackBoxOp::PedersenCommitment &obj, Serializer &serializer) { - serde::Serializable::serialize(obj.inputs, serializer); - serde::Serializable::serialize(obj.domain_separator, serializer); - serde::Serializable::serialize(obj.output, serializer); -} - -template <> -template -Program::BlackBoxOp::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { - Program::BlackBoxOp::PedersenCommitment obj; - obj.inputs = serde::Deserializable::deserialize(deserializer); - obj.domain_separator = serde::Deserializable::deserialize(deserializer); - obj.output = serde::Deserializable::deserialize(deserializer); - return obj; -} - namespace Program { inline bool operator==(const BlackBoxOp::MultiScalarMul &lhs, const BlackBoxOp::MultiScalarMul &rhs) { diff --git a/noir/noir-repo/acvm-repo/acir/src/circuit/black_box_functions.rs b/noir/noir-repo/acvm-repo/acir/src/circuit/black_box_functions.rs index 4bdce9a2d21..2e5a94f1c50 100644 --- a/noir/noir-repo/acvm-repo/acir/src/circuit/black_box_functions.rs +++ b/noir/noir-repo/acvm-repo/acir/src/circuit/black_box_functions.rs @@ -76,8 +76,6 @@ pub enum BlackBoxFunc { /// /// [grumpkin]: https://hackmd.io/@aztec-network/ByzgNxBfd#2-Grumpkin---A-curve-on-top-of-BN-254-for-SNARK-efficient-group-operations SchnorrVerify, - /// Will be deprecated - PedersenCommitment, /// Verifies a ECDSA signature over the secp256k1 curve. /// - inputs: /// - x coordinate of public key as 32 bytes @@ -220,7 +218,6 @@ impl BlackBoxFunc { BlackBoxFunc::BigIntToLeBytes => "bigint_to_le_bytes", BlackBoxFunc::Poseidon2Permutation => "poseidon2_permutation", BlackBoxFunc::Sha256Compression => "sha256_compression", - BlackBoxFunc::PedersenCommitment => "pedersen_commitment", } } @@ -247,7 +244,6 @@ impl BlackBoxFunc { "bigint_to_le_bytes" => Some(BlackBoxFunc::BigIntToLeBytes), "poseidon2_permutation" => Some(BlackBoxFunc::Poseidon2Permutation), "sha256_compression" => Some(BlackBoxFunc::Sha256Compression), - "pedersen_commitment" => Some(BlackBoxFunc::PedersenCommitment), _ => None, } } diff --git a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs index 4a8a50d4bc5..e06286d179e 100644 --- a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs +++ b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs @@ -117,12 +117,6 @@ pub enum BlackBoxFuncCall { message: Vec>, output: Witness, }, - /// Will be deprecated - PedersenCommitment { - inputs: Vec>, - domain_separator: u32, - outputs: (Witness, Witness), - }, EcdsaSecp256k1 { public_key_x: Box<[FunctionInput; 32]>, public_key_y: Box<[FunctionInput; 32]>, @@ -253,7 +247,6 @@ impl BlackBoxFuncCall { BlackBoxFuncCall::BigIntToLeBytes { .. } => BlackBoxFunc::BigIntToLeBytes, BlackBoxFuncCall::Poseidon2Permutation { .. } => BlackBoxFunc::Poseidon2Permutation, BlackBoxFuncCall::Sha256Compression { .. } => BlackBoxFunc::Sha256Compression, - BlackBoxFuncCall::PedersenCommitment { .. } => BlackBoxFunc::PedersenCommitment, } } @@ -267,7 +260,6 @@ impl BlackBoxFuncCall { | BlackBoxFuncCall::Blake2s { inputs, .. } | BlackBoxFuncCall::Blake3 { inputs, .. } | BlackBoxFuncCall::BigIntFromLeBytes { inputs, .. } - | BlackBoxFuncCall::PedersenCommitment { inputs, .. } | BlackBoxFuncCall::Poseidon2Permutation { inputs, .. } => inputs.to_vec(), BlackBoxFuncCall::Keccakf1600 { inputs, .. } => inputs.to_vec(), @@ -381,7 +373,6 @@ impl BlackBoxFuncCall { | BlackBoxFuncCall::SchnorrVerify { output, .. } | BlackBoxFuncCall::EcdsaSecp256k1 { output, .. } | BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output], - BlackBoxFuncCall::PedersenCommitment { outputs, .. } => vec![outputs.0, outputs.1], BlackBoxFuncCall::MultiScalarMul { outputs, .. } | BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => { vec![outputs.0, outputs.1, outputs.2] @@ -454,10 +445,6 @@ fn get_outputs_string(outputs: &[Witness]) -> String { impl std::fmt::Display for BlackBoxFuncCall { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if matches!(self, BlackBoxFuncCall::PedersenCommitment { .. }) { - return write!(f, "BLACKBOX::Deprecated"); - } - let uppercase_name = self.name().to_uppercase(); write!(f, "BLACKBOX::{uppercase_name} ")?; // INPUTS diff --git a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs index 278857c5a7b..a915cb95d07 100644 --- a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs +++ b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs @@ -91,10 +91,10 @@ fn multi_scalar_mul_circuit() { let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 223, 253, 207, - 27, 41, 45, 88, 9, 15, 167, 78, 205, 233, 196, 112, 50, 116, 228, 233, 8, 213, 193, 66, 46, - 164, 133, 122, 215, 171, 52, 55, 232, 234, 52, 167, 195, 103, 228, 47, 184, 163, 212, 79, - 244, 255, 223, 125, 98, 3, 85, 236, 192, 195, 193, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 77, 9, 14, 0, 32, 8, 202, 171, 227, 255, 255, 109, + 217, 162, 141, 114, 99, 2, 162, 74, 57, 53, 18, 2, 46, 208, 70, 122, 99, 162, 43, 113, 35, + 239, 102, 157, 230, 1, 94, 19, 45, 209, 145, 11, 202, 43, 238, 56, 249, 133, 254, 255, 187, + 79, 45, 204, 84, 220, 246, 193, 0, 0, 0, ]; assert_eq!(bytes, expected_serialization) diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs index 3600a3e30e6..c3b1627ba65 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs @@ -18,7 +18,6 @@ pub(crate) mod bigint; mod embedded_curve_ops; mod hash; mod logic; -mod pedersen; mod range; mod signature; pub(crate) mod utils; @@ -27,7 +26,6 @@ use embedded_curve_ops::{embedded_curve_add, multi_scalar_mul}; // Hash functions should eventually be exposed for external consumers. use hash::{solve_generic_256_hash_opcode, solve_sha_256_permutation_opcode}; use logic::{and, xor}; -use pedersen::pedersen; pub(crate) use range::solve_range_opcode; use signature::{ ecdsa::{secp256k1_prehashed, secp256r1_prehashed}, @@ -120,9 +118,6 @@ pub(crate) fn solve( message, *output, ), - BlackBoxFuncCall::PedersenCommitment { inputs, domain_separator, outputs } => { - pedersen(backend, initial_witness, inputs, *domain_separator, *outputs) - } BlackBoxFuncCall::EcdsaSecp256k1 { public_key_x, public_key_y, diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs deleted file mode 100644 index a85a8abfc9b..00000000000 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs +++ /dev/null @@ -1,29 +0,0 @@ -use acir::{ - circuit::opcodes::FunctionInput, - native_types::{Witness, WitnessMap}, - AcirField, -}; - -use crate::{ - pwg::{input_to_value, insert_value, OpcodeResolutionError}, - BlackBoxFunctionSolver, -}; - -pub(super) fn pedersen( - backend: &impl BlackBoxFunctionSolver, - initial_witness: &mut WitnessMap, - inputs: &[FunctionInput], - domain_separator: u32, - outputs: (Witness, Witness), -) -> Result<(), OpcodeResolutionError> { - let scalars: Result, _> = - inputs.iter().map(|input| input_to_value(initial_witness, *input, false)).collect(); - let scalars: Vec<_> = scalars?.into_iter().collect(); - - let (res_x, res_y) = backend.pedersen_commitment(&scalars, domain_separator)?; - - insert_value(&outputs.0, res_x, initial_witness)?; - insert_value(&outputs.1, res_y, initial_witness)?; - - Ok(()) -} diff --git a/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts b/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts index 69c77a7eaf1..239d5473606 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts +++ b/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts @@ -1,8 +1,8 @@ // See `multi_scalar_mul_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 223, 253, 207, 27, 41, 45, 88, 9, 15, 167, - 78, 205, 233, 196, 112, 50, 116, 228, 233, 8, 213, 193, 66, 46, 164, 133, 122, 215, 171, 52, 55, 232, 234, 52, 167, - 195, 103, 228, 47, 184, 163, 212, 79, 244, 255, 223, 125, 98, 3, 85, 236, 192, 195, 193, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 77, 9, 14, 0, 32, 8, 202, 171, 227, 255, 255, 109, 217, 162, 141, 114, 99, 2, + 162, 74, 57, 53, 18, 2, 46, 208, 70, 122, 99, 162, 43, 113, 35, 239, 102, 157, 230, 1, 94, 19, 45, 209, 145, 11, 202, + 43, 238, 56, 249, 133, 254, 255, 187, 79, 45, 204, 84, 220, 246, 193, 0, 0, 0, ]); export const initialWitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], diff --git a/noir/noir-repo/acvm-repo/blackbox_solver/src/curve_specific_solver.rs b/noir/noir-repo/acvm-repo/blackbox_solver/src/curve_specific_solver.rs index e66cfe8a92a..869017f52ee 100644 --- a/noir/noir-repo/acvm-repo/blackbox_solver/src/curve_specific_solver.rs +++ b/noir/noir-repo/acvm-repo/blackbox_solver/src/curve_specific_solver.rs @@ -14,11 +14,6 @@ pub trait BlackBoxFunctionSolver { signature: &[u8; 64], message: &[u8], ) -> Result; - fn pedersen_commitment( - &self, - inputs: &[F], - domain_separator: u32, - ) -> Result<(F, F), BlackBoxResolutionError>; fn multi_scalar_mul( &self, points: &[F], @@ -62,14 +57,6 @@ impl BlackBoxFunctionSolver for StubbedBlackBoxSolver { ) -> Result { Err(Self::fail(BlackBoxFunc::SchnorrVerify)) } - fn pedersen_commitment( - &self, - _inputs: &[F], - _domain_separator: u32, - ) -> Result<(F, F), BlackBoxResolutionError> { - Err(Self::fail(BlackBoxFunc::PedersenCommitment)) - } - fn multi_scalar_mul( &self, _points: &[F], diff --git a/noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/lib.rs b/noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/lib.rs index 78e6c2b2d10..d74c17a52b5 100644 --- a/noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/lib.rs +++ b/noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/lib.rs @@ -10,7 +10,6 @@ mod pedersen; mod poseidon2; mod schnorr; -use ark_ec::AffineRepr; pub use embedded_curve_ops::{embedded_curve_add, multi_scalar_mul}; pub use generator::generators::derive_generators; pub use poseidon2::{ @@ -44,22 +43,6 @@ impl BlackBoxFunctionSolver for Bn254BlackBoxSolver { )) } - fn pedersen_commitment( - &self, - inputs: &[FieldElement], - domain_separator: u32, - ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { - let inputs: Vec = inputs.iter().map(|input| input.into_repr()).collect(); - let result = pedersen::commitment::commit_native_with_index(&inputs, domain_separator); - let result = if let Some((x, y)) = result.xy() { - (FieldElement::from_repr(*x), FieldElement::from_repr(*y)) - } else { - (FieldElement::from(0_u128), FieldElement::from(0_u128)) - }; - - Ok(result) - } - fn multi_scalar_mul( &self, points: &[FieldElement], diff --git a/noir/noir-repo/acvm-repo/brillig/src/black_box.rs b/noir/noir-repo/acvm-repo/brillig/src/black_box.rs index a6721461d6a..b61c2272587 100644 --- a/noir/noir-repo/acvm-repo/brillig/src/black_box.rs +++ b/noir/noir-repo/acvm-repo/brillig/src/black_box.rs @@ -51,12 +51,6 @@ pub enum BlackBoxOp { signature: HeapVector, result: MemoryAddress, }, - /// Will be deprecated - PedersenCommitment { - inputs: HeapVector, - domain_separator: MemoryAddress, - output: HeapArray, - }, /// Performs multi scalar multiplication over the embedded curve. MultiScalarMul { points: HeapVector, diff --git a/noir/noir-repo/acvm-repo/brillig_vm/src/black_box.rs b/noir/noir-repo/acvm-repo/brillig_vm/src/black_box.rs index 88bec2eebd8..4201d2ddba2 100644 --- a/noir/noir-repo/acvm-repo/brillig_vm/src/black_box.rs +++ b/noir/noir-repo/acvm-repo/brillig_vm/src/black_box.rs @@ -221,25 +221,6 @@ pub(crate) fn evaluate_black_box ); Ok(()) } - BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { - let inputs: Vec = read_heap_vector(memory, inputs) - .iter() - .map(|x| *x.extract_field().unwrap()) - .collect(); - let domain_separator: u32 = - memory.read(*domain_separator).try_into().map_err(|_| { - BlackBoxResolutionError::Failed( - BlackBoxFunc::PedersenCommitment, - "Invalid separator length".to_string(), - ) - })?; - let (x, y) = solver.pedersen_commitment(&inputs, domain_separator)?; - memory.write_slice( - memory.read_ref(output.pointer), - &[MemoryValue::new_field(x), MemoryValue::new_field(y)], - ); - Ok(()) - } BlackBoxOp::BigIntAdd { lhs, rhs, output } => { let lhs = memory.read(*lhs).try_into().unwrap(); let rhs = memory.read(*rhs).try_into().unwrap(); @@ -439,7 +420,6 @@ fn black_box_function_from_op(op: &BlackBoxOp) -> BlackBoxFunc { BlackBoxOp::BigIntToLeBytes { .. } => BlackBoxFunc::BigIntToLeBytes, BlackBoxOp::Poseidon2Permutation { .. } => BlackBoxFunc::Poseidon2Permutation, BlackBoxOp::Sha256Compression { .. } => BlackBoxFunc::Sha256Compression, - BlackBoxOp::PedersenCommitment { .. } => BlackBoxFunc::PedersenCommitment, BlackBoxOp::ToRadix { .. } => unreachable!("ToRadix is not an ACIR BlackBoxFunc"), } } diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index e5a5c0ea9b4..10c0e8b8e8c 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -141,25 +141,6 @@ pub(crate) fn convert_black_box_call { - if let ( - [message, BrilligVariable::SingleAddr(domain_separator)], - [BrilligVariable::BrilligArray(result_array)], - ) = (function_arguments, function_results) - { - let inputs = convert_array_or_vector(brillig_context, *message, bb_func); - let output = brillig_context.codegen_brillig_array_to_heap_array(*result_array); - brillig_context.black_box_op_instruction(BlackBoxOp::PedersenCommitment { - inputs, - domain_separator: domain_separator.address, - output, - }); - brillig_context.deallocate_heap_vector(inputs); - brillig_context.deallocate_heap_array(output); - } else { - unreachable!("ICE: Pedersen expects one array argument, a register for the domain separator, and one array result") - } - } BlackBoxFunc::SchnorrVerify => { if let ( [BrilligVariable::SingleAddr(public_key_x), BrilligVariable::SingleAddr(public_key_y), signature, message], diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs index 38c924772d1..4964ff27f60 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs @@ -173,13 +173,6 @@ pub(crate) mod tests { ) -> Result { Ok(true) } - fn pedersen_commitment( - &self, - _inputs: &[FieldElement], - _domain_separator: u32, - ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { - Ok((2_u128.into(), 3_u128.into())) - } fn multi_scalar_mul( &self, _points: &[FieldElement], diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs index effd13c569e..7597da2be05 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs @@ -335,15 +335,6 @@ impl DebugShow { result ); } - BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { - debug_println!( - self.enable_debug_trace, - " PEDERSEN {} {} -> {}", - inputs, - domain_separator, - output - ); - } BlackBoxOp::SchnorrVerify { public_key_x, public_key_y, diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index f2c5821e118..db08b906185 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1286,31 +1286,6 @@ impl AcirContext { ) -> Result, RuntimeError> { // Separate out any arguments that should be constants let (constant_inputs, constant_outputs) = match name { - BlackBoxFunc::PedersenCommitment => { - // The last argument of pedersen is the domain separator, which must be a constant - let domain_var = match inputs.pop() { - Some(domain_var) => domain_var.into_var()?, - None => { - return Err(RuntimeError::InternalError(InternalError::MissingArg { - name: "pedersen call".to_string(), - arg: "domain separator".to_string(), - call_stack: self.get_call_stack(), - })) - } - }; - - let domain_constant = match self.vars[&domain_var].as_constant() { - Some(domain_constant) => domain_constant, - None => { - return Err(RuntimeError::InternalError(InternalError::NotAConstant { - name: "domain separator".to_string(), - call_stack: self.get_call_stack(), - })) - } - }; - - (vec![*domain_constant], Vec::new()) - } BlackBoxFunc::Poseidon2Permutation => { // The last argument is the state length, which must be a constant let state_len = match inputs.pop() { diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index dd65446e9b9..01fcaef9042 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -225,11 +225,6 @@ impl GeneratedAcir { output: outputs[0], } } - BlackBoxFunc::PedersenCommitment => BlackBoxFuncCall::PedersenCommitment { - inputs: inputs[0].clone(), - outputs: (outputs[0], outputs[1]), - domain_separator: constant_inputs[0].to_u128() as u32, - }, BlackBoxFunc::EcdsaSecp256k1 => { BlackBoxFuncCall::EcdsaSecp256k1 { // 32 bytes for each public key co-ordinate @@ -635,10 +630,7 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { // All of the hash/cipher methods will take in a // variable number of inputs. - BlackBoxFunc::AES128Encrypt - | BlackBoxFunc::Blake2s - | BlackBoxFunc::Blake3 - | BlackBoxFunc::PedersenCommitment => None, + BlackBoxFunc::AES128Encrypt | BlackBoxFunc::Blake2s | BlackBoxFunc::Blake3 => None, BlackBoxFunc::Keccakf1600 => Some(25), // The permutation takes a fixed number of inputs, but the inputs length depends on the proving system implementation. @@ -694,9 +686,6 @@ fn black_box_expected_output_size(name: BlackBoxFunc) -> Option { BlackBoxFunc::Sha256Compression => Some(8), - // Pedersen commitment returns a point - BlackBoxFunc::PedersenCommitment => Some(2), - // Can only apply a range constraint to one // witness at a time. BlackBoxFunc::RANGE => Some(0), diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs index dfda675f439..3c931f8cada 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs @@ -552,7 +552,7 @@ fn simplify_black_box_func( acvm::blackbox_solver::ecdsa_secp256r1_verify, ), - BlackBoxFunc::PedersenCommitment | BlackBoxFunc::MultiScalarMul => SimplifyResult::None, + BlackBoxFunc::MultiScalarMul => SimplifyResult::None, BlackBoxFunc::EmbeddedCurveAdd => blackbox::simplify_ec_add(dfg, solver, arguments), BlackBoxFunc::SchnorrVerify => blackbox::simplify_schnorr_verify(dfg, solver, arguments), diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs index 7789b212e58..3881646d5e4 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use acvm::{acir::AcirField, BlackBoxFunctionSolver, BlackBoxResolutionError, FieldElement}; use iter_extended::vecmap; @@ -41,13 +39,11 @@ pub(super) fn simplify_ec_add( return SimplifyResult::None; }; - let result_x = dfg.make_constant(result_x, Type::field()); - let result_y = dfg.make_constant(result_y, Type::field()); - let result_is_infinity = dfg.make_constant(result_is_infinity, Type::bool()); - - let typ = Type::Array(Arc::new(vec![Type::field()]), 3); - let result_array = - dfg.make_array(im::vector![result_x, result_y, result_is_infinity], typ); + let result_array = make_constant_array( + dfg, + vec![result_x, result_y, result_is_infinity], + Type::field(), + ); SimplifyResult::SimplifiedTo(result_array) } diff --git a/noir/noir-repo/noir_stdlib/src/hash/mod.nr b/noir/noir-repo/noir_stdlib/src/hash/mod.nr index f41bcf830d5..7cd4b8e292e 100644 --- a/noir/noir-repo/noir_stdlib/src/hash/mod.nr +++ b/noir/noir-repo/noir_stdlib/src/hash/mod.nr @@ -34,16 +34,6 @@ pub fn pedersen_commitment(input: [Field; N]) -> EmbeddedCurvePoint #[inline_always] pub fn pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> EmbeddedCurvePoint { - let value = __pedersen_commitment_with_separator(input, separator); - if (value[0] == 0) & (value[1] == 0) { - EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true } - } else { - EmbeddedCurvePoint { x: value[0], y: value[1], is_infinite: false } - } -} - -#[no_predicates] -fn pedersen_commitment_with_separator_noir(input: [Field; N], separator: u32) -> EmbeddedCurvePoint { let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N]; for i in 0..N { // we use the unsafe version because the multi_scalar_mul will constrain the scalars. @@ -78,10 +68,6 @@ pub fn pedersen_hash_with_separator(input: [Field; N], separator: u3 multi_scalar_mul_slice(vec_generators.slice, scalars.slice)[0] } -#[foreign(pedersen_commitment)] -fn __pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> [Field; 2] {} - -#[inline_always] #[field(bn254)] pub fn derive_generators(domain_separator_bytes: [u8; M], starting_index: u32) -> [EmbeddedCurvePoint; N] { crate::assert_constant(domain_separator_bytes); diff --git a/noir/noir-repo/tooling/lsp/src/solver.rs b/noir/noir-repo/tooling/lsp/src/solver.rs index e379ca92e4a..3c2d7499880 100644 --- a/noir/noir-repo/tooling/lsp/src/solver.rs +++ b/noir/noir-repo/tooling/lsp/src/solver.rs @@ -16,14 +16,6 @@ impl BlackBoxFunctionSolver for WrapperSolver { self.0.schnorr_verify(public_key_x, public_key_y, signature, message) } - fn pedersen_commitment( - &self, - inputs: &[acvm::FieldElement], - domain_separator: u32, - ) -> Result<(acvm::FieldElement, acvm::FieldElement), acvm::BlackBoxResolutionError> { - self.0.pedersen_commitment(inputs, domain_separator) - } - fn multi_scalar_mul( &self, points: &[acvm::FieldElement], diff --git a/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs b/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs index 6539a185c47..68057b6d86f 100644 --- a/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs +++ b/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs @@ -17,7 +17,6 @@ fn format_blackbox_function(call: &BlackBoxFuncCall) -> String { BlackBoxFuncCall::Blake2s { .. } => "blake2s".to_string(), BlackBoxFuncCall::Blake3 { .. } => "blake3".to_string(), BlackBoxFuncCall::SchnorrVerify { .. } => "schnorr_verify".to_string(), - BlackBoxFuncCall::PedersenCommitment { .. } => "pedersen_commitment".to_string(), BlackBoxFuncCall::EcdsaSecp256k1 { .. } => "ecdsa_secp256k1".to_string(), BlackBoxFuncCall::EcdsaSecp256r1 { .. } => "ecdsa_secp256r1".to_string(), BlackBoxFuncCall::MultiScalarMul { .. } => "multi_scalar_mul".to_string(), @@ -41,7 +40,6 @@ fn format_blackbox_op(call: &BlackBoxOp) -> String { BlackBoxOp::Blake2s { .. } => "blake2s".to_string(), BlackBoxOp::Blake3 { .. } => "blake3".to_string(), BlackBoxOp::SchnorrVerify { .. } => "schnorr_verify".to_string(), - BlackBoxOp::PedersenCommitment { .. } => "pedersen_commitment".to_string(), BlackBoxOp::EcdsaSecp256k1 { .. } => "ecdsa_secp256k1".to_string(), BlackBoxOp::EcdsaSecp256r1 { .. } => "ecdsa_secp256r1".to_string(), BlackBoxOp::MultiScalarMul { .. } => "multi_scalar_mul".to_string(),