-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Segregated Witness Support - WIP #520
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
Conversation
d548668
to
636999b
Compare
ca8ae32
to
2ac407e
Compare
src/transaction.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rubensayshi it isn't python 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe yea noticed that yday, been switching between projects too much :P
@rubensayshi when is the next time you can be available on slack? It'd be good to talk over how this [and future changes] will integrate with |
@dcousens I've got slack on my phone so you can always poke me but I usually prefer keeping my weekends code-free, though this weekend is an exception and working on this PR atm :D |
src/types.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this okay to do ?
5ef44ce
to
9099951
Compare
src/address.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this should go here or in fromBase58Check
, considering the length checks are in fromBase58Check
, this code has gotten a bit akward now ...
consider one of the test vectors for fromBase58Check
we had of an address with hash length of 22, it no longer throws a 'is too long' exception and because we're unaware of network
in fromBase58Check
we can't really check if it's sane either ...
what was the original reason for seperating fromBase58Check
and putting the exceptions there?
also is fromBase58Check
considered public API? is it painful to change things?
@dcousens I was about to ask you about this, because I noticed the refactoring of a few things ... let me know if there's anything I can do! |
It would be great to get this finished and merged so it can be used on testnet. Segwit is merged to bitcoin/master and active on Bitcoin testnet. It means people can start working on integration in earnest. |
@btcdrak I'll see if I can't work towards a 10th July PR date. |
} | ||
} | ||
|
||
Transaction.prototype.hashForSignatureV2 = function (inIndex, prevOutScript, amount, hashType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was cleared up - segwit has a different signature hashing scheme which commits the input amount in the signature, amongst other changes. It has a reusable midstate for all inputs in a transaction which may be cached, so avoids the O(n^2) hashing issue.
Lots of debugging |
@@ -0,0 +1,55 @@ | |||
var bufferutils = require('./bufferutils') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather opt for something like varstruct
than go this route if possible
Ideally it'd be great to do this in 4 PRs.
|
Why are we doing such a change in this PR? |
bump |
Note for OP, BIP142 was deferred |
The witness program size was extended from 32 to max 40 bytes https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Witness_program |
@btcdrak support for SegWit scripts was already added a small while ago. #602 See https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/script.js#L209-L223 and https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/script.js#L343-L354 and https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/script.js#L382 |
Also need to disable uncompressed keys which are disallowed under segwit. |
Is that in the BIP? |
I might find some time for this coming up, the release including segwit activation is coming up pretty close. There are some breaks in the API, probably passing the sigVersion in places, and the input amount now needs to be known during signing. Mostly, sigVersion can be determined in situ, and by including the amount, the full TxOut is now a requirement for signing (previously it was just the scriptPubKey). To address the upcoming BC break, I'd suggest accepting a full txout in the signing API (eg, |
That's the first I've seen of that, but again, my attention has been diverted? Any references? @afk11 do you have a medium with which we can collaborate on that effort more closely? |
I think the 'motivation' is scenarios like a Trezor being fed the wrong UTXO amount, since it blindly signs. If we commit the amount in the sig-hash, full nodes would reject a signature where the wrong amount was used. https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification I'm starting to think for a signing API, the requirements (bar keypairs) are the InferencesI notice for P2SH the library infers prevOutScript based on the redeemScript. It could probably do this based with segwit scripts too, although I prefer requiring the full TxOut from users always, and only optionally taking a redeemScript / witnessScript. Core doesn't infer things, it works from the scriptPubKey and decides what it needs next. (Solver in script/standard.cpp) While checking p2sh?/witness?/bare-scriptPubKey? it determines "is it a standard type, and what sighash sigVersion do I use?". P2SH / P2WSH are treated specially, and involve checking elsewhere to see that the hashes match and another call to Solver. Probably not a major issue, but I like there being a chain of hashes indicating which
Core's slack could work, otherwise happy to use email / XMPP at me$(at)$(IRL name)$(dot)io |
Interestingly, I'd prefer to move more to |
Ah ok :) I suppose the main reason would be to keep signing atomic - given a transaction, signing only takes so much Whether we pass all the arguments at signing, or all the arguments at addInput probably doesn't matter, but at least keep it pure, since I don't see any other method to set the prevOutScript (except for directly modifying internal values). I guess my disagreement stems from (i) it being split across two functions and, (ii) we're saving state anticipating it will only be used in that later function, so why not provide it only when necessary? Also believe the scriptPubKey should be the thing you check a redeemScript against to test suitability when signing, rather than inferring a scriptPubKey from an arbitrary redeemScript and signing with it. I really like how Core work out what to sign with given only a scriptPubKey and it's key/script store: https://github.com/bitcoin/bitcoin/blob/master/src/script/sign.cpp#L139 < /opinion> |
As discussed on slack, we should set up an example somewhere that idiomatically shows |
Updated milestone to |
WORK IN PROGRESS
getting shit to work before making it pretty; almost done with getting shit to work!
depends on: #540
first time spending a p2wpkh (6a539927494f3d6f07078dd1c70a28e0c4910662593072305529eaa66257f59d) and p2wpkh as p2sh (4704de796b8ea819f262eb3399fad85b838327497639da2ceafbd04a08a06be3) with bitcoinjs-lib :D
ToDo
toBuffer
should be able to return both segwit and non-segwit TXgetTxId
using the segwit TX atmvalue
arg toaddInput
and use it inTransactionBuilder.sign
instead ofvalue
arg there?TransactionBuilder.sign
TransactionBuilder.extractInput
/script.classifyInput
hashPrevouts
,hashSequence
andhashOutputs
for all signatures in a transaction (since that was one of the main reasons for changing the signatureHash xD)Usage
Signing Native P2WPKH
Signing P2WPKH nested in P2SH
References