fix findanddelete.

This commit is contained in:
Christopher Jeffrey 2016-04-27 20:50:04 -07:00
parent 62bab2bf32
commit f2a35c46c2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 52 additions and 21 deletions

View File

@ -965,8 +965,8 @@ Script.prototype.removeSeparators = function removeSeparators() {
var i; var i;
for (i = 0; i < this.code.length; i++) { for (i = 0; i < this.code.length; i++) {
// NOTE: We do not check for bad pushes here. Bad if (Script.isBadPush(this.code[i]))
// pushes may have been created by FindAndDelete(). break;
if (this.code[i] !== opcodes.OP_CODESEPARATOR) if (this.code[i] !== opcodes.OP_CODESEPARATOR)
code.push(this.code[i]); code.push(this.code[i]);
} }
@ -1954,7 +1954,7 @@ Script.array = function(value) {
Script.prototype.removeData = function removeData(data) { Script.prototype.removeData = function removeData(data) {
var total = 0; var total = 0;
var p, sig, raw, i, a, b; var p, sig, raw, i, a, b, op, size;
// We need to reserialize the // We need to reserialize the
// signature as a minimal push // signature as a minimal push
@ -1991,16 +1991,46 @@ Script.prototype.removeData = function removeData(data) {
// Compare on the byte level. // Compare on the byte level.
raw = this.encode(); raw = this.encode();
// Note that this is _faster_ than Buffer#indexOf. p = new BufferReader(raw, true);
for (i = 0; i < raw.length; i++) {
if (raw.length - i < sig.length) while (p.left() >= sig.length) {
break; if (utils.icmp(raw, sig, p.offset) === 0) {
if (utils.icmp(raw, sig, i) === 0) { a = raw.slice(0, p.offset);
a = raw.slice(0, i); b = raw.slice(p.offset + sig.length);
b = raw.slice(i + sig.length);
raw = Buffer.concat([a, b]); raw = Buffer.concat([a, b]);
p.data = raw;
total++; total++;
} }
if (p.left() === 0)
break;
op = p.readU8();
if (op >= 0x01 && op <= 0x4b) {
if (p.left() < op)
break;
} else if (op === opcodes.OP_PUSHDATA1) {
if (p.left() < 1)
break;
size = p.readU8();
if (p.left() < size)
break;
p.seek(size);
} else if (op === opcodes.OP_PUSHDATA2) {
if (p.left() < 2)
break;
size = p.readU16();
if (p.left() < size)
break;
p.seek(size);
} else if (op === opcodes.OP_PUSHDATA4) {
if (p.left() < 4)
break;
size = p.readU32();
if (p.left() < size)
break;
p.seek(size);
}
} }
if (total > 0) { if (total > 0) {
@ -3374,16 +3404,13 @@ Script.format = function format(code) {
var op, size; var op, size;
if (Buffer.isBuffer(chunk)) { if (Buffer.isBuffer(chunk)) {
op = chunk.op; op = chunk.opcode;
if (op == null) { if (op == null) {
if (chunk.length === 0) { if (chunk.length === 0) {
op = opcodes.OP_0; op = opcodes.OP_0;
} else if (chunk.length <= 0x4b) { } else if (chunk.length <= 0x4b) {
if (chunk.length === 1) { if (chunk.length === 1) {
if (chunk[0] === 0) { if (chunk[0] >= 1 && chunk[0] <= 16) {
op = opcodes.OP_0;
return constants.opcodesByVal[op];
} else if (chunk[0] >= 1 && chunk[0] <= 16) {
op = chunk[0] + 0x50; op = chunk[0] + 0x50;
return constants.opcodesByVal[op]; return constants.opcodesByVal[op];
} else if (chunk[0] === 0x81) { } else if (chunk[0] === 0x81) {

View File

@ -1513,6 +1513,8 @@ TX.prototype.isWatched = function isWatched(bloom) {
for (i = 0; i < code.length; i++) { for (i = 0; i < code.length; i++) {
chunk = code[i]; chunk = code[i];
if (Script.isBadPush(chunk))
break;
if (!Buffer.isBuffer(chunk) || chunk.length === 0) if (!Buffer.isBuffer(chunk) || chunk.length === 0)
continue; continue;
if (bloom.test(chunk)) if (bloom.test(chunk))

View File

@ -51,6 +51,8 @@ function createGenesisBlock(options) {
locktime: 0 locktime: 0
}; };
tx.inputs[0].script.code[1].opcode = 1;
txRaw = bcoin.protocol.framer.tx(tx); txRaw = bcoin.protocol.framer.tx(tx);
tx._raw = txRaw; tx._raw = txRaw;
tx._size = txRaw.length; tx._size = txRaw.length;
@ -117,7 +119,7 @@ var segnet3 = createGenesisBlock({
var segnet4 = createGenesisBlock({ var segnet4 = createGenesisBlock({
version: 1, version: 1,
ts: 1452831101, ts: 1452831101,
bits: utils.toCompact(network.segnet4.powLimit), bits: utils.toCompact(network.segnet4.pow.limit),
nonce: 0 nonce: 0
}); });
@ -126,15 +128,15 @@ utils.print(testnet);
utils.print(regtest); utils.print(regtest);
utils.print(segnet3); utils.print(segnet3);
utils.print('main hash: %s', utils.revHex(main.hash)); utils.print('main hash: %s', utils.revHex(main.hash));
utils.print('main raw: %s', utils.toHex(main._raw)); utils.print('main raw: %s', main._raw.toString('hex'));
utils.print(''); utils.print('');
utils.print('testnet hash: %s', utils.revHex(testnet.hash)); utils.print('testnet hash: %s', utils.revHex(testnet.hash));
utils.print('testnet raw: %s', utils.toHex(testnet._raw)); utils.print('testnet raw: %s', testnet._raw.toString('hex'));
utils.print(''); utils.print('');
utils.print('regtest hash: %s', utils.revHex(regtest.hash)); utils.print('regtest hash: %s', utils.revHex(regtest.hash));
utils.print('regtest raw: %s', utils.toHex(regtest._raw)); utils.print('regtest raw: %s', regtest._raw.toString('hex'));
utils.print('segnet3 hash: %s', utils.revHex(segnet3.hash)); utils.print('segnet3 hash: %s', utils.revHex(segnet3.hash));
utils.print('segnet3 raw: %s', utils.toHex(segnet3._raw)); utils.print('segnet3 raw: %s', segnet3._raw.toString('hex'));
utils.print('segnet4 hash: %s', utils.revHex(segnet4.hash)); utils.print('segnet4 hash: %s', utils.revHex(segnet4.hash));
utils.print('segnet4 raw: %s', utils.toHex(segnet4._raw)); utils.print('segnet4 raw: %s', segnet4._raw.toString('hex'));
utils.print(segnet4); utils.print(segnet4);