Skip to content

Dual signature causing ReachedPrunedBranch #333

@topologoanatom

Description

@topologoanatom

1. Description

Double verification of Schnorr signatures causes a ReachedPrunedBranch error.

/// Verify Schnorr signature for dual oracle price attestation
/// Message format: SHA256(timestamp || price)
fn checksig_price_attestation(pk: Pubkey, timestamp: u32, price: u64, sig: Signature) {
    let hasher: Ctx8 = jet::sha_256_ctx_8_init();
    let hasher: Ctx8 = jet::sha_256_ctx_8_add_4(hasher, timestamp);
    let hasher: Ctx8 = jet::sha_256_ctx_8_add_8(hasher, price);
    let msg: u256 = jet::sha_256_ctx_8_finalize(hasher);
    jet::bip_0340_verify((pk, msg), sig);
}

fn settlement_positive_path(
    current_price: u64,
    new_price: u64,
    timestamp: u32,
    amount: u64,
    oracle_sig: Signature,
    secondary_sig: Signature
) {
    assert!(jet::eq_64(current_price, current_price));
    assert!(jet::eq_64(new_price, new_price));
    assert!(jet::eq_32(timestamp, timestamp));
    assert!(jet::eq_64(amount, amount));

    checksig_price_attestation(param::ORACLE_PK, timestamp, new_price, oracle_sig);
    checksig_price_attestation(param::USER_PK, timestamp, new_price, secondary_sig);
}

However, if comment out current_price and/or amount assertions, bug disappears.
The reproduction code includes both cases.


2. Steps to Reproduce

  1. Use https://github.com/topologoanatom/simplicity-contracts/tree/bug/dual_sig
  2. Run
cargo test test_settlement_positive_dual_sig_bug 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions