Basic 'use' syntax for importing custom predicates (#286)

* Basic 'use' syntax for importing custom predicates

* Add extra test for unknown batches

* Fix unused import

* Enforce that imports must match number of predicates in a batch
This commit is contained in:
Rob Knight 2025-06-13 19:09:08 +02:00 committed by GitHub
parent f7bb6af219
commit 21ab3c2d0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 499 additions and 136 deletions

View file

@ -28,9 +28,10 @@
use std::{
cmp::{Ord, Ordering},
fmt,
fmt::Write,
};
use hex::{FromHex, FromHexError};
use hex::{FromHex, FromHexError, ToHex};
use plonky2::{
field::types::{Field, PrimeField64},
hash::poseidon::PoseidonHash,
@ -143,6 +144,32 @@ pub struct Hash(
pub [F; HASH_SIZE],
);
impl ToHex for Hash {
fn encode_hex<T: std::iter::FromIterator<char>>(&self) -> T {
self.0
.iter()
.rev()
.fold(String::with_capacity(64), |mut s, limb| {
write!(s, "{:016x}", limb.0).unwrap();
s
})
.chars()
.collect()
}
fn encode_hex_upper<T: std::iter::FromIterator<char>>(&self) -> T {
self.0
.iter()
.rev()
.fold(String::with_capacity(64), |mut s, limb| {
write!(s, "{:016X}", limb.0).unwrap();
s
})
.chars()
.collect()
}
}
pub fn hash_value(input: &RawValue) -> Hash {
hash_fields(&input.0)
}