Skip to content

Commit

Permalink
Improve CScriptNum() comment
Browse files Browse the repository at this point in the history
Edited-by: Pieter Wuille <pieter.wuille@gmail.com>
  • Loading branch information
petertodd authored and sipa committed Oct 25, 2014
1 parent 698c6ab commit 6004e77
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,23 @@ class CScriptNum
if (vch.size() > nMaxNumSize) {
throw scriptnum_error("script number overflow");
}
if (fRequireMinimal && vch.size() > 0 && (vch.back() & 0x7f) == 0 && (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0)) {
throw scriptnum_error("non-minimally encoded script number");
if (fRequireMinimal && vch.size() > 0) {
// Check that the number is encoded with the minimum possible
// number of bytes.
//
// If the most-significant-byte - excluding the sign bit - is zero
// then we're not minimal. Note how this test also rejects the
// negative-zero encoding, 0x80.
if ((vch.back() & 0x7f) == 0) {
// One exception: if there's more than one byte and the most
// significant bit of the second-most-significant-byte is set
// it would conflict with the sign bit. An example of this case
// is +-255, which encode to 0xff00 and 0xff80 respectively.
// (big-endian).
if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
throw scriptnum_error("non-minimally encoded script number");
}
}
}
m_value = set_vch(vch);
}
Expand Down

0 comments on commit 6004e77

Please sign in to comment.