Skip to content

Commit 01caa5b

Browse files
authored
feat: add proof compression (Lightprotocol#435)
* feat(prover.js): add proof compression * feat: proof compression
1 parent fd00bdd commit 01caa5b

File tree

38 files changed

+393
-275
lines changed

38 files changed

+393
-275
lines changed

Cargo.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-lock.yaml

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

programs/psp10in2out/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ light-merkle-tree-program = { version = "0.3.1", path = "../merkle-tree", featur
2323
solana-security-txt = "1.1.0"
2424

2525
# Light Deps
26-
groth16-solana = "0.0.2"
26+
groth16-solana = { git= "https://github.com/Lightprotocol/groth16-solana", branch="master"}
27+
2728
light-macros = { version = "0.3.1", path = "../../macros/light" }
2829
light-verifier-sdk = { version = "0.3.1", path = "../../verifier-sdk" }
2930

programs/psp10in2out/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Config for TransactionConfig {
3333
pub mod light_psp10in2out {
3434
use std::marker::PhantomData;
3535

36-
use light_verifier_sdk::light_transaction::{Amounts, Proof};
36+
use light_verifier_sdk::light_transaction::{Amounts, ProofCompressed};
3737

3838
use super::*;
3939

@@ -89,7 +89,7 @@ pub mod light_psp10in2out {
8989
InstructionDataCompressedTransferSecond::try_deserialize_unchecked(
9090
&mut [vec![0u8; 8], inputs].concat().as_slice(),
9191
)?;
92-
let proof = Proof {
92+
let proof = ProofCompressed {
9393
a: inputs.proof_a,
9494
b: inputs.proof_b,
9595
c: inputs.proof_c,
@@ -218,9 +218,9 @@ pub struct LightInstructionSecond<
218218
#[derive(Debug)]
219219
#[account]
220220
pub struct InstructionDataCompressedTransferSecond {
221-
proof_a: [u8; 64],
222-
proof_b: [u8; 128],
223-
proof_c: [u8; 64],
221+
proof_a: [u8; 32],
222+
proof_b: [u8; 64],
223+
proof_c: [u8; 32],
224224
}
225225

226226
#[derive(Accounts)]

programs/psp2in2out-storage/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ anchor-spl = "0.28.0"
2222

2323
# Light deps
2424
aligned-sized = { version = "0.1.0", path = "../../macros/aligned-sized" }
25-
groth16-solana = "0.0.2"
25+
groth16-solana = { git= "https://github.com/Lightprotocol/groth16-solana", branch="master"}
26+
2627
light-macros = { version = "0.3.1", path = "../../macros/light" }
2728
light-merkle-tree-program = { version = "0.3.1", path = "../merkle-tree", features = ["cpi"] }
2829
light-verifier-sdk = { version = "0.3.1", path = "../../verifier-sdk" }

programs/psp2in2out-storage/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use aligned_sized::aligned_sized;
22
use anchor_lang::prelude::*;
33
use light_macros::light_verifier_accounts;
44
use light_verifier_sdk::light_transaction::{
5-
Amounts, Message, Proof, Transaction, TransactionInput, VERIFIER_STATE_SEED,
5+
Amounts, Message, Transaction, TransactionInput, VERIFIER_STATE_SEED,
66
};
77

88
pub mod verifying_key;
@@ -36,6 +36,8 @@ pub enum VerifierError {
3636

3737
#[program]
3838
pub mod light_psp2in2out_storage {
39+
use light_verifier_sdk::light_transaction::ProofCompressed;
40+
3941
use super::*;
4042

4143
/// Saves the provided message in a temporary PDA.
@@ -87,7 +89,7 @@ pub mod light_psp2in2out_storage {
8789
&mut [vec![0u8; 8], inputs, vec![0u8; 16]].concat().as_slice(),
8890
)?;
8991
let message = Message::new(&ctx.accounts.verifier_state.msg);
90-
let proof = Proof {
92+
let proof = ProofCompressed {
9193
a: inputs.proof_a,
9294
b: inputs.proof_b,
9395
c: inputs.proof_c,
@@ -168,9 +170,9 @@ pub struct LightInstructionSecond<'info> {
168170
#[derive(Debug)]
169171
#[account]
170172
pub struct InstructionDataCompressedTransferSecond {
171-
proof_a: [u8; 64],
172-
proof_b: [u8; 128],
173-
proof_c: [u8; 64],
173+
proof_a: [u8; 32],
174+
proof_b: [u8; 64],
175+
proof_c: [u8; 32],
174176
input_nullifier: [[u8; 32]; 2],
175177
output_commitment: [[u8; 32]; 2],
176178
public_amount_sol: [u8; 32],

programs/psp2in2out/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ light-merkle-tree-program = { version = "0.3.1", path = "../merkle-tree", featur
2323
solana-security-txt = "1.1.0"
2424

2525
# Light Deps
26-
groth16-solana = "0.0.2"
26+
groth16-solana = { git= "https://github.com/Lightprotocol/groth16-solana", branch="master"}
2727
light-macros = { version = "0.3.1", path = "../../macros/light" }
2828
light-verifier-sdk = { version = "0.3.1", path = "../../verifier-sdk" }
2929

programs/psp2in2out/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anchor_lang::prelude::*;
22
use light_macros::light_verifier_accounts;
3-
use light_verifier_sdk::light_transaction::{Amounts, Proof, Transaction, TransactionInput};
3+
use light_verifier_sdk::light_transaction::{
4+
Amounts, ProofCompressed, Transaction, TransactionInput,
5+
};
46

57
pub mod verifying_key;
68
use verifying_key::VERIFYINGKEY_TRANSACTION_MASP2_MAIN;
@@ -21,6 +23,7 @@ pub const PROGRAM_ID: &str = "J1RRetZ4ujphU75LP8RadjXMf3sA12yC2R44CF7PmU7i";
2123

2224
#[program]
2325
pub mod light_psp2in2out {
26+
2427
use super::*;
2528

2629
/// This instruction is the first step of a compressed transaction.
@@ -39,7 +42,7 @@ pub mod light_psp2in2out {
3942
let len_missing_bytes = 256 - inputs.encrypted_utxos.len();
4043
let mut enc_utxos = inputs.encrypted_utxos;
4144
enc_utxos.append(&mut vec![0u8; len_missing_bytes]);
42-
let proof = Proof {
45+
let proof = ProofCompressed {
4346
a: inputs.proof_a,
4447
b: inputs.proof_b,
4548
c: inputs.proof_c,
@@ -76,9 +79,9 @@ pub struct LightInstruction<'info> {}
7679
#[derive(Debug)]
7780
#[account]
7881
pub struct InstructionDataCompressedTransferFirst {
79-
proof_a: [u8; 64],
80-
proof_b: [u8; 128],
81-
proof_c: [u8; 64],
82+
proof_a: [u8; 32],
83+
proof_b: [u8; 64],
84+
proof_c: [u8; 32],
8285
public_amount_spl: [u8; 32],
8386
input_nullifier: [[u8; 32]; 2],
8487
output_commitment: [[u8; 32]; 2],

programs/psp4in4out-app-storage/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ light-merkle-tree-program = { version = "0.3.1", path = "../merkle-tree", featur
2323
solana-security-txt = "1.1.0"
2424

2525
# Light Deps
26-
groth16-solana = "0.0.2"
26+
groth16-solana = { git= "https://github.com/Lightprotocol/groth16-solana", branch="master"}
27+
2728
light-macros = { version = "0.3.1", path = "../../macros/light" }
2829
light-verifier-sdk = { version = "0.3.1", path = "../../verifier-sdk" }
2930
bytemuck = "1.14.0"

programs/psp4in4out-app-storage/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anchor_lang::{prelude::*, solana_program::hash::hash};
22
use bytemuck::{Pod, Zeroable};
33
use light_macros::{light_verifier_accounts, pubkey};
44
use light_verifier_sdk::light_transaction::{
5-
Amounts, Config, Proof, Transaction, TransactionInput,
5+
Amounts, Config, ProofCompressed, Transaction, TransactionInput,
66
};
77

88
pub mod verifying_key;
@@ -42,23 +42,23 @@ pub mod light_psp4in4out_app_storage {
4242
/// This instruction is used to invoke this system verifier and can only be invoked via cpi.
4343
pub fn compressed_transfer_inputs<'info>(
4444
ctx: Context<'_, '_, '_, 'info, LightInstruction<'info>>,
45-
proof_a: [u8; 64],
46-
proof_b: [u8; 128],
47-
proof_c: [u8; 64],
45+
proof_a: [u8; 32],
46+
proof_b: [u8; 64],
47+
proof_c: [u8; 32],
4848
connecting_hash: [u8; 32],
4949
start_offset: usize,
5050
) -> Result<()> {
51-
let proof = Proof {
51+
let proof = ProofCompressed {
5252
a: proof_a,
5353
b: proof_b,
5454
c: proof_c,
5555
};
5656
// + 8 to account for the discriminator
5757
let end_offset =
5858
start_offset + 8 + std::mem::size_of::<Psp4In4OutAppStorageVerifierState>();
59-
6059
let verifier_state = Psp4In4OutAppStorageVerifierState::try_deserialize_unchecked(
61-
&mut &ctx.accounts.verifier_state.to_account_info().data.borrow()[32..end_offset],
60+
&mut &ctx.accounts.verifier_state.to_account_info().data.borrow()
61+
[start_offset..end_offset],
6262
)?;
6363

6464
let public_amount = Amounts {

0 commit comments

Comments
 (0)