Skip to content

Commit c1619b7

Browse files
committed
assignment is defined over base field
1 parent f4a5292 commit c1619b7

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

spartan_parallel/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ colored = { version = "2", default-features = false, optional = true }
3030
flate2 = { version = "1" }
3131
goldilocks = { git = "https://github.com/scroll-tech/ceno-Goldilocks" }
3232
ff = "0.13.0"
33+
halo2curves = "0.1.0"
3334

3435
[dev-dependencies]
3536
criterion = "0.5"

spartan_parallel/src/lib.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use std::{
4646

4747
use dense_mlpoly::{DensePolynomial, PolyEvalProof};
4848
use errors::{ProofVerifyError, R1CSError};
49+
use halo2curves::serde::SerdeObject;
4950
use instance::Instance;
5051
use itertools::Itertools;
5152
use math::Math;
@@ -79,34 +80,21 @@ pub struct ComputationDecommitment<S: SpartanExtensionField> {
7980
#[derive(Clone, Serialize, Deserialize)]
8081
pub struct Assignment<S: SpartanExtensionField> {
8182
/// Entries of an assignment
82-
pub assignment: Vec<S>,
83+
pub assignment: Vec<S::BaseField>,
8384
}
8485

8586
impl<S: SpartanExtensionField> Assignment<S> {
8687
/// Constructs a new `Assignment` from a vector
8788
pub fn new(assignment: &[[u8; 32]]) -> Result<Assignment<S>, R1CSError> {
88-
let bytes_to_scalar = |vec: &[[u8; 32]]| -> Result<Vec<S>, R1CSError> {
89-
let mut vec_scalar: Vec<S> = Vec::new();
90-
for v in vec {
91-
let val = S::from_bytes(v);
92-
if val.is_some().unwrap_u8() == 1 {
93-
vec_scalar.push(val.unwrap());
94-
} else {
95-
return Err(R1CSError::InvalidScalar);
96-
}
97-
}
98-
Ok(vec_scalar)
89+
let bytes_to_scalar = |vec: &[[u8; 32]]| -> Result<Vec<S::BaseField>, R1CSError> {
90+
vec
91+
.into_iter()
92+
.map(|v| S::BaseField::from_raw_bytes(v).ok_or(R1CSError::InvalidScalar))
93+
.collect()
9994
};
10095
let assignment_scalar = bytes_to_scalar(assignment);
10196

102-
// check for any parsing errors
103-
if assignment_scalar.is_err() {
104-
return Err(R1CSError::InvalidScalar);
105-
}
106-
107-
Ok(Assignment {
108-
assignment: assignment_scalar.unwrap(),
109-
})
97+
assignment_scalar.map(|a| Assignment { assignment: a })
11098
}
11199

112100
/// Write the assignment into a file

spartan_parallel/src/scalar/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ mod fp2;
44
use ff::Field;
55
pub use fp::Scalar;
66
pub use fp2::ScalarExt2;
7-
use goldilocks::ExtensionField;
7+
use goldilocks::{ExtensionField, SmallField};
88
use merlin::Transcript;
99
use rand::{CryptoRng, RngCore};
10-
use serde::Serialize;
10+
use serde::{Deserialize, Serialize};
1111
use std::fmt;
1212
use std::{
1313
cmp::Eq,
@@ -49,7 +49,7 @@ pub trait SpartanExtensionField:
4949
type InnerType: ExtensionField + Field;
5050

5151
/// Basefield for conserving computational resources
52-
type BaseField: Field;
52+
type BaseField: SmallField + for<'a> Deserialize<'a>;
5353

5454
/// Return inner Goldilocks field element
5555
fn inner(&self) -> &Self::InnerType;

0 commit comments

Comments
 (0)