add initial MerkleTree implementation (#13)

Add initial MerkleTree implementation, which is a wrapper on top of
Plonky2's MerkleTree, with the idea that the future iteration will
replace it by the MerkleTree specified at
https://0xparc.github.io/pod2/merkletree.html .
This commit is contained in:
arnaucube 2025-02-03 18:03:45 +01:00 committed by GitHub
parent bf2fa090a3
commit 5b455acbd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 194 additions and 5 deletions

View file

@ -2,13 +2,19 @@ use hex::{FromHex, FromHexError};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::{Field, PrimeField64};
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::plonk::config::Hasher;
use plonky2::plonk::config::{Hasher, PoseidonGoldilocksConfig};
use std::cmp::Ordering;
use std::fmt;
pub mod backend;
pub mod frontend;
pub mod merkletree;
pub type F = GoldilocksField;
/// C is the Plonky2 config used in POD2 to work with Plonky2 recursion.
pub type C = PoseidonGoldilocksConfig;
/// D defines the extension degree of the field used in the Plonky2 proofs (quadratic extension).
pub const D: usize = 2;
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
pub struct Hash(pub [F; 4]);
@ -40,6 +46,17 @@ impl FromHex for Hash {
}
}
impl Ord for Hash {
fn cmp(&self, other: &Self) -> Ordering {
self.to_string().cmp(&other.to_string())
}
}
impl PartialOrd for Hash {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct PodId(pub Hash);
pub const SELF: PodId = PodId(Hash([F::ONE, F::ZERO, F::ZERO, F::ZERO]));