Skip to content

feat: actually check push data bytes #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2024
Merged
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
11 changes: 8 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use core::convert::TryFrom;

use bitcoin::constants::MAX_SCRIPT_ELEMENT_SIZE;
use bitcoin::hashes::Hash;
use bitcoin::script::{self, PushBytes, ScriptBuf};
use bitcoin::PubkeyHash;
Expand Down Expand Up @@ -49,12 +50,16 @@ pub(crate) fn witness_size<T: ItemSize>(wit: &[T]) -> usize {

pub(crate) fn witness_to_scriptsig(witness: &[Vec<u8>]) -> ScriptBuf {
let mut b = script::Builder::new();
for wit in witness {
for (i, wit) in witness.iter().enumerate() {
if let Ok(n) = script::read_scriptint(wit) {
b = b.push_int(n);
} else {
let push = <&PushBytes>::try_from(wit.as_slice())
.expect("All pushes in miniscript are <73 bytes");
if i != witness.len() - 1 {
assert!(wit.len() < 73, "All pushes in miniscript are < 73 bytes");
} else {
assert!(wit.len() <= MAX_SCRIPT_ELEMENT_SIZE, "P2SH redeem script is <= 520 bytes");
}
let push = <&PushBytes>::try_from(wit.as_slice()).expect("checked above");
b = b.push_slice(push)
}
}
Expand Down
Loading