mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-02-12 09:53:09 +00:00
Add HashGate constant type
This commit is contained in:
parent
3534018fec
commit
5488be2acd
@ -2,6 +2,7 @@
|
||||
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field_types::RichField;
|
||||
use crate::gates::poseidon::PoseidonGate;
|
||||
use crate::hash::hash_types::{HashOut, HashOutTarget};
|
||||
use crate::iop::target::Target;
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
@ -11,6 +12,7 @@ pub(crate) const SPONGE_CAPACITY: usize = 4;
|
||||
pub(crate) const SPONGE_WIDTH: usize = SPONGE_RATE + SPONGE_CAPACITY;
|
||||
|
||||
pub(crate) const HASH_FAMILY: HashFamily = HashFamily::Poseidon;
|
||||
pub(crate) type HashGate<F, const D: usize, const W: usize> = PoseidonGate<F, D, W>;
|
||||
|
||||
pub(crate) enum HashFamily {
|
||||
GMiMC,
|
||||
|
||||
@ -6,9 +6,8 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field_types::{Field, RichField};
|
||||
use crate::gates::gmimc::GMiMCGate;
|
||||
use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget};
|
||||
use crate::hash::hashing::{compress, hash_or_noop};
|
||||
use crate::hash::hashing::{compress, hash_or_noop, HashGate};
|
||||
use crate::hash::merkle_tree::MerkleCap;
|
||||
use crate::iop::target::{BoolTarget, Target};
|
||||
use crate::iop::wire::Wire;
|
||||
@ -107,10 +106,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let mut state: HashOutTarget = self.hash_or_noop(leaf_data);
|
||||
|
||||
for (&bit, &sibling) in leaf_index_bits.iter().zip(&proof.siblings) {
|
||||
let gate_type = GMiMCGate::<F, D, 12>::new();
|
||||
let gate_type = HashGate::<F, D, 12>::new();
|
||||
let gate = self.add_gate(gate_type, vec![]);
|
||||
|
||||
let swap_wire = GMiMCGate::<F, D, 12>::WIRE_SWAP;
|
||||
let swap_wire = HashGate::<F, D, 12>::WIRE_SWAP;
|
||||
let swap_wire = Target::Wire(Wire {
|
||||
gate,
|
||||
input: swap_wire,
|
||||
@ -121,7 +120,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.map(|i| {
|
||||
Target::Wire(Wire {
|
||||
gate,
|
||||
input: GMiMCGate::<F, D, 12>::wire_input(i),
|
||||
input: HashGate::<F, D, 12>::wire_input(i),
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -137,7 +136,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.map(|i| {
|
||||
Target::Wire(Wire {
|
||||
gate,
|
||||
input: GMiMCGate::<F, D, 12>::wire_output(i),
|
||||
input: HashGate::<F, D, 12>::wire_output(i),
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
|
||||
@ -545,10 +545,7 @@ where
|
||||
x: ExtensionTarget<D>,
|
||||
) -> ExtensionTarget<D> {
|
||||
// x |--> x^7
|
||||
let x2 = builder.mul_extension(x, x);
|
||||
let x4 = builder.mul_extension(x2, x2);
|
||||
let x3 = builder.mul_extension(x, x2);
|
||||
builder.mul_extension(x3, x4)
|
||||
builder.exp_u64_extension(x, 7)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user