Skip to content

Commit a5c02d1

Browse files
authored
Merge pull request #13 from joshdoman/multi-input
feat(api): multi-input emulation
2 parents 67c64b2 + e8f8c32 commit a5c02d1

2 files changed

Lines changed: 194 additions & 208 deletions

File tree

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,19 @@ Finally, the enclave should be able to expose the master public key, so that use
4242
/// Trait to abstract the behavior of the bitcoin script verifier, allowing
4343
/// users to provide their own verifier.
4444
pub trait Verifier {
45-
/// Verify a bitcoin script, mirroring the API of `bitcoinkernel::verify`.
45+
/// Verify one or more scripts in a bitcoin transaction.
4646
///
4747
/// # Arguments
48-
/// * `script_pubkey` - The script public key to verify.
49-
/// * `amount` - The amount of the input being spent.
50-
/// * `tx_to` - The transaction containing the script.
51-
/// * `input_index` - The index of the input to verify.
48+
/// * `script_pubkeys` - The scriptPubKeys to verify (by index).
49+
/// * `tx_to` - The transaction with emulated witness data.
5250
/// * `spent_outputs` - The outputs being spent by the transaction.
5351
///
5452
/// # Errors
5553
/// Returns `Error` if verification fails.
5654
fn verify(
5755
&self,
58-
script_pubkey: &[u8],
59-
amount: Option<i64>,
56+
script_pubkeys: &HashMap<usize, ScriptBuf>,
6057
tx_to: &[u8],
61-
input_index: usize,
6258
spent_outputs: &[TxOut],
6359
) -> Result<(), Error>;
6460
}
@@ -70,37 +66,42 @@ pub struct DefaultVerifier;
7066
### Convert emulated transaction
7167

7268
```rust
73-
/// Verifies an emulated Bitcoin script and signs the corresponding transaction.
69+
/// Verifies emulated Bitcoin script and signs the corresponding transaction.
7470
///
75-
/// This function performs script verification using bitcoinkernel, verifying an
76-
/// emulated P2TR input. If successful, it derives an XOnlyPublicKey from the
77-
/// parent key and the emulated merkle root, which is then tweaked with an optional
78-
/// backup merkle root to derive the actual spent UTXO, which is then key-path signed
79-
/// with `SIGHASH_DEFAULT`.
71+
/// This function performs script verification using a Verifier, which verifies one or
72+
/// more emulated P2TR inputs. If successful, it derives for each emulated input an
73+
/// XOnlyPublicKey from the parent key and the emulated merkle root, which is then tweaked
74+
/// with an optional backup merkle root to derive the input's actual spent UTXO. This is
75+
/// then key-path signed with `SIGHASH_DEFAULT`.
8076
///
8177
/// If the emulated script-path spend includes a data-carrying annex (begins with 0x50
8278
/// followed by 0x00), the annex is included in the key-path spend. Otherwise, the annex
8379
/// is dropped.
8480
///
81+
/// Non-emulated inputs are identified by the input type. An emulated input must be a
82+
/// P2TR script-path spend, with a derived scriptPubKey that does not match that of the
83+
/// actual spent output.
84+
///
85+
/// Each signature uses a unique `aux_rand` by hashing the provided `aux_rand` with the
86+
/// index of the input, using SHA256.
87+
///
8588
/// # Arguments
8689
/// * `verifier` - The verifier to use for script validation
87-
/// * `input_index` - Index of the input to verify and sign (0-based)
8890
/// * `emulated_tx_to` - Serialized transaction to verify and sign
8991
/// * `actual_spent_outputs` - Actual outputs being spent
9092
/// * `aux_rand` - Auxiliary random data for signing
9193
/// * `parent_key` - Parent secret key used to derive child key for signing
92-
/// * `backup_merkle_root` - Optional merkle root for backup script path spending
94+
/// * `backup_merkle_roots` - Optional merkle roots for backup script path spending
9395
///
9496
/// # Errors
9597
/// Returns error if verification fails, key derivation fails, or signing fails
9698
pub fn verify_and_sign<V: Verifier>(
9799
verifier: &V,
98-
input_index: usize,
99100
emulated_tx_to: &[u8],
100101
actual_spent_outputs: &[TxOut],
101102
aux_rand: &[u8; 32],
102103
parent_key: SecretKey,
103-
backup_merkle_root: Option<TapNodeHash>,
104+
backup_merkle_roots: HashMap<usize, TapNodeHash>,
104105
) -> Result<Transaction, Error>;
105106
```
106107

0 commit comments

Comments
 (0)