Skip to content

Commit 6487e0f

Browse files
committed
Add inner proof size limit.
1 parent 9e7d5de commit 6487e0f

22 files changed

Lines changed: 363 additions & 147 deletions

benches/fee_payments.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
2525
// Benchmark: Generate FeeAccountRegistrationProof.
2626
c.bench_function("FeeAccountRegistrationProof generate", |b| {
2727
b.iter(|| {
28-
let (_proof, _account_state) = FeeAccountRegistrationProof::new(
28+
let (_proof, _account_state) = FeeAccountRegistrationProof::<()>::new(
2929
&mut rng,
3030
black_box(&account_keys.acct),
3131
asset_id,
@@ -37,7 +37,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
3737
});
3838

3939
// Generate a registration proof for verification benchmark.
40-
let (reg_proof, mut fee_account_state) = FeeAccountRegistrationProof::new(
40+
let (reg_proof, mut fee_account_state) = FeeAccountRegistrationProof::<()>::new(
4141
&mut rng,
4242
&account_keys.acct,
4343
asset_id,
@@ -77,7 +77,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
7777
// Benchmark: Generate FeeAccountTopupProof.
7878
c.bench_function("FeeAccountTopupProof generate", |b| {
7979
b.iter(|| {
80-
let _proof = FeeAccountTopupProof::new(
80+
let _proof = FeeAccountTopupProof::<()>::new(
8181
&mut rng,
8282
black_box(&account_keys.acct),
8383
&mut fee_account_state.clone(),
@@ -90,7 +90,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
9090
});
9191

9292
// Generate a topup proof for verification benchmark.
93-
let topup_proof = FeeAccountTopupProof::new(
93+
let topup_proof = FeeAccountTopupProof::<()>::new(
9494
&mut rng,
9595
&account_keys.acct,
9696
&mut fee_account_state,
@@ -129,7 +129,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
129129
// Benchmark: Generate FeeAccountPaymentProof.
130130
c.bench_function("FeeAccountPaymentProof generate", |b| {
131131
b.iter(|| {
132-
let _proof = FeeAccountPaymentProof::new(
132+
let _proof = FeeAccountPaymentProof::<()>::new(
133133
&mut rng,
134134
black_box(&account_keys.acct),
135135
ctx,
@@ -142,7 +142,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
142142
});
143143

144144
// Generate a payment proof for verification benchmark.
145-
let payment_proof = FeeAccountPaymentProof::new(
145+
let payment_proof = FeeAccountPaymentProof::<()>::new(
146146
&mut rng,
147147
&account_keys.acct,
148148
ctx,

benches/proof_benchmark.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn proof_benchmark(c: &mut Criterion) {
4141
// Benchmark: Generate account asset registration proof.
4242
c.bench_function("AccountAssetRegistrationProof generate", |b| {
4343
b.iter(|| {
44-
let (_proof, mut _account_state) = AccountAssetRegistrationProof::new(
44+
let (_proof, mut _account_state) = AccountAssetRegistrationProof::<()>::new(
4545
&mut rng,
4646
black_box(&issuer_keys),
4747
asset_id,
@@ -54,7 +54,7 @@ fn proof_benchmark(c: &mut Criterion) {
5454
});
5555

5656
// Generate a proof to benchmark verification.
57-
let (proof, mut account_state) = AccountAssetRegistrationProof::new(
57+
let (proof, mut account_state) = AccountAssetRegistrationProof::<()>::new(
5858
&mut rng,
5959
black_box(&issuer_keys),
6060
asset_id,
@@ -121,7 +121,7 @@ fn proof_benchmark(c: &mut Criterion) {
121121
}
122122

123123
// Register the investor's account state.
124-
let (_proof, mut investor_account_state) = AccountAssetRegistrationProof::new(
124+
let (_proof, mut investor_account_state) = AccountAssetRegistrationProof::<()>::new(
125125
&mut rng,
126126
&investor_keys,
127127
asset_id,
@@ -153,7 +153,7 @@ fn proof_benchmark(c: &mut Criterion) {
153153
let leg_amount = 500u64;
154154
c.bench_function("AssetMintingProof generate", |b| {
155155
b.iter(|| {
156-
let _proof = AssetMintingProof::new(
156+
let _proof = AssetMintingProof::<(), _>::new(
157157
&mut rng,
158158
&issuer_keys,
159159
ctx,
@@ -166,7 +166,7 @@ fn proof_benchmark(c: &mut Criterion) {
166166
});
167167

168168
// Generate a proof to benchmark verification.
169-
let proof = AssetMintingProof::new(
169+
let proof = AssetMintingProof::<(), _>::new(
170170
&mut rng,
171171
&issuer_keys,
172172
ctx,
@@ -289,7 +289,7 @@ fn proof_benchmark(c: &mut Criterion) {
289289
.map(|_| {
290290
let mut rng = rand::thread_rng();
291291
let mut account_state = account_state.clone();
292-
SenderAffirmationProof::new(
292+
SenderAffirmationProof::<()>::new(
293293
&mut rng,
294294
&issuer_keys,
295295
&leg_ref,
@@ -425,7 +425,7 @@ fn proof_benchmark(c: &mut Criterion) {
425425
let med_enc = leg_enc
426426
.mediator_encryption(0)
427427
.expect("Failed to get mediator encryption for mediator affirmation proof");
428-
let _proof = MediatorAffirmationProof::new(
428+
let _proof = MediatorAffirmationProof::<()>::new(
429429
&mut rng,
430430
&leg_ref,
431431
&med_enc,
@@ -442,7 +442,7 @@ fn proof_benchmark(c: &mut Criterion) {
442442
.mediator_encryption(0)
443443
.expect("Failed to get mediator encryption for mediator affirmation proof");
444444
let proof =
445-
MediatorAffirmationProof::new(&mut rng, &leg_ref, &med_enc, &mediator_keys, 0, true)
445+
MediatorAffirmationProof::<()>::new(&mut rng, &leg_ref, &med_enc, &mediator_keys, 0, true)
446446
.expect("Failed to generate mediator affirmation proof");
447447

448448
// Benchmark: Verify mediator affirmation proof.

dart-common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ pub const MAX_ACCOUNT_ASSET_REG_PROOFS: u32 = 50;
5252
pub const MAX_BATCHED_PROOFS: u32 = 10;
5353
pub const MAX_FEE_ACCOUNT_REG_PROOFS: u32 = 10;
5454
pub const MAX_FEE_ACCOUNT_TOPUP_PROOFS: u32 = 10;
55+
56+
pub const MAX_INNER_PROOF_SIZE: u32 = 10 * 1024;

dart-testing-cli/src/lib.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,14 @@ impl DartTestingDb {
860860
(proof, asset_state)
861861
} else {
862862
// Create registration proof and initial state.
863-
let (proof, asset_state) =
864-
AccountAssetRegistrationProof::new(rng, &account_keys, asset_id, 0, &did, params)?;
863+
let (proof, asset_state) = AccountAssetRegistrationProof::<()>::new(
864+
rng,
865+
&account_keys,
866+
asset_id,
867+
0,
868+
&did,
869+
params,
870+
)?;
865871

866872
// Update the account state with the pending state change.
867873
self.update_account_asset_state(&account_info, &asset_state)?;
@@ -941,7 +947,7 @@ impl DartTestingDb {
941947
} else {
942948
let account_keys = account_info.account_keys()?;
943949
// Create minting proof
944-
let proof = AssetMintingProof::new(
950+
let proof = AssetMintingProof::<()>::new(
945951
rng,
946952
&account_keys,
947953
&did,
@@ -1199,7 +1205,7 @@ impl DartTestingDb {
11991205
}
12001206

12011207
// Generate sender affirmation proof
1202-
Ok(SenderAffirmationProof::new(
1208+
Ok(SenderAffirmationProof::<()>::new(
12031209
rng,
12041210
&account_keys,
12051211
&leg_ref,
@@ -1261,7 +1267,7 @@ impl DartTestingDb {
12611267
proof_action,
12621268
|account_keys, leg_ref, leg_enc, _leg, account_state, account_tree, rng| {
12631269
// Create sender counter update proof
1264-
Ok(SenderCounterUpdateProof::new(
1270+
Ok(SenderCounterUpdateProof::<()>::new(
12651271
rng,
12661272
&account_keys,
12671273
&leg_ref,
@@ -1322,7 +1328,7 @@ impl DartTestingDb {
13221328
|account_keys, leg_ref, leg_enc, leg, account_state, account_tree, rng| {
13231329
let amount = leg.amount();
13241330
// Create sender reversal proof
1325-
Ok(SenderReversalProof::new(
1331+
Ok(SenderReversalProof::<()>::new(
13261332
rng,
13271333
&account_keys,
13281334
&leg_ref,
@@ -1392,7 +1398,7 @@ impl DartTestingDb {
13921398
}
13931399

13941400
// Create receiver affirmation proof
1395-
Ok(ReceiverAffirmationProof::new(
1401+
Ok(ReceiverAffirmationProof::<()>::new(
13961402
rng,
13971403
&account_keys,
13981404
&leg_ref,
@@ -1463,7 +1469,7 @@ impl DartTestingDb {
14631469
let _leg = encrypted_leg.decrypt(LegRole::mediator(0), &account_keys)?;
14641470

14651471
// Create mediator affirmation proof
1466-
MediatorAffirmationProof::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
1472+
MediatorAffirmationProof::<()>::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
14671473
};
14681474

14691475
// If proof action is to generate only, save proof and return
@@ -1527,7 +1533,7 @@ impl DartTestingDb {
15271533
proof_action,
15281534
|account_keys, leg_ref, leg_enc, leg, asset_state, account_tree, rng| {
15291535
// Create receiver claim proof
1530-
Ok(ReceiverClaimProof::new(
1536+
Ok(ReceiverClaimProof::<()>::new(
15311537
rng,
15321538
&account_keys,
15331539
&leg_ref,

src/bp/account.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use polymesh_dart_common::NullifierSkGenCounter;
2222
use super::*;
2323
use crate::account_reg_split::AccountRegHostProtocol;
2424
use crate::auth_proofs::create_registration_auth_proof;
25+
use crate::encode::BoundedCanonical;
2526
use crate::*;
2627

2728
pub(crate) type BPAccountState = bp_account::AccountState<PallasA>;
@@ -340,7 +341,7 @@ impl AccountAssetState {
340341
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, PartialEq, Eq)]
341342
#[scale_info(skip_type_params(T))]
342343
pub struct BatchedAccountAssetRegistrationProof<T: DartLimits = ()> {
343-
pub proofs: BoundedVec<AccountAssetRegistrationProof, T::MaxAccountAssetRegProofs>,
344+
pub proofs: BoundedVec<AccountAssetRegistrationProof<T>, T::MaxAccountAssetRegProofs>,
344345
}
345346

346347
impl<T: DartLimits> BatchedAccountAssetRegistrationProof<T> {
@@ -513,16 +514,18 @@ impl<T: DartLimits> BatchedAccountAssetRegistrationProof<T> {
513514

514515
/// Account asset registration proof. Report section 5.1.3 "Account Registration".
515516
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, PartialEq, Eq)]
516-
pub struct AccountAssetRegistrationProof {
517+
#[scale_info(skip_type_params(T))]
518+
pub struct AccountAssetRegistrationProof<T: DartLimits = ()> {
517519
pub account: AccountPublicKeys,
518520
pub asset_id: AssetId,
519521
pub counter: NullifierSkGenCounter,
520522
pub account_state_commitment: AccountStateCommitment,
521523

522-
pub(crate) inner: WrappedCanonical<account_registration::RegTxnProof<PallasA>>,
524+
pub(crate) inner:
525+
BoundedCanonical<account_registration::RegTxnProof<PallasA>, T::MaxInnerProofSize>,
523526
}
524527

525-
impl AccountAssetRegistrationProof {
528+
impl<T: DartLimits> AccountAssetRegistrationProof<T> {
526529
/// Generate a new account state for an asset and a registration proof for it.
527530
pub fn new<R: RngCore + CryptoRng>(
528531
rng: &mut R,

src/bp/account_reg_split.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ impl AccountRegHostProtocol {
7575
))
7676
}
7777

78-
pub fn finish<R: RngCore + CryptoRng>(
78+
pub fn finish<R: RngCore + CryptoRng, T: DartLimits>(
7979
mut self,
8080
rng: &mut R,
8181
device_response: &TwoSksDeviceResponse,
8282
counter: NullifierSkGenCounter,
8383
tree_params: &CurveTreeParameters<AccountTreeConfig>,
84-
) -> Result<AccountAssetRegistrationProof, Error> {
84+
) -> Result<AccountAssetRegistrationProof<T>, Error> {
8585
let auth_proof = device_response.0.decode()?;
8686

8787
let challenge_h_final =
@@ -107,7 +107,7 @@ impl AccountRegHostProtocol {
107107
asset_id: self.account_state.asset_id(),
108108
counter,
109109
account_state_commitment: self.account_state.current_commitment()?,
110-
inner: WrappedCanonical::wrap(&bp_proof)?,
110+
inner: BoundedCanonical::wrap(&bp_proof)?,
111111
})
112112
}
113113
}

0 commit comments

Comments
 (0)