support longer arrays in vec_ref (#367)

Support arrays up to 256 elements (hardcoded maximum just to avoid abuse) by combining multiple random_accesses.
The index is now split into low and high parts. It's a bit more inconvenient than using a single Target but this allows avoiding bit decomposition.
This commit is contained in:
Eduard S. 2025-07-30 16:07:25 -07:00 committed by GitHub
parent bde35369d3
commit 4fa285d9fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 175 additions and 61 deletions

View file

@ -1,6 +1,5 @@
use std::fmt;
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
use crate::{
@ -9,7 +8,7 @@ use crate::{
mainpod::Statement,
primitives::merkletree::MerkleClaimAndProof,
},
middleware::{self, OperationType, Params, ToFields, F},
middleware::{self, OperationType},
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -18,20 +17,17 @@ pub enum OperationArg {
Index(usize),
}
impl ToFields for OperationArg {
fn to_fields(&self, _params: &Params) -> Vec<F> {
let f = match self {
Self::None => F::ZERO,
Self::Index(i) => F::from_canonical_usize(*i),
};
vec![f]
}
}
impl OperationArg {
pub fn is_none(&self) -> bool {
matches!(self, OperationArg::None)
}
pub fn as_usize(&self) -> usize {
match self {
Self::None => 0,
Self::Index(i) => *i,
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -41,14 +37,13 @@ pub enum OperationAux {
CustomPredVerifyIndex(usize),
}
impl ToFields for OperationAux {
fn to_fields(&self, _params: &Params) -> Vec<F> {
let fs = match self {
Self::None => [F::ZERO, F::ZERO],
Self::MerkleProofIndex(i) => [F::from_canonical_usize(*i), F::ZERO],
Self::CustomPredVerifyIndex(i) => [F::ZERO, F::from_canonical_usize(*i)],
};
vec![fs[0], fs[1]]
impl OperationAux {
pub fn as_usizes(&self) -> [usize; 2] {
match self {
Self::None => [0, 0],
Self::MerkleProofIndex(i) => [*i, 0],
Self::CustomPredVerifyIndex(i) => [0, *i],
}
}
}