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

chore!: remove pedersen hash opcode #9245

Merged
merged 16 commits into from
Oct 18, 2024
26 changes: 0 additions & 26 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,32 +989,6 @@ fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &B
..Default::default()
});
}
BlackBoxOp::PedersenHash { inputs, domain_separator, output } => {
let message_offset = inputs.pointer.to_usize();
let message_size_offset = inputs.size.to_usize();

let index_offset = domain_separator.to_usize();
let dest_offset = output.to_usize();

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::PEDERSEN,
indirect: Some(
AddressingModeBuilder::default()
.direct_operand(domain_separator)
.direct_operand(output)
.indirect_operand(&inputs.pointer)
.direct_operand(&inputs.size)
.build(),
),
operands: vec![
AvmOperand::U32 { value: index_offset as u32 },
AvmOperand::U32 { value: dest_offset as u32 },
AvmOperand::U32 { value: message_offset as u32 },
AvmOperand::U32 { value: message_size_offset as u32 },
],
..Default::default()
});
}
BlackBoxOp::Poseidon2Permutation {
message,
output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ void build_constraints(Builder& builder,
constraint_system.original_opcode_indices.pedersen_constraints.at(i));
}

for (size_t i = 0; i < constraint_system.pedersen_hash_constraints.size(); ++i) {
const auto& constraint = constraint_system.pedersen_hash_constraints.at(i);
create_pedersen_hash_constraint(builder, constraint);
gate_counter.track_diff(constraint_system.gates_per_opcode,
constraint_system.original_opcode_indices.pedersen_hash_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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct AcirFormatOriginalOpcodeIndices {
std::vector<size_t> blake3_constraints;
std::vector<size_t> keccak_permutations;
std::vector<size_t> pedersen_constraints;
std::vector<size_t> pedersen_hash_constraints;
std::vector<size_t> poseidon2_constraints;
std::vector<size_t> multi_scalar_mul_constraints;
std::vector<size_t> ec_add_constraints;
Expand Down Expand Up @@ -96,7 +95,6 @@ struct AcirFormat {
std::vector<Blake3Constraint> blake3_constraints;
std::vector<Keccakf1600> keccak_permutations;
std::vector<PedersenConstraint> pedersen_constraints;
std::vector<PedersenHashConstraint> pedersen_hash_constraints;
std::vector<Poseidon2Constraint> poseidon2_constraints;
std::vector<MultiScalarMul> multi_scalar_mul_constraints;
std::vector<EcAdd> ec_add_constraints;
Expand Down Expand Up @@ -147,7 +145,6 @@ struct AcirFormat {
blake3_constraints,
keccak_permutations,
pedersen_constraints,
pedersen_hash_constraints,
poseidon2_constraints,
multi_scalar_mul_constraints,
ec_add_constraints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -176,7 +175,6 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -258,7 +256,6 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -366,7 +363,6 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -425,7 +421,6 @@ 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
Expand Down Expand Up @@ -477,7 +472,6 @@ TEST_F(AcirFormatTests, TestKeccakPermutation)
.blake3_constraints = {},
.keccak_permutations = { keccak_permutation },
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -553,7 +547,6 @@ TEST_F(AcirFormatTests, TestCollectsGateCounts)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -681,7 +674,6 @@ TEST_F(AcirFormatTests, TestBigAdd)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indice
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -68,9 +67,6 @@ void mock_opcode_indices(acir_format::AcirFormat& constraint_system)
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.pedersen_hash_constraints.size(); i++) {
constraint_system.original_opcode_indices.pedersen_hash_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++);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,6 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg,
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<T, Program::BlackBoxFuncCall::PedersenHash>) {
af.pedersen_hash_constraints.push_back(PedersenHashConstraint{
.scalars = map(arg.inputs, [](auto& e) { return get_witness_from_function_input(e); }),
.hash_index = arg.domain_separator,
.result = arg.output.value,
});
af.constrained_witness.insert(af.pedersen_hash_constraints.back().result);
af.original_opcode_indices.pedersen_hash_constraints.push_back(opcode_index);
} else if constexpr (std::is_same_v<T, Program::BlackBoxFuncCall::EcdsaSecp256k1>) {
af.ecdsa_k1_constraints.push_back(EcdsaSecp256k1Constraint{
.hashed_message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ TEST_F(BigIntTests, TestBigIntConstraintMultiple)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -261,7 +260,6 @@ TEST_F(BigIntTests, TestBigIntConstraintSimple)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -320,7 +318,6 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -384,7 +381,6 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse2)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -469,7 +465,6 @@ TEST_F(BigIntTests, TestBigIntDIV)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -207,7 +206,6 @@ TEST_F(MegaHonk, Databus)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -315,7 +313,6 @@ TEST_F(MegaHonk, DatabusReturn)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ TEST_F(EcOperations, TestECOperations)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = { ec_add_constraint },
Expand Down Expand Up @@ -214,7 +213,6 @@ TEST_F(EcOperations, TestECMultiScalarMul)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = { msm_constrain },
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -164,7 +163,6 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -215,7 +213,6 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ TEST(ECDSASecp256r1, test_hardcoded)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -200,7 +199,6 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -256,7 +254,6 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -308,7 +305,6 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class AcirHonkRecursionConstraint : public ::testing::Test {
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ TEST_F(MSMTests, TestMSM)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = { msm_constrain },
.ec_add_constraints = {},
Expand Down
22 changes: 0 additions & 22 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,8 @@ template <typename Builder> void create_pedersen_constraint(Builder& builder, co
builder.assert_equal(point.y.witness_index, input.result_y);
}

template <typename Builder> void create_pedersen_hash_constraint(Builder& builder, const PedersenHashConstraint& input)
{
using field_ct = stdlib::field_t<Builder>;

std::vector<field_ct> 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 result = stdlib::pedersen_hash<Builder>::hash(scalars, input.hash_index);

builder.assert_equal(result.witness_index, input.result);
}

template void create_pedersen_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder,
const PedersenConstraint& input);
template void create_pedersen_hash_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder,
const PedersenHashConstraint& input);
template void create_pedersen_constraint<MegaCircuitBuilder>(MegaCircuitBuilder& builder,
const PedersenConstraint& input);
template void create_pedersen_hash_constraint<MegaCircuitBuilder>(MegaCircuitBuilder& builder,
const PedersenHashConstraint& input);

} // namespace acir_format
10 changes: 0 additions & 10 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ struct PedersenConstraint {
friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default;
};

struct PedersenHashConstraint {
std::vector<uint32_t> scalars;
uint32_t hash_index;

uint32_t result;

friend bool operator==(PedersenHashConstraint const& lhs, PedersenHashConstraint const& rhs) = default;
};

template <typename Builder> void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input);
template <typename Builder> void create_pedersen_hash_constraint(Builder& builder, const PedersenHashConstraint& input);

template <typename B> inline void read(B& buf, PedersenConstraint& constraint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ TEST_F(Poseidon2Tests, TestPoseidon2Permutation)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = { poseidon2_constraint },
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Builder create_inner_circuit()
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down Expand Up @@ -264,7 +263,6 @@ Builder create_outer_circuit(std::vector<Builder>& inner_circuits)
.blake3_constraints = {},
.keccak_permutations = {},
.pedersen_constraints = {},
.pedersen_hash_constraints = {},
.poseidon2_constraints = {},
.multi_scalar_mul_constraints = {},
.ec_add_constraints = {},
Expand Down
Loading
Loading