mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
bitcoin: fix script number encoding.
Encodings are signed: we may need 5 bytes to encode giant u32s. Reported-by: Fabrice Drouin <fabrice.drouin@acinq.fr> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8522a5ea64
commit
999472d99a
@ -85,16 +85,19 @@ static void add_number(u8 **script, u32 num)
|
||||
else if (num <= 16)
|
||||
add_op(script, 0x50 + num);
|
||||
else {
|
||||
le32 n = cpu_to_le32(num);
|
||||
le64 n = cpu_to_le64(num);
|
||||
|
||||
if (num <= 0x000000FF)
|
||||
/* Beware: encoding is signed! */
|
||||
if (num <= 0x0000007F)
|
||||
add_push_bytes(script, &n, 1);
|
||||
else if (num <= 0x0000FFFF)
|
||||
else if (num <= 0x00007FFF)
|
||||
add_push_bytes(script, &n, 2);
|
||||
else if (num <= 0x00FFFFFF)
|
||||
else if (num <= 0x007FFFFF)
|
||||
add_push_bytes(script, &n, 3);
|
||||
else
|
||||
else if (num <= 0x7FFFFFFF)
|
||||
add_push_bytes(script, &n, 4);
|
||||
else
|
||||
add_push_bytes(script, &n, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user