chore: minor error handling improvements (#325)
* Minor error handling improvements * Fix error
This commit is contained in:
parent
901ba6442c
commit
2c41a6c554
7 changed files with 62 additions and 58 deletions
|
|
@ -316,8 +316,10 @@ pub(super) fn add_homog_offset<const D: usize, F: ECFieldExt<D>>(
|
|||
}
|
||||
|
||||
const GROUP_ORDER_STR: &str = "1067993516717146951041484916571792702745057740581727230159139685185762082554198619328292418486241";
|
||||
pub static GROUP_ORDER: LazyLock<BigUint> =
|
||||
LazyLock::new(|| BigUint::from_str_radix(GROUP_ORDER_STR, 10).unwrap());
|
||||
pub static GROUP_ORDER: LazyLock<BigUint> = LazyLock::new(|| {
|
||||
BigUint::from_str_radix(GROUP_ORDER_STR, 10)
|
||||
.expect("The input should be a valid decimal string.")
|
||||
});
|
||||
|
||||
static FIELD_NUM_SQUARES: LazyLock<BigUint> =
|
||||
LazyLock::new(|| (ECField::order() - BigUint::one()) >> 1);
|
||||
|
|
@ -605,10 +607,8 @@ impl CircuitBuilderElliptic for CircuitBuilder<GoldilocksField, 2> {
|
|||
let outputs = ECAddHomogOffset::apply(self, &inputs);
|
||||
// plonky2 expects all gate constraints to be satisfied by the zero vector.
|
||||
// So our elliptic curve addition gate computes [x,z-b,u,t-b], and we have to add the b here.
|
||||
let x = FieldTarget::new(outputs[0..5].try_into().unwrap());
|
||||
let z = FieldTarget::new(outputs[5..10].try_into().unwrap());
|
||||
let u = FieldTarget::new(outputs[10..15].try_into().unwrap());
|
||||
let t = FieldTarget::new(outputs[15..20].try_into().unwrap());
|
||||
let [x, z, u, t] =
|
||||
array::from_fn(|j| FieldTarget::new(array::from_fn(|i| outputs[5 * j + i])));
|
||||
let b1 = self.constant(Point::B1);
|
||||
let z = self.nnf_add_scalar_times_generator_power(b1, 1, &z);
|
||||
let t = self.nnf_add_scalar_times_generator_power(b1, 1, &t);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::{array, marker::PhantomData};
|
||||
|
||||
use num::BigUint;
|
||||
use plonky2::{
|
||||
|
|
@ -217,7 +217,7 @@ impl<const DEG: usize, NNF: OEF<DEG> + FieldExtension<DEG, BaseField = F>>
|
|||
inputs.extend_from_slice(&x.components);
|
||||
inputs.extend_from_slice(&y.components);
|
||||
let outputs = NNFMulSimple::<DEG, NNF>::apply(self, &inputs);
|
||||
OEFTarget::new(outputs.try_into().unwrap())
|
||||
OEFTarget::new(array::from_fn(|i| outputs[i]))
|
||||
}
|
||||
fn nnf_div(&mut self, x: &OEFTarget<DEG, NNF>, y: &OEFTarget<DEG, NNF>) -> OEFTarget<DEG, NNF> {
|
||||
let one = self.nnf_one();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::array;
|
||||
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
|
||||
use crate::backends::plonky2::primitives::ec::{
|
||||
|
|
@ -39,10 +41,8 @@ impl SimpleGate for ECAddHomogOffset {
|
|||
Self::F: plonky2::field::extension::Extendable<D>,
|
||||
{
|
||||
let mut ans = Vec::with_capacity(20);
|
||||
let x1 = QuinticTensor::from_base(wires[0..5].try_into().unwrap());
|
||||
let u1 = QuinticTensor::from_base(wires[5..10].try_into().unwrap());
|
||||
let x2 = QuinticTensor::from_base(wires[10..15].try_into().unwrap());
|
||||
let u2 = QuinticTensor::from_base(wires[15..20].try_into().unwrap());
|
||||
let [x1, u1, x2, u2] =
|
||||
array::from_fn(|j| QuinticTensor::from_base(array::from_fn(|i| wires[5 * j + i])));
|
||||
let out = add_homog_offset(x1, u1, x2, u2);
|
||||
for v in out {
|
||||
ans.extend(v.to_base());
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ impl Intermediate {
|
|||
h
|
||||
}
|
||||
fn hash(&self) -> Hash {
|
||||
self.hash.unwrap()
|
||||
self.hash.expect("Hash has not been computed.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -554,7 +554,7 @@ impl Leaf {
|
|||
h
|
||||
}
|
||||
fn hash(&self) -> Hash {
|
||||
self.hash.unwrap()
|
||||
self.hash.expect("Hash has not been computed.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue