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

check v before ecrecover #105

Merged
merged 1 commit into from
May 9, 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
7 changes: 4 additions & 3 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ export default class Input {
const r = buf.slice(33 + off, 65 + off);
const s = buf.slice(65 + off, 97 + off);
const v = buf.readUInt8(97 + off);
const signer = Input.recoverSignerAddress(sigHashBuf, v, r, s);

input.setSig(r, s, v, signer);
if (v > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we just want to check v here? I assume we should check r and s to equals 0, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct :)

const signer = Input.recoverSignerAddress(sigHashBuf, v, r, s);
input.setSig(r, s, v, signer);
}

return input;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ describe('transactions', () => {
assert.equal(condition.inputs[1].signer, ADDR);
});

it('should allow to create and parse spending condition tx without signed input.', () => {
const prevTx = '0x7777777777777777777777777777777777777777777777777777777777777777';
const value = BigInt('99000000');
const color = 1337;
const condition = Tx.spendCond(
[new Input({
prevout: new Outpoint(prevTx, 0),
script: '0x123456',
}), new Input({
prevout: new Outpoint(prevTx, 1),
})
], [new Output(value, ADDR, color)],
);
condition.inputs[0].setMsgData('0xabcdef');
assert.deepEqual(Tx.fromRaw(condition.toRaw()), condition);
});

it('should allow to create and parse spending condition with different tokens', () => {
const prevTx = '0x7777777777777777777777777777777777777777777777777777777777777777';
const NFT_COLOR_BASE = 32769; // 2^15 + 1
Expand Down