-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper traits for constructing Value::known
constants
#699
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,7 +248,7 @@ pub mod tests { | |
use group::{ff::PrimeField, Curve}; | ||
use halo2_proofs::{ | ||
arithmetic::CurveAffine, | ||
circuit::{AssignedCell, Chip, Layouter, Value}, | ||
circuit::{AssignedCell, Chip, FieldValue, Layouter, Value}, | ||
plonk::{Any, Error}, | ||
}; | ||
use pasta_curves::pallas; | ||
|
@@ -519,39 +519,39 @@ pub mod tests { | |
// 2^64 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 64)), | ||
sign: Value::known(pallas::Base::one()), | ||
sign: FieldValue::ONE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here (though the length difference could be smaller as |
||
magnitude_error: Value::known(pallas::Base::from(1 << 1)), | ||
}, | ||
// -2^64 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 64)), | ||
sign: Value::known(-pallas::Base::one()), | ||
sign: -Value::<pallas::Base>::ONE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, situations like this require type annotations (to know which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding the need of the explicit type requirement makes it worse TBH. Although There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not (have its own constant)? IIRC, -1 was the most common constant in the Orchard circuit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I was remembering correctly: #698 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For -1 specifically it would help: let a = -Value::<pallas::Base>::ONE;
let a = FieldValue::MINUS_ONE; But the point still applies generally. |
||
magnitude_error: Value::known(pallas::Base::from(1 << 1)), | ||
}, | ||
// 2^66 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 66)), | ||
sign: Value::known(pallas::Base::one()), | ||
sign: FieldValue::ONE, | ||
magnitude_error: Value::known(pallas::Base::from(1 << 3)), | ||
}, | ||
// -2^66 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 66)), | ||
sign: Value::known(-pallas::Base::one()), | ||
sign: -Value::<pallas::Base>::ONE, | ||
magnitude_error: Value::known(pallas::Base::from(1 << 3)), | ||
}, | ||
// 2^254 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()), | ||
sign: Value::known(pallas::Base::one()), | ||
sign: FieldValue::ONE, | ||
magnitude_error: Value::known( | ||
pallas::Base::from_u128(1 << 95).square() * pallas::Base::from(2), | ||
), | ||
}, | ||
// -2^254 | ||
MyCircuit { | ||
magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()), | ||
sign: Value::known(-pallas::Base::one()), | ||
sign: -Value::<pallas::Base>::ONE, | ||
magnitude_error: Value::known( | ||
pallas::Base::from_u128(1 << 95).square() * pallas::Base::from(2), | ||
), | ||
|
@@ -605,7 +605,7 @@ pub mod tests { | |
let magnitude_u64 = rand::random::<u64>(); | ||
let circuit = MyCircuit { | ||
magnitude: Value::known(pallas::Base::from(magnitude_u64)), | ||
sign: Value::known(pallas::Base::zero()), | ||
sign: FieldValue::ZERO, | ||
magnitude_error: Value::unknown(), | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use super::{ | |
AssignedBits, BlockWord, SpreadInputs, SpreadVar, Table16Assignment, ROUNDS, STATE, | ||
}; | ||
use halo2_proofs::{ | ||
circuit::{Layouter, Value}, | ||
circuit::{IntegerValue, Layouter, Value}, | ||
pasta::pallas, | ||
plonk::{Advice, Column, ConstraintSystem, Error, Selector}, | ||
poly::Rotation, | ||
|
@@ -922,7 +922,7 @@ impl CompressionConfig { | |
layouter: &mut impl Layouter<pallas::Base>, | ||
state: State, | ||
) -> Result<[BlockWord; DIGEST_SIZE], Error> { | ||
let mut digest = [BlockWord(Value::known(0)); DIGEST_SIZE]; | ||
let mut digest = [BlockWord(IntegerValue::ZERO); DIGEST_SIZE]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the result is actually longer, as for primitive integers the type can often be elided. |
||
layouter.assign_region( | ||
|| "digest", | ||
|mut region| { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cases like this, the helper constant is a clear win.