Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions DART_TXN_FLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ This is an important “rollback” scenario and is exercised in tests.
3. Mediator affirmation (reject)
- The settlement becomes `Rejected`.

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

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

The *chain* only sees:

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

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

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

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

- Sender reversal is exercised for rejected settlements.
- Sender revert affirmation is exercised for rejected settlements.
- 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.

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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Run code coverage as
cargo llvm-cov -p polymesh-dart -p polymesh-dart-bp --release --lcov --output-path target/coverage/lcov.info --no-clean
```

To get report in HTML, install `lcov` and run run
To get report in HTML, install `lcov` and run
```
genhtml -o target/coverage/html target/coverage/lcov.info
```
Expand Down
12 changes: 6 additions & 6 deletions benches/fee_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
// Benchmark: Generate FeeAccountRegistrationProof.
c.bench_function("FeeAccountRegistrationProof generate", |b| {
b.iter(|| {
let (_proof, _account_state) = FeeAccountRegistrationProof::new(
let (_proof, _account_state) = FeeAccountRegistrationProof::<()>::new(
&mut rng,
black_box(&account_keys.acct),
asset_id,
Expand All @@ -37,7 +37,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
});

// Generate a registration proof for verification benchmark.
let (reg_proof, mut fee_account_state) = FeeAccountRegistrationProof::new(
let (reg_proof, mut fee_account_state) = FeeAccountRegistrationProof::<()>::new(
&mut rng,
&account_keys.acct,
asset_id,
Expand Down Expand Up @@ -77,7 +77,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
// Benchmark: Generate FeeAccountTopupProof.
c.bench_function("FeeAccountTopupProof generate", |b| {
b.iter(|| {
let _proof = FeeAccountTopupProof::new(
let _proof = FeeAccountTopupProof::<()>::new(
&mut rng,
black_box(&account_keys.acct),
&mut fee_account_state.clone(),
Expand All @@ -90,7 +90,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
});

// Generate a topup proof for verification benchmark.
let topup_proof = FeeAccountTopupProof::new(
let topup_proof = FeeAccountTopupProof::<()>::new(
&mut rng,
&account_keys.acct,
&mut fee_account_state,
Expand Down Expand Up @@ -129,7 +129,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
// Benchmark: Generate FeeAccountPaymentProof.
c.bench_function("FeeAccountPaymentProof generate", |b| {
b.iter(|| {
let _proof = FeeAccountPaymentProof::new(
let _proof = FeeAccountPaymentProof::<()>::new(
&mut rng,
black_box(&account_keys.acct),
ctx,
Expand All @@ -142,7 +142,7 @@ fn fee_proof_benchmark(c: &mut Criterion) {
});

// Generate a payment proof for verification benchmark.
let payment_proof = FeeAccountPaymentProof::new(
let payment_proof = FeeAccountPaymentProof::<()>::new(
&mut rng,
&account_keys.acct,
ctx,
Expand Down
16 changes: 8 additions & 8 deletions benches/proof_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn proof_benchmark(c: &mut Criterion) {
// Benchmark: Generate account asset registration proof.
c.bench_function("AccountAssetRegistrationProof generate", |b| {
b.iter(|| {
let (_proof, mut _account_state) = AccountAssetRegistrationProof::new(
let (_proof, mut _account_state) = AccountAssetRegistrationProof::<()>::new(
&mut rng,
black_box(&issuer_keys),
asset_id,
Expand All @@ -54,7 +54,7 @@ fn proof_benchmark(c: &mut Criterion) {
});

// Generate a proof to benchmark verification.
let (proof, mut account_state) = AccountAssetRegistrationProof::new(
let (proof, mut account_state) = AccountAssetRegistrationProof::<()>::new(
&mut rng,
black_box(&issuer_keys),
asset_id,
Expand Down Expand Up @@ -121,7 +121,7 @@ fn proof_benchmark(c: &mut Criterion) {
}

// Register the investor's account state.
let (_proof, mut investor_account_state) = AccountAssetRegistrationProof::new(
let (_proof, mut investor_account_state) = AccountAssetRegistrationProof::<()>::new(
&mut rng,
&investor_keys,
asset_id,
Expand Down Expand Up @@ -153,7 +153,7 @@ fn proof_benchmark(c: &mut Criterion) {
let leg_amount = 500u64;
c.bench_function("AssetMintingProof generate", |b| {
b.iter(|| {
let _proof = AssetMintingProof::new(
let _proof = AssetMintingProof::<(), _>::new(
&mut rng,
&issuer_keys,
ctx,
Expand All @@ -166,7 +166,7 @@ fn proof_benchmark(c: &mut Criterion) {
});

// Generate a proof to benchmark verification.
let proof = AssetMintingProof::new(
let proof = AssetMintingProof::<(), _>::new(
&mut rng,
&issuer_keys,
ctx,
Expand Down Expand Up @@ -289,7 +289,7 @@ fn proof_benchmark(c: &mut Criterion) {
.map(|_| {
let mut rng = rand::thread_rng();
let mut account_state = account_state.clone();
SenderAffirmationProof::new(
SenderAffirmationProof::<()>::new(
&mut rng,
&issuer_keys,
&leg_ref,
Expand Down Expand Up @@ -425,7 +425,7 @@ fn proof_benchmark(c: &mut Criterion) {
let med_enc = leg_enc
.mediator_encryption(0)
.expect("Failed to get mediator encryption for mediator affirmation proof");
let _proof = MediatorAffirmationProof::new(
let _proof = MediatorAffirmationProof::<()>::new(
&mut rng,
&leg_ref,
&med_enc,
Expand All @@ -442,7 +442,7 @@ fn proof_benchmark(c: &mut Criterion) {
.mediator_encryption(0)
.expect("Failed to get mediator encryption for mediator affirmation proof");
let proof =
MediatorAffirmationProof::new(&mut rng, &leg_ref, &med_enc, &mediator_keys, 0, true)
MediatorAffirmationProof::<()>::new(&mut rng, &leg_ref, &med_enc, &mediator_keys, 0, true)
.expect("Failed to generate mediator affirmation proof");

// Benchmark: Verify mediator affirmation proof.
Expand Down
2 changes: 2 additions & 0 deletions dart-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ pub const MAX_ACCOUNT_ASSET_REG_PROOFS: u32 = 50;
pub const MAX_BATCHED_PROOFS: u32 = 10;
pub const MAX_FEE_ACCOUNT_REG_PROOFS: u32 = 10;
pub const MAX_FEE_ACCOUNT_TOPUP_PROOFS: u32 = 10;

pub const MAX_INNER_PROOF_SIZE: u32 = 10 * 1024;
8 changes: 4 additions & 4 deletions dart-testing-cli/reinit_db_and_run_testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ run mediator-affirm -w mediator-reject-proof.dat -s mediator --settlement 1 --le
run mediator-affirm -r mediator-reject-proof.dat -s mediator --settlement 1 --leg 0

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

#run sender-reversal -s issuer1-0 --settlement 1 --leg 0
run sender-reversal -w sender-reversal-proof.dat -s issuer1-0 --settlement 1 --leg 0
run sender-reversal -r sender-reversal-proof.dat -s issuer1-0 --settlement 1 --leg 0
#run sender-revert-affirmation -s issuer1-0 --settlement 1 --leg 0
run sender-revert-affirmation -w sender-revert-affirmation-proof.dat -s issuer1-0 --settlement 1 --leg 0
run sender-revert-affirmation -r sender-revert-affirmation-proof.dat -s issuer1-0 --settlement 1 --leg 0

run end-block

Expand Down
54 changes: 28 additions & 26 deletions dart-testing-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ impl DartTestingDb {
"CREATE TABLE IF NOT EXISTS asset_root_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
block_number INTEGER NOT NULL,
height INTEGER NOT NULL,
root_data BLOB NOT NULL
)",
[],
Expand All @@ -460,6 +461,7 @@ impl DartTestingDb {
"CREATE TABLE IF NOT EXISTS account_root_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
block_number INTEGER NOT NULL,
height INTEGER NOT NULL,
root_data BLOB NOT NULL
)",
[],
Expand Down Expand Up @@ -860,8 +862,14 @@ impl DartTestingDb {
(proof, asset_state)
} else {
// Create registration proof and initial state.
let (proof, asset_state) =
AccountAssetRegistrationProof::new(rng, &account_keys, asset_id, 0, &did, params)?;
let (proof, asset_state) = AccountAssetRegistrationProof::<()>::new(
rng,
&account_keys,
asset_id,
0,
&did,
params,
)?;

// Update the account state with the pending state change.
self.update_account_asset_state(&account_info, &asset_state)?;
Expand Down Expand Up @@ -941,7 +949,7 @@ impl DartTestingDb {
} else {
let account_keys = account_info.account_keys()?;
// Create minting proof
let proof = AssetMintingProof::new(
let proof = AssetMintingProof::<()>::new(
rng,
&account_keys,
&did,
Expand Down Expand Up @@ -1076,7 +1084,10 @@ impl DartTestingDb {
receiver: receiver_keys,
asset: asset_state,
amount,
config: LegConfig::default(),
config: LegConfig {
reveal_asset_id: true,
..Default::default()
},
public_enc_keys: vec![],
});
}
Expand All @@ -1098,22 +1109,13 @@ impl DartTestingDb {
settlement: SettlementProof<()>,
) -> Result<SettlementId> {
let mut asset_lookup = AssetKeysLookup::new();
for leg_proof in settlement.legs.iter() {
if let AnySettlementLegProof::RevealedAssetId(_) = leg_proof {
let leg_enc = leg_proof
.leg_enc()
.decode()
.map_err(|e| anyhow!("{:?}", e))?;
if let polymesh_dart_bp::leg::AssetIdEncryption::Revealed(asset_id) =
leg_enc.leg_enc_core_and_eph_keys.core.ct_asset_id
{
if !asset_lookup.contains_key(&asset_id) {
let asset_info = self.get_asset_by_id(asset_id)?;
let mediators = asset_info.mediators()?;
let auditors = asset_info.auditors()?;
asset_lookup.add(AssetState::new::<()>(asset_id, &mediators, &auditors)?);
}
}
let revealed_assets = settlement.revealed_asset_ids();
for asset_id in revealed_assets {
if !asset_lookup.contains_key(&asset_id) {
let asset_info = self.get_asset_by_id(asset_id)?;
let mediators = asset_info.mediators()?;
let auditors = asset_info.auditors()?;
asset_lookup.add(AssetState::new::<()>(asset_id, &mediators, &auditors)?);
}
}

Expand Down Expand Up @@ -1199,7 +1201,7 @@ impl DartTestingDb {
}

// Generate sender affirmation proof
Ok(SenderAffirmationProof::new(
Ok(SenderAffirmationProof::<()>::new(
rng,
&account_keys,
&leg_ref,
Expand Down Expand Up @@ -1261,7 +1263,7 @@ impl DartTestingDb {
proof_action,
|account_keys, leg_ref, leg_enc, _leg, account_state, account_tree, rng| {
// Create sender counter update proof
Ok(SenderCounterUpdateProof::new(
Ok(SenderCounterUpdateProof::<()>::new(
rng,
&account_keys,
&leg_ref,
Expand Down Expand Up @@ -1322,7 +1324,7 @@ impl DartTestingDb {
|account_keys, leg_ref, leg_enc, leg, account_state, account_tree, rng| {
let amount = leg.amount();
// Create sender reversal proof
Ok(SenderReversalProof::new(
Ok(SenderRevertAffirmationProof::<()>::new(
rng,
&account_keys,
&leg_ref,
Expand Down Expand Up @@ -1392,7 +1394,7 @@ impl DartTestingDb {
}

// Create receiver affirmation proof
Ok(ReceiverAffirmationProof::new(
Ok(ReceiverAffirmationProof::<()>::new(
rng,
&account_keys,
&leg_ref,
Expand Down Expand Up @@ -1463,7 +1465,7 @@ impl DartTestingDb {
let _leg = encrypted_leg.decrypt(LegRole::mediator(0), &account_keys)?;

// Create mediator affirmation proof
MediatorAffirmationProof::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
MediatorAffirmationProof::<()>::new(rng, &leg_ref, &med_enc, &account_keys, 0, accept)?
};

// If proof action is to generate only, save proof and return
Expand Down Expand Up @@ -1527,7 +1529,7 @@ impl DartTestingDb {
proof_action,
|account_keys, leg_ref, leg_enc, leg, asset_state, account_tree, rng| {
// Create receiver claim proof
Ok(ReceiverClaimProof::new(
Ok(ReceiverClaimProof::<()>::new(
rng,
&account_keys,
&leg_ref,
Expand Down
4 changes: 2 additions & 2 deletions dart-testing-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ enum Commands {
},

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

Commands::SenderReversal {
Commands::SenderRevertAffirmation {
signer_account,
settlement_id,
leg_index,
Expand Down
Loading
Loading