Skip to content

Commit

Permalink
Bail if reveal transaction is too large (ordinals#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Jan 18, 2023
1 parent 690ed24 commit 56dd605
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
super::*,
bitcoin::{
blockdata::{opcodes, script},
policy::MAX_STANDARD_TX_WEIGHT,
schnorr::{TapTweak, TweakedKeyPair, TweakedPublicKey, UntweakedKeyPair},
secp256k1::{
self, constants::SCHNORR_SIGNATURE_SIZE, rand, schnorr::Signature, Secp256k1, XOnlyPublicKey,
Expand Down Expand Up @@ -276,6 +277,14 @@ impl Inscribe {
commit_tx_address
);

let reveal_weight = reveal_tx.weight();

if reveal_weight > MAX_STANDARD_TX_WEIGHT.try_into().unwrap() {
bail!(
"reveal transaction weight greater than {MAX_STANDARD_TX_WEIGHT} (MAX_STANDARD_TX_WEIGHT): {reveal_weight}"
);
}

Ok((unsigned_commit_tx, reveal_tx, recovery_key_pair))
}

Expand Down Expand Up @@ -513,4 +522,33 @@ mod tests {
20_000 - fee - (20_000 - commit_tx.output[0].value),
);
}

#[test]
fn inscribe_over_max_standard_tx_weight() {
let utxos = vec![(outpoint(1), Amount::from_sat(50 * COIN_VALUE))];

let inscription = inscription("text/plain", [0; MAX_STANDARD_TX_WEIGHT as usize]);
let satpoint = None;
let commit_address = change(0);
let reveal_address = recipient();

let error = Inscribe::create_inscription_transactions(
satpoint,
inscription,
BTreeMap::new(),
Network::Bitcoin,
utxos.into_iter().collect(),
vec![commit_address, change(1)],
reveal_address,
FeeRate::try_from(1.0).unwrap(),
)
.unwrap_err()
.to_string();

assert!(
error.contains(&format!("reveal transaction weight greater than {MAX_STANDARD_TX_WEIGHT} (MAX_STANDARD_TX_WEIGHT): 402799")),
"{}",
error
);
}
}

0 comments on commit 56dd605

Please sign in to comment.