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

uncompressed g16 #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 examples/hello_example/program/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PROGRAM_KEYPAIR_PATH = path.resolve(
);
const CONNECTION_URL = "http://127.0.0.1:8899";
const COMPUTE_UNITS = 1400000;
const COMPRESSED_PROOF_PATH = path.resolve(__dirname, "../../../test/data/compressed_proof.bin");
const COMPRESSED_PROOF_PATH = path.resolve(__dirname, "../../../test/data/proof.bin");
const CLAIM_DIGEST_PATH = path.resolve(__dirname, "../../../test/data/claim_digest.bin");
enum InstructionType {
VerifyProof = 0,
Expand Down
21 changes: 9 additions & 12 deletions examples/hello_example/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ fn verify_proof(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {

let public_inputs_account = &accounts[0];

// TODO update doc, or serialization format to support both compressed and normal
// [claim_digest (32 bytes) | compressed_proof_a (32 bytes) | compressed_proof_b (64 bytes) | compressed_proof_c (32 bytes)]
if data.len() != 160 {
if data.len() != 288 {
return Err(ProgramError::InvalidInstructionData);
}

Expand All @@ -156,25 +157,21 @@ fn verify_proof(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
msg!("Generated and stored public inputs.");

// Extract and decompress proof components
let compressed_proof_a: &[u8; 32] = data[32..64]
let pi_a: [u8; 64] = data[32..96]
.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?;
let compressed_proof_b: &[u8; 64] = data[64..128]
let pi_b: [u8; 128] = data[96..224]
.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?;
let compressed_proof_c: &[u8; 32] = data[128..160]
let pi_c: [u8; 64] = data[224..288]
.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?;

let proof_a = decompress_g1(compressed_proof_a).map_err(|_| ProgramError::Custom(1))?;
let proof_b = decompress_g2(compressed_proof_b).map_err(|_| ProgramError::Custom(2))?;
let proof_c = decompress_g1(compressed_proof_c).map_err(|_| ProgramError::Custom(3))?;
// let proof_a = decompress_g1(compressed_proof_a).map_err(|_| ProgramError::Custom(1))?;
// let proof_b = decompress_g2(compressed_proof_b).map_err(|_| ProgramError::Custom(2))?;
// let proof_c = decompress_g1(compressed_proof_c).map_err(|_| ProgramError::Custom(3))?;

let proof = Proof {
pi_a: proof_a,
pi_b: proof_b,
pi_c: proof_c,
};
let proof = Proof { pi_a, pi_b, pi_c };

// Verify the proof
let verifier = Verifier::new(&proof, &public_inputs, &VERIFYING_KEY);
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ mod test_lib {
assert!(verifier.verify().is_ok(), "Verification failed");
}

#[test]
fn test_write_proof_to_file() {
let (_, proof, _) = load_receipt_and_extract_data();

let proof = [
proof.pi_a.as_slice(),
proof.pi_b.as_slice(),
proof.pi_c.as_slice(),
]
.concat();

write_compressed_proof_to_file("test/data/proof.bin", &proof);
}

#[test]
fn test_write_compressed_proof_to_file() {
let (_, proof, _) = load_receipt_and_extract_data();
Expand Down
Binary file added test/data/proof.bin
Binary file not shown.