Skip to content
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

zk/vm: Witness Scalar values at the time of witnessing rather than ti… #261

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/zk/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,15 @@ impl Circuit<pallas::Base> for ZkCircuit {
}

Witness::Scalar(w) => {
// NOTE: Because the type in `halo2_gadgets` does not have a `Clone`
// impl, we push scalars as-is to the heap. They get witnessed
// when they get used.
trace!(target: "zk::vm", "Witnessing Scalar into circuit");
let scalar = ScalarFixed::new(
ecc_chip.as_ref().unwrap().clone(),
layouter.namespace(|| "Witness ScalarFixed"),
*w,
)?;

trace!(target: "zk::vm", "Pushing Scalar to heap address {}", heap.len());
heap.push(HeapVar::Scalar(*w));
heap.push(HeapVar::Scalar(scalar));
}

Witness::MerklePath(w) => {
Expand Down Expand Up @@ -783,11 +787,8 @@ impl Circuit<pallas::Base> for ZkCircuit {
let lhs: FixedPoint<pallas::Affine, EccChip<OrchardFixedBases>> =
heap[args[1].1].clone().try_into()?;

let rhs = ScalarFixed::new(
ecc_chip.as_ref().unwrap().clone(),
layouter.namespace(|| "EcMul: ScalarFixed::new()"),
heap[args[0].1].clone().try_into()?,
)?;
let rhs: ScalarFixed<pallas::Affine, EccChip<OrchardFixedBases>> =
heap[args[0].1].clone().try_into()?;

let (ret, _) = lhs.mul(layouter.namespace(|| "EcMul()"), rhs)?;

Expand Down
5 changes: 3 additions & 2 deletions src/zk/vm_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use darkfi_sdk::crypto::{constants::OrchardFixedBases, MerkleNode};
use halo2_gadgets::ecc::{
chip::EccChip, FixedPoint, FixedPointBaseField, FixedPointShort, NonIdentityPoint, Point,
ScalarFixed,
};
use halo2_proofs::{
circuit::{AssignedCell, Value},
Expand Down Expand Up @@ -99,7 +100,7 @@ pub enum HeapVar {
EcFixedPointShort(FixedPointShort<pallas::Affine, EccChip<OrchardFixedBases>>),
EcFixedPointBase(FixedPointBaseField<pallas::Affine, EccChip<OrchardFixedBases>>),
Base(AssignedCell<pallas::Base, pallas::Base>),
Scalar(Value<pallas::Scalar>),
Scalar(ScalarFixed<pallas::Affine, EccChip<OrchardFixedBases>>),
MerklePath(Value<[pallas::Base; 32]>),
Uint32(Value<u32>),
Uint64(Value<u64>),
Expand Down Expand Up @@ -128,7 +129,7 @@ impl_try_from!(EcNiPoint, NonIdentityPoint<pallas::Affine, EccChip<OrchardFixedB
impl_try_from!(EcFixedPoint, FixedPoint<pallas::Affine, EccChip<OrchardFixedBases>>);
impl_try_from!(EcFixedPointShort, FixedPointShort<pallas::Affine, EccChip<OrchardFixedBases>>);
impl_try_from!(EcFixedPointBase, FixedPointBaseField<pallas::Affine, EccChip<OrchardFixedBases>>);
impl_try_from!(Scalar, Value<pallas::Scalar>);
impl_try_from!(Scalar, ScalarFixed<pallas::Affine, EccChip<OrchardFixedBases>>);
impl_try_from!(Base, AssignedCell<pallas::Base, pallas::Base>);
impl_try_from!(Uint32, Value<u32>);
impl_try_from!(MerklePath, Value<[pallas::Base; 32]>);
Loading