Skip to content

Commit

Permalink
Merge #781: feat: optimize pushbytes by removing unreachable minimal …
Browse files Browse the repository at this point in the history
…check

84d1ad5 feat: optimize pushbytes by removing unreachable minimal check (ChrisCho-H)

Pull request description:

  In [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin/blob/aa25adfc64ea0d742ca202991140f280024aba1b/bitcoin/src/blockdata/script/push_bytes.rs#L312), `read_scriptint` checks `NonMinimalPush`, which makes an additional minimal check needless and `PushBytes` inefficient.

ACKs for top commit:
  apoelstra:
    ACK 84d1ad5; successfully ran local tests; yep, I think you are right

Tree-SHA512: d16a199fd5caef13b4fa78584d61c7feb843accb2097b29ca7ccdabfd1cae3e5af9d54d70dc7b7b93f50809c2719f70a87cf4dbba9da53ed55d427568de9eed2
  • Loading branch information
apoelstra committed Dec 3, 2024
2 parents 733bedd + 84d1ad5 commit ce42c66
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/miniscript/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,9 @@ pub fn lex(script: &'_ script::Script) -> Result<Vec<Token<'_>>, Error> {
33 => ret.push(Token::Bytes33(bytes.as_bytes())),
65 => ret.push(Token::Bytes65(bytes.as_bytes())),
_ => {
// check minimality of the number
match script::read_scriptint(bytes.as_bytes()) {
Ok(v) if v >= 0 => {
// check minimality of the number
if script::Builder::new().push_int(v).into_script()[1..].as_bytes()
!= bytes.as_bytes()
{
return Err(Error::InvalidPush(bytes.to_owned().into()));
}
ret.push(Token::Num(v as u32));
}
Ok(_) => return Err(Error::InvalidPush(bytes.to_owned().into())),
Expand Down

0 comments on commit ce42c66

Please sign in to comment.