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

feat: program refactor #651

Merged
merged 105 commits into from
May 10, 2024
Merged

feat: program refactor #651

merged 105 commits into from
May 10, 2024

Conversation

tamirhemo
Copy link
Contributor

No description provided.

Comment on lines 576 to 602
// TODO: this is very subject to change as groth16 e2e is stabilized
// Convert pv.vkey_digest to a bn254 field element
let vkey_hash = babybears_to_bn254(&pv.sp1_vk_digest);
let mut vkey_hash = Bn254Fr::zero();
for (i, word) in pv.sp1_vk_digest.iter().enumerate() {
if i == 0 {
// Truncate top 3 bits
vkey_hash = Bn254Fr::from_canonical_u32(word.as_canonical_u32() & 0x1fffffffu32);
} else {
vkey_hash *= Bn254Fr::from_canonical_u64(1 << 32);
vkey_hash += Bn254Fr::from_canonical_u32(word.as_canonical_u32());
}
}

// Convert pv.committed_value_digest to a bn254 field element
let committed_values_digest_bytes: [BabyBear; 32] =
words_to_bytes(&pv.committed_value_digest)
.try_into()
.unwrap();
let committed_values_digest = babybear_bytes_to_bn254(&committed_values_digest_bytes);
let mut committed_values_digest = Bn254Fr::zero();
for (i, word) in pv.committed_value_digest.iter().enumerate() {
for (j, byte) in word.0.iter().enumerate() {
if i == 0 && j == 0 {
// Truncate top 3 bits
committed_values_digest =
Bn254Fr::from_canonical_u32(byte.as_canonical_u32() & 0x1f);
} else {
committed_values_digest *= Bn254Fr::from_canonical_u32(256);
committed_values_digest += Bn254Fr::from_canonical_u32(byte.as_canonical_u32());
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

this code was moved out already, should be as it is in main

Comment on lines 606 to 607
witness.commited_values_digest = committed_values_digest;
witness.vkey_hash = vkey_hash;
Copy link
Member

Choose a reason for hiding this comment

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

this should be as it was

Comment on lines +419 to +450
let (shard_proofs, kinds) =
batch.iter().cloned().unzip::<_, _, Vec<_>, Vec<_>>();

let input = SP1ReduceMemoryLayout {
compress_vk: &self.compress_vk,
recursive_machine: &self.compress_machine,
shard_proofs,
kinds,
is_complete,
};

let mut runtime = RecursionRuntime::<Val<InnerSC>, Challenge<InnerSC>, _>::new(
&self.compress_program,
self.compress_machine.config().perm.clone(),
);

let mut witness_stream = Vec::new();
witness_stream.extend(input.write());

runtime.witness_stream = witness_stream.into();
runtime.run();
runtime.print_stats();

let mut recursive_challenger = self.compress_machine.config().challenger();
let mut proof = self.compress_machine.prove::<LocalProver<_, _>>(
&self.compress_pk,
runtime.record,
&mut recursive_challenger,
);

debug_assert_eq!(proof.shard_proofs.len(), 1);
(proof.shard_proofs.pop().unwrap(), ReduceProgramType::Reduce)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be a call to verify_batch or some function

@kevjue kevjue changed the base branch from main to dev May 9, 2024 23:58
Copy link
Contributor

@kevjue kevjue left a comment

Choose a reason for hiding this comment

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

LGTM

@kevjue kevjue added this pull request to the merge queue May 10, 2024
Merged via the queue into dev with commit ffccd03 May 10, 2024
3 checks passed
@kevjue kevjue deleted the tamir/program-refactor branch May 10, 2024 00:51
@kevjue kevjue restored the tamir/program-refactor branch May 10, 2024 22:27
@kevjue kevjue deleted the tamir/program-refactor branch May 10, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants