more accurate multisig. misc fixes.
This commit is contained in:
parent
949f8684b0
commit
2775382691
@ -1829,9 +1829,16 @@ Chain.prototype.isInitial = function isInitial() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Chain.prototype.getProgress = function getProgress() {
|
Chain.prototype.getProgress = function getProgress() {
|
||||||
|
var start, current, end;
|
||||||
|
|
||||||
if (!this.tip)
|
if (!this.tip)
|
||||||
return 0;
|
return 0;
|
||||||
return Math.min(1, this.tip.ts / (utils.now() - 40 * 60));
|
|
||||||
|
start = network.genesis.ts;
|
||||||
|
current = this.tip.ts - start;
|
||||||
|
end = utils.now() - start - 40 * 60;
|
||||||
|
|
||||||
|
return Math.min(1, current / end);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -66,8 +66,11 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.setHeader('X-Bcoin-Version', constants.USER_VERSION);
|
||||||
|
res.setHeader('X-Bcoin-Agent', constants.USER_AGENT);
|
||||||
res.setHeader('X-Bcoin-Network', network.type);
|
res.setHeader('X-Bcoin-Network', network.type);
|
||||||
res.setHeader('X-Bcoin-Version', constants.USER_AGENT);
|
res.setHeader('X-Bcoin-Height', self.node.chain.height + '');
|
||||||
|
res.setHeader('X-Bcoin-Tip', utils.revHex(self.node.chain.tip.hash));
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -182,8 +185,13 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
|
|
||||||
this.get('/', function(req, res, next, send) {
|
this.get('/', function(req, res, next, send) {
|
||||||
send(200, {
|
send(200, {
|
||||||
version: constants.USER_AGENT,
|
version: constants.USER_VERSION,
|
||||||
network: network.type
|
agent: constants.USER_AGENT,
|
||||||
|
network: network.type,
|
||||||
|
height: self.node.chain.height,
|
||||||
|
tip: utils.revHex(self.node.chain.tip.hash),
|
||||||
|
peers: self.node.pool.peers.all.length,
|
||||||
|
progress: self.node.chain.getProgress()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -413,7 +413,7 @@ MinerBlock.prototype.updateCommitment = function updateCommitment() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MinerBlock.prototype.updateCoinbase = function updateCoinbase() {
|
MinerBlock.prototype.updateCoinbase = function updateCoinbase() {
|
||||||
this.coinbase.inputs[0].script[1] = this.extraNonce.toBuffer();
|
this.coinbase.inputs[0].script[1] = bcoin.script.array(this.extraNonce);
|
||||||
this.coinbase.outputs[0].value = this.block.getReward();
|
this.coinbase.outputs[0].value = this.block.getReward();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -941,8 +941,8 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
|
|||||||
var op, val, v1, v2, v3;
|
var op, val, v1, v2, v3;
|
||||||
var n, n1, n2, n3;
|
var n, n1, n2, n3;
|
||||||
var res, key, sig, type, subscript, hash;
|
var res, key, sig, type, subscript, hash;
|
||||||
var keys, i, j, m;
|
var keys, i, j, m, ikey, isig;
|
||||||
var succ, locktime;
|
var locktime;
|
||||||
|
|
||||||
if (flags == null)
|
if (flags == null)
|
||||||
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||||
@ -1399,6 +1399,10 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
|
|||||||
key = stack.pop();
|
key = stack.pop();
|
||||||
sig = stack.pop();
|
sig = stack.pop();
|
||||||
|
|
||||||
|
subscript = this.getSubscript(lastSep);
|
||||||
|
if (version === 0)
|
||||||
|
subscript.removeData(sig);
|
||||||
|
|
||||||
if (!Script.isValidKey(key, flags))
|
if (!Script.isValidKey(key, flags))
|
||||||
throw new ScriptError('Key is not valid.', op, ip);
|
throw new ScriptError('Key is not valid.', op, ip);
|
||||||
|
|
||||||
@ -1407,10 +1411,6 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
|
|||||||
|
|
||||||
type = sig[sig.length - 1];
|
type = sig[sig.length - 1];
|
||||||
|
|
||||||
subscript = this.getSubscript(lastSep);
|
|
||||||
if (version === 0)
|
|
||||||
subscript.removeData(sig);
|
|
||||||
|
|
||||||
hash = tx.signatureHash(index, subscript, type, version);
|
hash = tx.signatureHash(index, subscript, type, version);
|
||||||
|
|
||||||
res = Script.checksig(hash, sig, key, flags);
|
res = Script.checksig(hash, sig, key, flags);
|
||||||
@ -1428,73 +1428,85 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
|
|||||||
if (!tx)
|
if (!tx)
|
||||||
throw new ScriptError('No TX passed in.', op, ip);
|
throw new ScriptError('No TX passed in.', op, ip);
|
||||||
|
|
||||||
if (stack.length < 4)
|
i = 1;
|
||||||
|
if (stack.length < i)
|
||||||
throw new ScriptError('Stack too small.', op, ip);
|
throw new ScriptError('Stack too small.', op, ip);
|
||||||
|
|
||||||
n = Script.num(stack.pop(), flags).toNumber();
|
n = Script.num(stack.top(-i), flags).toNumber();
|
||||||
|
|
||||||
if (!(n >= 1 && n <= constants.script.MAX_MULTISIG_PUBKEYS))
|
if (!(n >= 0 && n <= constants.script.MAX_MULTISIG_PUBKEYS))
|
||||||
throw new ScriptError('`n` is out of bounds.', op, ip);
|
throw new ScriptError('`n` is out of bounds.', op, ip);
|
||||||
|
|
||||||
if (stack.length < n + 1)
|
opCount += n;
|
||||||
|
|
||||||
|
if (opCount > constants.script.MAX_OPS)
|
||||||
|
throw new ScriptError('Too many ops.', op, ip);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
ikey = i;
|
||||||
|
i += n;
|
||||||
|
|
||||||
|
if (stack.length < i)
|
||||||
throw new ScriptError('`n` exceeds stack size.', op, ip);
|
throw new ScriptError('`n` exceeds stack size.', op, ip);
|
||||||
|
|
||||||
keys = [];
|
m = Script.num(stack.top(-i), flags).toNumber();
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
key = stack.pop();
|
|
||||||
|
|
||||||
if (!Script.isValidKey(key, flags))
|
if (!(m >= 0 && m <= n))
|
||||||
throw new ScriptError('Key is not valid.', op, ip);
|
|
||||||
|
|
||||||
keys.push(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
m = Script.num(stack.pop(), flags).toNumber();
|
|
||||||
|
|
||||||
if (!(m >= 1 && m <= n))
|
|
||||||
throw new ScriptError('`m` is out of bounds.', op, ip);
|
throw new ScriptError('`m` is out of bounds.', op, ip);
|
||||||
|
|
||||||
if (stack.length < m)
|
i++;
|
||||||
|
isig = i;
|
||||||
|
i += m;
|
||||||
|
|
||||||
|
if (stack.length < i)
|
||||||
throw new ScriptError('`m` exceeds stack size.', op, ip);
|
throw new ScriptError('`m` exceeds stack size.', op, ip);
|
||||||
|
|
||||||
subscript = this.getSubscript(lastSep);
|
subscript = this.getSubscript(lastSep);
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
for (j = 0; j < m; j++) {
|
||||||
sig = stack.get(stack.length - 1 - i);
|
sig = stack.top(-isig - j);
|
||||||
if (version === 0)
|
if (version === 0)
|
||||||
subscript.removeData(sig);
|
subscript.removeData(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
succ = 0;
|
res = true;
|
||||||
for (i = 0, j = 0; i < m; i++) {
|
while (res && m > 0) {
|
||||||
sig = stack.pop();
|
sig = stack.top(-isig);
|
||||||
|
key = stack.top(-ikey);
|
||||||
|
|
||||||
if (!Script.isValidSignature(sig, flags))
|
if (!Script.isValidSignature(sig, flags))
|
||||||
throw new ScriptError('Signature is not valid.', op, ip);
|
throw new ScriptError('Signature is not valid.', op, ip);
|
||||||
|
|
||||||
type = sig[sig.length - 1];
|
if (!Script.isValidKey(key, flags))
|
||||||
|
throw new ScriptError('Key is not valid.', op, ip);
|
||||||
|
|
||||||
|
type = sig[sig.length - 1];
|
||||||
hash = tx.signatureHash(index, subscript, type, version);
|
hash = tx.signatureHash(index, subscript, type, version);
|
||||||
|
|
||||||
res = false;
|
if (Script.checksig(hash, sig, key, flags)) {
|
||||||
for (; !res && j < n; j++)
|
isig++;
|
||||||
res = Script.checksig(hash, sig, keys[j], flags);
|
m--;
|
||||||
|
}
|
||||||
|
|
||||||
if (res)
|
ikey++;
|
||||||
succ++;
|
n--;
|
||||||
|
|
||||||
|
if (m > n)
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (i-- > 1)
|
||||||
|
stack.pop();
|
||||||
|
|
||||||
if (stack.length < 1)
|
if (stack.length < 1)
|
||||||
throw new ScriptError('No dummy present.', op, ip);
|
throw new ScriptError('No dummy present.', op, ip);
|
||||||
|
|
||||||
val = stack.pop();
|
|
||||||
|
|
||||||
if (flags & constants.flags.VERIFY_NULLDUMMY) {
|
if (flags & constants.flags.VERIFY_NULLDUMMY) {
|
||||||
if (!Script.isDummy(val))
|
if (!Script.isDummy(stack.top(-1)))
|
||||||
throw new ScriptError('Dummy did not verify.', op, ip);
|
throw new ScriptError('Dummy did not verify.', op, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = succ >= m;
|
stack.pop();
|
||||||
|
|
||||||
if (op === opcodes.OP_CHECKMULTISIGVERIFY) {
|
if (op === opcodes.OP_CHECKMULTISIGVERIFY) {
|
||||||
if (!res)
|
if (!res)
|
||||||
@ -2427,6 +2439,9 @@ Script.prototype.isMultisig = function isMultisig() {
|
|||||||
if (n == null)
|
if (n == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (n < 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
m = Script.getSmall(this.code[0]);
|
m = Script.getSmall(this.code[0]);
|
||||||
|
|
||||||
if (m == null)
|
if (m == null)
|
||||||
|
|||||||
@ -375,8 +375,8 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
copy.inputs.push({
|
copy.inputs.push({
|
||||||
prevout: this.inputs[i].prevout,
|
prevout: this.inputs[i].prevout,
|
||||||
script: this.inputs[i].script.clone(),
|
script: this.inputs[i].script,
|
||||||
witness: this.inputs[i].witness.clone(),
|
witness: this.inputs[i].witness,
|
||||||
sequence: this.inputs[i].sequence
|
sequence: this.inputs[i].sequence
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
for (i = 0; i < this.outputs.length; i++) {
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
copy.outputs.push({
|
copy.outputs.push({
|
||||||
value: this.outputs[i].value,
|
value: this.outputs[i].value,
|
||||||
script: this.outputs[i].script.clone()
|
script: this.outputs[i].script
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user