Skip to content

Commit 90f0c54

Browse files
Neopalliumlovesh
andauthored
DART v1 updates (#2)
* Add inner proof size limit. * Fixup * Update serialization tests. * Reviews cleanup. * Fix issue with growing curve tree height. * Fix issue with affirmation proofs. * dart-testing-cli - use larger curve tree height. * Update test proofs after fixing affirmation proofs. * Improve affirmation proof type names. * Proof name cleanup. * Add missing batched proof. * Check the revealed asset id in the leg. * Remove useless Result. * fix bug with batch verification and add test * Use BTreeSet in KeyDistributionProof. * Resolve review comments. * use vec and not slice --------- Co-authored-by: lovesh <lovesh.bond@gmail.com>
1 parent 9e7d5de commit 90f0c54

50 files changed

Lines changed: 1026 additions & 504 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

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

DART_TXN_FLOWS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ This is an important “rollback” scenario and is exercised in tests.
269269
3. Mediator affirmation (reject)
270270
- The settlement becomes `Rejected`.
271271

272-
4. Sender reversal (cleanup)
273-
- Sender submits a reversal proof for the rejected leg.
272+
4. Sender revert affirmation (cleanup)
273+
- Sender submits a revert affirmation proof for the rejected leg.
274274
- This undoes the sender’s earlier state transition for that rejected leg.
275275

276276
5. Settlement becomes `Finalized`
@@ -313,7 +313,7 @@ At the flow level:
313313
- Receiver affirmation: consumes the receiver’s current account state and produces a new state consistent with “I have committed to receive this leg”.
314314
- Receiver claim: in the executed phase, updates receiver state to actually claim the received amount for the leg.
315315
- Sender counter update: in the executed phase, updates sender state to finalize the sender-side accounting for the leg.
316-
- Sender reversal (after rejection): in the rejected phase, updates sender state to undo the earlier sender affirmation for the rejected leg.
316+
- Sender revert affirmation (after rejection): in the rejected phase, updates sender state to undo the earlier sender affirmation for the rejected leg.
317317

318318
The *chain* only sees:
319319

@@ -506,9 +506,9 @@ This section links the settlement lifecycle actions in this doc to the concrete
506506
- Build/verify: `SenderCounterUpdateProof::{new, verify}`
507507
- Code: [src/bp/leg/proofs.rs](src/bp/leg/proofs.rs)
508508

509-
- Sender reversal (rejected-phase cleanup)
510-
- Proof: `SenderReversalProof`
511-
- Build/verify: `SenderReversalProof::{new, verify}`
509+
- Sender revert affirmation (rejected-phase cleanup)
510+
- Proof: `SenderRevertAffirmationProof`
511+
- Build/verify: `SenderRevertAffirmationProof::{new, verify}`
512512
- Code: [src/bp/leg/proofs.rs](src/bp/leg/proofs.rs)
513513

514514
- Instant settlement (creation proof + all affirmations packaged together)
@@ -521,7 +521,7 @@ Binding note (important for reviewers): most follow-on proofs are keyed by a `Le
521521

522522
This doc intentionally reflects what is exercised in the integration tests:
523523

524-
- Sender reversal is exercised for rejected settlements.
524+
- Sender revert affirmation is exercised for rejected settlements.
525525
- Receiver-side “reversal” and some alternative counter/balance transition variants are described in the math spec, but may not be wired through all higher-level APIs/tests in this repo yet.
526526

527527
If you want this doc to be treated as the authoritative spec for *all* txn variants (including every reversal/irreversible mode), we should decide whether to:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Run code coverage as
6666
cargo llvm-cov -p polymesh-dart -p polymesh-dart-bp --release --lcov --output-path target/coverage/lcov.info --no-clean
6767
```
6868

69-
To get report in HTML, install `lcov` and run run
69+
To get report in HTML, install `lcov` and run
7070
```
7171
genhtml -o target/coverage/html target/coverage/lcov.info
7272
```

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/reinit_db_and_run_testing.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ run mediator-affirm -w mediator-reject-proof.dat -s mediator --settlement 1 --le
6666
run mediator-affirm -r mediator-reject-proof.dat -s mediator --settlement 1 --leg 0
6767

6868
# TODO:
69-
#run receiver-counter-update -s investor-0 --settlement 1 --leg 0
69+
#run receiver-revert-affirmation -s investor-0 --settlement 1 --leg 0
7070

71-
#run sender-reversal -s issuer1-0 --settlement 1 --leg 0
72-
run sender-reversal -w sender-reversal-proof.dat -s issuer1-0 --settlement 1 --leg 0
73-
run sender-reversal -r sender-reversal-proof.dat -s issuer1-0 --settlement 1 --leg 0
71+
#run sender-revert-affirmation -s issuer1-0 --settlement 1 --leg 0
72+
run sender-revert-affirmation -w sender-revert-affirmation-proof.dat -s issuer1-0 --settlement 1 --leg 0
73+
run sender-revert-affirmation -r sender-revert-affirmation-proof.dat -s issuer1-0 --settlement 1 --leg 0
7474

7575
run end-block
7676

dart-testing-cli/src/lib.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ impl DartTestingDb {
450450
"CREATE TABLE IF NOT EXISTS asset_root_history (
451451
id INTEGER PRIMARY KEY AUTOINCREMENT,
452452
block_number INTEGER NOT NULL,
453+
height INTEGER NOT NULL,
453454
root_data BLOB NOT NULL
454455
)",
455456
[],
@@ -460,6 +461,7 @@ impl DartTestingDb {
460461
"CREATE TABLE IF NOT EXISTS account_root_history (
461462
id INTEGER PRIMARY KEY AUTOINCREMENT,
462463
block_number INTEGER NOT NULL,
464+
height INTEGER NOT NULL,
463465
root_data BLOB NOT NULL
464466
)",
465467
[],
@@ -860,8 +862,14 @@ impl DartTestingDb {
860862
(proof, asset_state)
861863
} else {
862864
// Create registration proof and initial state.
863-
let (proof, asset_state) =
864-
AccountAssetRegistrationProof::new(rng, &account_keys, asset_id, 0, &did, params)?;
865+
let (proof, asset_state) = AccountAssetRegistrationProof::<()>::new(
866+
rng,
867+
&account_keys,
868+
asset_id,
869+
0,
870+
&did,
871+
params,
872+
)?;
865873

866874
// Update the account state with the pending state change.
867875
self.update_account_asset_state(&account_info, &asset_state)?;
@@ -941,7 +949,7 @@ impl DartTestingDb {
941949
} else {
942950
let account_keys = account_info.account_keys()?;
943951
// Create minting proof
944-
let proof = AssetMintingProof::new(
952+
let proof = AssetMintingProof::<()>::new(
945953
rng,
946954
&account_keys,
947955
&did,
@@ -1076,7 +1084,10 @@ impl DartTestingDb {
10761084
receiver: receiver_keys,
10771085
asset: asset_state,
10781086
amount,
1079-
config: LegConfig::default(),
1087+
config: LegConfig {
1088+
reveal_asset_id: true,
1089+
..Default::default()
1090+
},
10801091
public_enc_keys: vec![],
10811092
});
10821093
}
@@ -1098,22 +1109,13 @@ impl DartTestingDb {
10981109
settlement: SettlementProof<()>,
10991110
) -> Result<SettlementId> {
11001111
let mut asset_lookup = AssetKeysLookup::new();
1101-
for leg_proof in settlement.legs.iter() {
1102-
if let AnySettlementLegProof::RevealedAssetId(_) = leg_proof {
1103-
let leg_enc = leg_proof
1104-
.leg_enc()
1105-
.decode()
1106-
.map_err(|e| anyhow!("{:?}", e))?;
1107-
if let polymesh_dart_bp::leg::AssetIdEncryption::Revealed(asset_id) =
1108-
leg_enc.leg_enc_core_and_eph_keys.core.ct_asset_id
1109-
{
1110-
if !asset_lookup.contains_key(&asset_id) {
1111-
let asset_info = self.get_asset_by_id(asset_id)?;
1112-
let mediators = asset_info.mediators()?;
1113-
let auditors = asset_info.auditors()?;
1114-
asset_lookup.add(AssetState::new::<()>(asset_id, &mediators, &auditors)?);
1115-
}
1116-
}
1112+
let revealed_assets = settlement.revealed_asset_ids();
1113+
for asset_id in revealed_assets {
1114+
if !asset_lookup.contains_key(&asset_id) {
1115+
let asset_info = self.get_asset_by_id(asset_id)?;
1116+
let mediators = asset_info.mediators()?;
1117+
let auditors = asset_info.auditors()?;
1118+
asset_lookup.add(AssetState::new::<()>(asset_id, &mediators, &auditors)?);
11171119
}
11181120
}
11191121

@@ -1199,7 +1201,7 @@ impl DartTestingDb {
11991201
}
12001202

12011203
// Generate sender affirmation proof
1202-
Ok(SenderAffirmationProof::new(
1204+
Ok(SenderAffirmationProof::<()>::new(
12031205
rng,
12041206
&account_keys,
12051207
&leg_ref,
@@ -1261,7 +1263,7 @@ impl DartTestingDb {
12611263
proof_action,
12621264
|account_keys, leg_ref, leg_enc, _leg, account_state, account_tree, rng| {
12631265
// Create sender counter update proof
1264-
Ok(SenderCounterUpdateProof::new(
1266+
Ok(SenderCounterUpdateProof::<()>::new(
12651267
rng,
12661268
&account_keys,
12671269
&leg_ref,
@@ -1322,7 +1324,7 @@ impl DartTestingDb {
13221324
|account_keys, leg_ref, leg_enc, leg, account_state, account_tree, rng| {
13231325
let amount = leg.amount();
13241326
// Create sender reversal proof
1325-
Ok(SenderReversalProof::new(
1327+
Ok(SenderRevertAffirmationProof::<()>::new(
13261328
rng,
13271329
&account_keys,
13281330
&leg_ref,
@@ -1392,7 +1394,7 @@ impl DartTestingDb {
13921394
}
13931395

13941396
// Create receiver affirmation proof
1395-
Ok(ReceiverAffirmationProof::new(
1397+
Ok(ReceiverAffirmationProof::<()>::new(
13961398
rng,
13971399
&account_keys,
13981400
&leg_ref,
@@ -1463,7 +1465,7 @@ impl DartTestingDb {
14631465
let _leg = encrypted_leg.decrypt(LegRole::mediator(0), &account_keys)?;
14641466

14651467
// Create mediator affirmation proof
1466-
MediatorAffirmationProof::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
1468+
MediatorAffirmationProof::<()>::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
14671469
};
14681470

14691471
// If proof action is to generate only, save proof and return
@@ -1527,7 +1529,7 @@ impl DartTestingDb {
15271529
proof_action,
15281530
|account_keys, leg_ref, leg_enc, leg, asset_state, account_tree, rng| {
15291531
// Create receiver claim proof
1530-
Ok(ReceiverClaimProof::new(
1532+
Ok(ReceiverClaimProof::<()>::new(
15311533
rng,
15321534
&account_keys,
15331535
&leg_ref,

dart-testing-cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ enum Commands {
271271
},
272272

273273
/// Reverse sender affirmation for rejected settlement
274-
SenderReversal {
274+
SenderRevertAffirmation {
275275
/// Signer and account in format signer-account (account optional, will find by asset_id)
276276
#[arg(short, long)]
277277
signer_account: String,
@@ -652,7 +652,7 @@ fn main() -> Result<()> {
652652
);
653653
}
654654

655-
Commands::SenderReversal {
655+
Commands::SenderRevertAffirmation {
656656
signer_account,
657657
settlement_id,
658658
leg_index,

0 commit comments

Comments
 (0)