Coinbase scripts generated by zcashd have an extra OP_0, and nSequence == 0xFFFFFFFF.
Also, the height in coinbase needs to match nExpiryHeight. Co-authored-by: Jack Grigg <str4d@electriccoin.co> Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
60faf1c2c5
commit
f81796c12a
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,7 @@ from .sapling.jubjub import (
|
||||||
Point,
|
Point,
|
||||||
Fr as JubjubScalar,
|
Fr as JubjubScalar,
|
||||||
)
|
)
|
||||||
from .utils import leos2ip
|
from .utils import leos2ip, i2leosp
|
||||||
from .zc_utils import write_compact_size
|
from .zc_utils import write_compact_size
|
||||||
|
|
||||||
MAX_MONEY = 21000000 * 100000000
|
MAX_MONEY = 21000000 * 100000000
|
||||||
|
@ -234,6 +234,28 @@ class Script(object):
|
||||||
script._script = b
|
script._script = b
|
||||||
return script
|
return script
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def coinbase_from_height(height):
|
||||||
|
assert height >= 0
|
||||||
|
if height == 0:
|
||||||
|
enc_height = b'\x00'
|
||||||
|
elif height <= 16:
|
||||||
|
enc_height = bytes([0x50 + height])
|
||||||
|
elif height <= 0x7F:
|
||||||
|
enc_height = b'\x01' + i2leosp( 8, height)
|
||||||
|
elif height <= 0x7FFF:
|
||||||
|
enc_height = b'\x02' + i2leosp(16, height)
|
||||||
|
elif height <= 0x7FFFFF:
|
||||||
|
enc_height = b'\x03' + i2leosp(24, height)
|
||||||
|
elif height <= 0x7FFFFFFF:
|
||||||
|
enc_height = b'\x04' + i2leosp(32, height)
|
||||||
|
else:
|
||||||
|
assert height <= 0x7FFFFFFFFF
|
||||||
|
enc_height = b'\x05' + i2leosp(40, height)
|
||||||
|
|
||||||
|
# zcashd adds an OP_0
|
||||||
|
return Script.from_bytes(enc_height + b'\x00')
|
||||||
|
|
||||||
def raw(self):
|
def raw(self):
|
||||||
return self._script
|
return self._script
|
||||||
|
|
||||||
|
@ -415,8 +437,8 @@ class TransactionV5(object):
|
||||||
if is_coinbase:
|
if is_coinbase:
|
||||||
self.vin.append(TxIn.from_components(
|
self.vin.append(TxIn.from_components(
|
||||||
OutPoint.from_components(b'\x00' * 32, 0xFFFFFFFF),
|
OutPoint.from_components(b'\x00' * 32, 0xFFFFFFFF),
|
||||||
Script.from_bytes(b"\x51"),
|
Script.coinbase_from_height(self.nExpiryHeight),
|
||||||
0))
|
0xFFFFFFFF))
|
||||||
if have_transparent_out:
|
if have_transparent_out:
|
||||||
for _ in range((rand.u8() % 3) + 1):
|
for _ in range((rand.u8() % 3) + 1):
|
||||||
self.vout.append(TxOut(rand))
|
self.vout.append(TxOut(rand))
|
||||||
|
|
Loading…
Reference in New Issue