-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ratan Kaliani <[email protected]>
- Loading branch information
1 parent
3834017
commit 92f14c0
Showing
15 changed files
with
915 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::request::BLAKE2BRequest; | ||
use crate::prelude::U64Variable; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BLAKE2BAccelerator { | ||
pub blake2b_requests: Vec<BLAKE2BRequest>, | ||
pub blake2b_responses: Vec<[U64Variable; 4]>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use super::accelerator::BLAKE2BAccelerator; | ||
use super::digest_hint::BLAKE2BDigestHint; | ||
use super::proof_hint::BLAKE2BProofHint; | ||
use super::request::BLAKE2BRequest; | ||
use super::stark::{get_blake2b_data, stark}; | ||
use crate::frontend::hint::synchronous::Async; | ||
use crate::prelude::*; | ||
|
||
impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> { | ||
/// The constraints for an accelerated BLAKE2B computation using Curta. | ||
pub(crate) fn curta_constrain_blake2b(&mut self, accelerator: BLAKE2BAccelerator) { | ||
// Get all the digest values using the digest hint. | ||
for (request, response) in accelerator | ||
.blake2b_requests | ||
.iter() | ||
.zip(accelerator.blake2b_responses.iter()) | ||
{ | ||
let digest_hint = BLAKE2BDigestHint::new(); | ||
let mut input_stream = VariableStream::new(); | ||
|
||
match &request { | ||
BLAKE2BRequest::Fixed(msg) => { | ||
let len = self.constant::<Variable>(L::Field::from_canonical_usize(msg.len())); | ||
input_stream.write(&len); | ||
input_stream.write_slice(msg); | ||
} | ||
BLAKE2BRequest::Variable(msg, len, _) => { | ||
input_stream.write(len); | ||
input_stream.write_slice(msg); | ||
} | ||
} | ||
|
||
let output_stream = self.hint(input_stream, digest_hint); | ||
let digest = output_stream.read::<[U64Variable; 4]>(self); | ||
self.assert_is_equal(digest, *response); | ||
} | ||
|
||
// Prove correctness of the digest using the proof hint. | ||
|
||
// Initialize the corresponding stark and hint. | ||
let blake2b_data = get_blake2b_data(self, accelerator); | ||
let parameters = blake2b_data.parameters(); | ||
let blake2b_stark = stark(parameters); | ||
let proof_hint = BLAKE2BProofHint::new(parameters); | ||
let mut input_stream = VariableStream::new(); | ||
input_stream.write_blake2b_input(&blake2b_data); | ||
|
||
// Read the stark proof and public inputs from the hint's output stream. | ||
let output_stream = self.async_hint(input_stream, Async(proof_hint)); | ||
let proof = output_stream.read_byte_stark_proof(self, &blake2b_stark.stark); | ||
let num_public_inputs = blake2b_stark.stark.air_data.num_public_inputs; | ||
let public_inputs = output_stream.read_vec(self, num_public_inputs); | ||
|
||
// Verify the proof. | ||
blake2b_stark.verify_proof(self, proof, &public_inputs, blake2b_data) | ||
} | ||
} |
Oops, something went wrong.