Skip to content

Commit

Permalink
Merge pull request #470 nodar-chkuaselidze/fix/reject-cache
Browse files Browse the repository at this point in the history
fix malleability check in mempool
  • Loading branch information
braydonf committed Feb 15, 2019
2 parents 375965c + f0023cb commit f585d86
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mempool/mempool.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ class Mempool extends EventEmitter {

// If it succeeded, segwit may be causing the
// failure. Try with segwit but without cleanstack.
flags |= Script.flags.VERIFY_CLEANSTACK;
flags |= Script.flags.VERIFY_WITNESS;

// Cleanstack was causing the failure.
if (await this.verifyResult(tx, view, flags))
Expand Down
49 changes: 49 additions & 0 deletions test/mempool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const KeyRing = require('../lib/primitives/keyring');
const Address = require('../lib/primitives/address');
const Outpoint = require('../lib/primitives/outpoint');
const Script = require('../lib/script/script');
const opcodes = Script.opcodes;
const Witness = require('../lib/script/witness');
const MemWallet = require('./util/memwallet');
const ALL = Script.hashType.ALL;
Expand Down Expand Up @@ -337,6 +338,54 @@ describe('Mempool', function() {
assert(!mempool.hasReject(tx.hash()));
});

it('should cache a non-malleated tx with non-empty stack', async () => {
// Wrap in P2SH, so we pass standardness checks.
const key = KeyRing.generate();

{
const script = new Script();
script.pushOp(opcodes.OP_1);
script.compile();
key.script = script;
}

const wallet = new MemWallet();
const script = Script.fromAddress(wallet.getAddress());
const dummyCoin = dummyInput(script, random.randomBytes(32));

// spend first output
const t1 = new MTX();
t1.addOutput(key.getAddress(), 50000);
t1.addCoin(dummyCoin);
wallet.sign(t1);

const t2 = new MTX();
t2.addCoin(Coin.fromTX(t1, 0, 0));
t2.addOutput(wallet.getAddress(), 40000);

{
const script = new Script();
script.pushOp(opcodes.OP_1);
script.pushData(key.script.toRaw());
script.compile();

t2.inputs[0].script = script;
}

await mempool.addTX(t1.toTX());

let err;
try {
await mempool.addTX(t2.toTX());
} catch (e) {
err = e;
}

assert(err);
assert(!err.malleated);
assert(mempool.hasReject(t2.hash()));
});

it('should not cache a malleated wtx with wit removed', async () => {
const key = KeyRing.generate();

Expand Down

0 comments on commit f585d86

Please sign in to comment.