diff --git a/bitcoin/src/blockdata/script/builder.rs b/bitcoin/src/blockdata/script/builder.rs index cecdcce2..d622befc 100644 --- a/bitcoin/src/blockdata/script/builder.rs +++ b/bitcoin/src/blockdata/script/builder.rs @@ -44,7 +44,7 @@ impl Builder { } // We can also special-case zero else if data == 0 { - self.push_opcode(opcodes::OP_FALSE) + self.push_opcode(opcodes::OP_0) } // Otherwise encode it as data else { self.push_int_non_minimal(data) } diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index 199dfb58..b843ac82 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -66,6 +66,11 @@ pub use self::types::*; /// Encodes an integer in script(minimal CScriptNum) format. /// /// Writes bytes into the buffer and returns the number of bytes written. +/// +/// Note that `write_scriptint`/`read_scriptint` do not roundtrip if the value written requires +/// more than 4 bytes, this is in line with Bitcoin Core (see [`CScriptNum::serialize`]). +/// +/// [`CScriptNum::serialize`]: pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize { let mut len = 0; if n == 0 { return len; } @@ -110,6 +115,8 @@ pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize { /// don't fit in 64 bits (for efficiency on modern processors) so we /// simply say, anything in excess of 32 bits is no longer a number. /// This is basically a ranged type implementation. +/// +/// This code is based on the `CScriptNum` constructor in Bitcoin Core (see `script.h`). pub fn read_scriptint(v: &[u8]) -> Result { let len = v.len(); if len > 4 { return Err(Error::NumericOverflow); } @@ -167,6 +174,7 @@ pub fn read_scriptbool(v: &[u8]) -> bool { /// Note that this does **not** return an error for `size` between `core::size_of::()` /// and `u16::max_value / 8` if there's no overflow. #[inline] +#[deprecated(since = "0.30.0", note = "bitcoin integers are signed 32 bits, use read_scriptint")] pub fn read_uint(data: &[u8], size: usize) -> Result { read_uint_iter(&mut data.iter(), size).map_err(Into::into) } @@ -212,7 +220,7 @@ fn opcode_to_verify(opcode: Option) -> Option { #[non_exhaustive] pub enum Error { /// Something did a non-minimal push; for more information see - /// `https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#Push_operators` + /// NonMinimalPush, /// Some opcode expected a parameter but it was missing or truncated. EarlyEndOfScript,