Open msgilligan opened 9 years ago
The probably closest method is Script.correctlySpends(Transaction, long, Script).
So can (and should) we create a Java interface that could be implemented by two adapters: one for BitcoinConsensus.VerifyScript()
and the other for Script.correctlySpends()
?
`
Also, a question: It appears script verification at this level does not check balances or protect against double spends. Correct?
Apparently that is the case because the tests are not being connected to a blockchain database or to the network, right?
Also, a question: It appears script verification at this level does not check balances or protect against double spends. Correct?
At this level, no. It's really the core layer, and just checks whether "some transaction script of a transactions spends an output of a previous transaction".
So can (and should) we create a Java interface that could be implemented by two adapters: one for BitcoinConsensus.VerifyScript() and the other for Script.correctlySpends()?
I think this would be awesome. Yesterday I played with BitcoinJ a bit and created a PoC to see, whether an integration might work. I copied the source (is there a handy way to include Gradle projects..?) and then I replaced Script.correctlySpends(), see: https://github.com/dexX7/bitcoinj/commit/2e77ad276adbe3cb7c213d6bee1954cbd18b153c.
There are a few outstanding issues, but I was able to pass the tests via mvn clean test
.
... but I was able to pass the tests ...
Today I played around with BitcoinJ and the script tests of Bitcoin Core (script_invalid.json, script_valid.json), and I hacked together some tests to run the tests with BitcoinJ's Script.correctlySpends()
as well as BitcoinConsensus.VerifyScript()
.
Turned out about 140 tests are failing with BitcoinJ, mostly because, so I believe, BitcoinJ doesn't understand all script verification flags (and lacks the logic the flags trigger), while VerifyScript()
passed fine. BitcoinJ runs a subset of these tests, though the failing ones are not included.
This underlines the need for an integration, however, I'm not really sure how to tackle it. I'm out in a few minutes, but tomorrow I'm probably going to publish the more or less sloppy test integration, and it would be awesome, if we could build upon it. :)
Nice work. I've got my hands pretty full this week, but will take a look at it as soon as I can. Testing (and learning more about) the Bitcoin script opcodes is something I have wanted to do for a very long time.
I believe there is an experimental, full-node version of bitcoinj -- A quick search didn't find any code, though.
There is a
Transaction.verify()
method but it doesn't do complete verification the same as libbitcoinconsensus.If there is something close to full-verification in bitcoinj it would be nice to create a common interface so any Spock tests could be used to test both implementations and compare.