Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix malleability check in mempool #470

Merged
merged 2 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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