Skip to content

[precompile] Add fixed_witness_group() to officially generate fixed witnesses. #975

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion gkr_iop/src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>
fn gkr_witness<'a>(
circuit: &GKRCircuit<E>,
phase1_witness_group: &RowMajorMatrix<E::BaseField>,
fixed: &[Vec<E::BaseField>],
fixed: &RowMajorMatrix<E::BaseField>,
challenges: &[E],
) -> (
GKRCircuitWitness<'a, CpuBackend<E, PCS>>,
Expand Down
2 changes: 1 addition & 1 deletion gkr_iop/src/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait ProtocolWitnessGeneratorProver<PB: ProverBackend> {
phase1_witness_group: &RowMajorMatrix<
<<PB as ProverBackend>::E as ExtensionField>::BaseField,
>,
fixed: &[Vec<<<PB as ProverBackend>::E as ExtensionField>::BaseField>],
fixed: &RowMajorMatrix<<<PB as ProverBackend>::E as ExtensionField>::BaseField>,
challenges: &[PB::E],
) -> (GKRCircuitWitness<'a, PB>, GKRCircuitOutput<'a, PB>);
}
5 changes: 4 additions & 1 deletion gkr_iop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub trait ProtocolBuilder<E: ExtensionField>: Sized {
pub trait ProtocolWitnessGenerator<E: ExtensionField> {
type Trace;

/// The fixed witness.
fn fixed_witness_group(&self) -> RowMajorMatrix<E::BaseField>;

/// The vectors to be committed in the phase1.
fn phase1_witness_group(
&self,
Expand All @@ -75,7 +78,7 @@ pub trait ProtocolWitnessGenerator<E: ExtensionField> {
phase1_witness_group: &RowMajorMatrix<
<<PB as ProverBackend>::E as ExtensionField>::BaseField,
>,
fixed: &[Vec<<<PB as ProverBackend>::E as ExtensionField>::BaseField>],
fixed: &RowMajorMatrix<<<PB as ProverBackend>::E as ExtensionField>::BaseField>,
challenges: &[PB::E],
) -> (GKRCircuitWitness<'a, PB>, GKRCircuitOutput<'a, PB>) {
<PD as ProtocolWitnessGeneratorProver<PB>>::gkr_witness(
Expand Down
7 changes: 6 additions & 1 deletion gkr_iop/src/precompiles/bitwise_keccakf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ where
E: ExtensionField,
{
type Trace = KeccakTrace<E>;

fn fixed_witness_group(&self) -> RowMajorMatrix<E::BaseField> {
RowMajorMatrix::new_by_values(vec![], 1, InstancePaddingStrategy::Default)
}

fn phase1_witness_group(
&self,
phase1: Self::Trace,
Expand Down Expand Up @@ -874,7 +879,7 @@ pub fn run_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>(
let (gkr_witness, gkr_output) = layout.gkr_witness::<CpuBackend<E, PCS>, CpuProver<_>>(
&gkr_circuit,
&phase1_witness,
&[],
&layout.fixed_witness_group(),
&[],
);
exit_span!(span);
Expand Down
23 changes: 15 additions & 8 deletions gkr_iop/src/precompiles/lookup_keccakf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,20 @@ where
{
type Trace = KeccakTrace;

fn fixed_witness_group(&self) -> RowMajorMatrix<E::BaseField> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Not this line, but per our offline discussion, to complete functionality, we need expand (i.e. iter().cycle() in rust) fixed poly dynamically via num_instances. I will come back to this part when I make the e2e integration

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the returned matrix should be the padded version?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return matrix should be original size for commit into mpcs.
the place of padding should be gkr_witness, or another define another stage when know num_instance at that moment.

RowMajorMatrix::new_by_values(
RC.iter()
.flat_map(|x| {
(0..8)
.map(|i| E::BaseField::from_canonical_u64((x >> (i << 3)) & 0xFF))
.collect_vec()
})
.collect_vec(),
8,
InstancePaddingStrategy::Default,
)
}

fn phase1_witness_group(
&self,
phase1: Self::Trace,
Expand Down Expand Up @@ -838,14 +852,7 @@ pub fn run_faster_keccakf<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>
];

let span = entered_span!("gkr_witness", profiling_2 = true);
let rc_witness = RC
.iter()
.map(|x| {
(0..8)
.map(|i| E::BaseField::from_canonical_u64((x >> (i << 3)) & 0xFF))
.collect_vec()
})
.collect_vec();
let rc_witness = layout.fixed_witness_group();
#[allow(clippy::type_complexity)]
let (gkr_witness, gkr_output) = layout.gkr_witness::<CpuBackend<E, PCS>, CpuProver<_>>(
&gkr_circuit,
Expand Down