Skip to content

Commit

Permalink
correct consensusBranchId for sapling
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjiling committed Nov 14, 2018
1 parent 5848956 commit ea496de
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/bufferutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ function readUInt64LE (buffer, offset) {
return b + a
}

function readInt64LE (buffer, offset) {
var a = buffer.readUInt32LE(offset)
var b = buffer.readInt32LE(offset + 4)
b *= 0x100000000
return b + a
}

function writeUInt64LE (buffer, value, offset) {
verifuint(value, 0x001fffffffffffff)

Expand Down Expand Up @@ -48,6 +55,7 @@ module.exports = {
readPushDataInt: pushdata.decode,
readUInt64LE: readUInt64LE,
readVarInt: readVarInt,
readInt64LE: readInt64LE,
varIntBuffer: varuint.encode,
varIntSize: varuint.encodingLength,
writePushDataInt: pushdata.encode,
Expand Down
18 changes: 16 additions & 2 deletions src/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ module.exports = {
},
pubKeyHash: 0x1cb8,
scriptHash: 0x1cbd,
wif: 0x80
wif: 0x80,
// This parameter was introduced in version 3 to allow soft forks, for version 1 and 2 transactions we add a
// dummy value.
consensusBranchId: {
1: 0x00,
2: 0x00,
3: 0x5ba81b19,
4: 0x76b809bb
}
},
testnet: {
messagePrefix: '\x18Bitcoin Signed Message:\n',
Expand All @@ -22,7 +30,13 @@ module.exports = {
},
pubKeyHash: 0x6f,
scriptHash: 0xc4,
wif: 0xef
wif: 0xef,
consensusBranchId: {
1: 0x00,
2: 0x00,
3: 0x5ba81b19,
4: 0x76b809bb
}
},
litecoin: {
messagePrefix: '\x19Litecoin Signed Message:\n',
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Transaction.PREVOUTS_HASH_PERSON = new Buffer('ZcashPrevoutHash')
Transaction.SEQUENCE_HASH_PERSON = new Buffer('ZcashSequencHash')
Transaction.OUTPUTS_HASH_PERSON = new Buffer('ZcashOutputsHash')
Transaction.JOINSPLITS_HASH_PERSON = new Buffer('ZcashJSplitsHash')
Transaction.OVERWINTER_HASH_PERSON = Buffer.concat([new Buffer('ZcashSigHash'), Buffer.from('191ba85b', 'hex')])
Transaction.OVERWINTER_HASH_PERSON = Buffer.concat([new Buffer('ZcashSigHash'), Buffer.from('bb09b876', 'hex')])

// Sapling note magic values, copied from src/zcash/Zcash.h
var NOTEENCRYPTION_AUTH_BYTES = 16;
Expand Down
4 changes: 4 additions & 0 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ TransactionBuilder.prototype.setLockTime = function (locktime) {
TransactionBuilder.prototype.setVersion = function (version) {
typeforce(types.UInt32, version)

if (!this.network.consensusBranchId.hasOwnProperty(this.tx.version)) {
throw new Error('Unsupported Zcash transaction')
}

// XXX: this might eventually become more complex depending on what the versions represent
this.tx.version = version
}
Expand Down

0 comments on commit ea496de

Please sign in to comment.