I have a function which converts u8 to PrimeField element. I name it as u8_to_prime
The error I get is
error[E0038]: the trait `PrimeField` cannot be made into an object
--> src/main.rs:49:17
|
49 | let mut test: [ff::PrimeField;LEN] = [u8_to_prime(null);LEN];
| ^^^^^^^^^^^^^^ `PrimeField` cannot be made into an object
|
My code is
let null: u8 = 0;
let mut test: [ff::PrimeField;LEN] = [u8_to_prime(null);LEN];
This is just for test, I want to have something like
Actually on similar lines, I want to make a circuit where A[i]*B[i] = C[i]
That is checking point wise.
I am writing circuit as follows
//implementation of the demo circuit
impl <S: PrimeField> Circuit<S> for RedactDemo<S>{
fn synthesize<CS: ConstraintSystem<S>>(self, cs: &mut CS) -> Result<(), SynthesisError>
{
//assert_eq!(LEN);
//private input
for i in 1..LEN{
let document_value = self.document.unwrap();
let document = cs.alloc(|| "document",|| document_value[i].ok_or(SynthesisError::AssignmentMissing))?;
//public input
let redactor_value = self.redactor.unwrap();
let redactor = cs.alloc(|| "redactor",|| redactor_value[i].ok_or(SynthesisError::AssignmentMissing))?;
let redacted = cs.alloc_input(|| "redacted", || self.redacted.unwrap()[i].ok_or(SynthesisError::AssignmentMissing))?;
//enforcing the fact that indeed a*b = w, using multiplication gate
cs.enforce(
|| "mult",
|lc| lc + document,
|lc| lc + redactor,
|lc| lc + redacted
);
}
Ok(())
}
}
But this gives me error,
error[E0599]: no method named `ok_or` found for type parameter `S` in the current scope
--> src/main.rs:149:62
|
149 | let document = cs.alloc(|| "document",|| document_value[i].ok_or(SynthesisError::AssignmentMissing))?;
| ^^^^^ method not found in `S`
error[E0599]: no method named `ok_or` found for type parameter `S` in the current scope
--> src/main.rs:152:62
|
152 | let redactor = cs.alloc(|| "redactor",|| redactor_value[i].ok_or(SynthesisError::AssignmentMissing))?;
| ^^^^^ method not found in `S`
error[E0599]: no method named `ok_or` found for type parameter `S` in the current scope
--> src/main.rs:153:77
|
153 | let redacted = cs.alloc_input(|| "redacted", || self.redacted.unwrap()[i].ok_or(SynthesisError::AssignmentMissing))?;
| ^^^^^ method not found in `S`
The problem is I do understand the error. But, I want to give entire array in and check at each point if document*redactor == redacted
Any suggestions as to what should be done? Also, I am working in library bellman
RedactDemo::document is an Option<[S; LEN]>, but you have already unwrapped it, so document_value is not an Option, it is just an array [S; LEN]. And an individual element like document_value[i] has type S.
So instead of calling Option::ok_or (which is used to convert from Option to Result), you can simply use Ok(...) to construct a Result.
You should read the book chapters on enums and error handling if you haven't made it there yet.