A vertical slice of P2SH in ElectrumSV – Roger Taylor
Let’s confirm how P2SH scripts work in the context of ElectrumSV. This is a vertical slice from the wallet down to the node through the indexing server, examining the part each plays.
ElectrumSV listens to the P2P network, which propagates the transactions miners have processed and approved and committed to blocks. So what do nodes do with transactions that include P2SH scripts?
A P2SH output script, which has to match the fixed standard structure defined in BIP16, contains the 160 bit hash of the script. It takes one item of data, hashes it and clips the hash to 160 bits. If the the data was the expected data, based on the hash, then the spend succeeds.
A P2SH input script also has a standard structure. It can only be push data operations. The last piece of data is the serialised script. The data preceding it is never passed to the output, but is instead passed to the deserialised script which is expected to execute successfully. If it does, the serialised script is then passed to the output script, and if that also executes successfully, the spend is valid.
Reference: interpreter.cpp in the Bitcoin-sv github repository.
At this time, ElectrumX mostly deals with the needs of Bitcoin Core. This means that the blockchain isn’t intended for more than superficial use, and so the indexing is limited to complete script contents. There’s no nuances of analysing what is in the script. As long as it is spendable, ElectrumX hashes it and indexes all references to scripts that match the hash.
Reference: coins.py in the ElectrumX github repository.
A wallet knows the addresses it will have incoming payments on, and currently it registers for a designated number of these. It does so by constructing the output scripts these addresses are expected to feature in, and passes the hashes of these to ElectrumX as the things it should be notified about.
That’s pretty much it. It gets notified of unspent outputs that feature an address it is interested in. It doesn’t need to evaluate scripts, because if a block is valid, then the scripts must have been evaluated successfully already. And if there is some shenanigans going on there, then a reorg will eventually clear things up. Spends are just inputs that refer to an output of interest, the contents of the input script are irrelevant.
ElectrumSV only ever touches on P2SH in the context of multi-signature scripts, so it will never ask to be notified about other kinds of P2SH transactions.
Reference: wallet.py in the ElectrumSV github repository.
Published at Thu, 05 Sep 2019 02:29:30 +0000
Bitcoin Pic Of The Moment
✅ This image from Marco Verch (trendingtopics) is available under Creative Commons 2.0. Please link to the original photo and the license. 📝 License for use outside of the Creative Commons is available by request.
By trendingtopics on 2019-04-09 13:02:44
