Skip to content

Commit

Permalink
Merge pull request #10 from monlovesmango/main
Browse files Browse the repository at this point in the history
enforce vault input index of 0
  • Loading branch information
rot13maxi authored Sep 27, 2024
2 parents a275943 + 500e8ff commit 48b7ee9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/vault/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl VaultCovenant {
let tx_commitment_spec = TxCommitmentSpec {
prev_sciptpubkeys: false,
prev_amounts: false,
input_index: false,
outputs: false,
..Default::default()
};
Expand Down Expand Up @@ -466,6 +467,7 @@ impl VaultCovenant {
let tx_commitment_spec = TxCommitmentSpec {
prev_sciptpubkeys: false,
prev_amounts: false,
input_index: false,
outputs: false,
..Default::default()
};
Expand Down
4 changes: 4 additions & 0 deletions src/vault/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub(crate) fn vault_trigger_withdrawal() -> ScriptBuf {
// start with encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_slice([0x00u8, 0x00u8, 0x00u8, 0x00u8]) // add input index of 0
.push_opcode(OP_SWAP) // bring working sigmsg back to top of stack
.push_opcode(OP_CAT) // input index
.push_opcode(OP_CAT) // spend type
.push_slice(*DUST_AMOUNT) // push the dust amount for the target output
Expand Down Expand Up @@ -161,6 +163,8 @@ pub(crate) fn vault_cancel_withdrawal() -> ScriptBuf {
// start with encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_slice([0x00u8, 0x00u8, 0x00u8, 0x00u8]) // add input index of 0
.push_opcode(OP_SWAP) // bring working sigmsg back to top of stack
.push_opcode(OP_CAT) // input index
.push_opcode(OP_CAT) // spend type
.push_opcode(OP_FROMALTSTACK) // get the output amount
Expand Down
12 changes: 8 additions & 4 deletions src/vault/signature_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) struct TxCommitmentSpec {
pub(crate) prev_amounts: bool,
pub(crate) prev_sciptpubkeys: bool,
pub(crate) sequences: bool,
pub(crate) input_index: bool,
pub(crate) outputs: bool,
pub(crate) spend_type: bool,
pub(crate) annex: bool,
Expand All @@ -62,6 +63,7 @@ impl Default for TxCommitmentSpec {
prev_amounts: true,
prev_sciptpubkeys: true,
sequences: true,
input_index: true,
outputs: true,
spend_type: true,
annex: true,
Expand Down Expand Up @@ -262,10 +264,12 @@ pub(crate) fn get_sigmsg_components<S: Into<TapLeafHash>>(
debug!("input sequence: {:?}", sequence.to_hex_string(Case::Lower));
components.push(sequence);
} else {
let mut input_idx = Vec::new();
(input_index as u32).consensus_encode(&mut input_idx)?;
debug!("input index: {:?}", input_idx.to_hex_string(Case::Lower));
components.push(input_idx);
if spec.input_index {
let mut input_idx = Vec::new();
(input_index as u32).consensus_encode(&mut input_idx)?;
debug!("input index: {:?}", input_idx.to_hex_string(Case::Lower));
components.push(input_idx);
}
}

// If an annex is present (the lowest bit of spend_type is set):
Expand Down

0 comments on commit 48b7ee9

Please sign in to comment.