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

Create common Interface with bitcoinj #7

Open
msgilligan opened this issue Sep 17, 2015 · 6 comments
Open

Create common Interface with bitcoinj #7

msgilligan opened this issue Sep 17, 2015 · 6 comments

Comments

@msgilligan
Copy link
Collaborator

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.

@dexX7
Copy link
Owner

dexX7 commented Sep 18, 2015

The probably closest method is Script.correctlySpends(Transaction, long, Script).

@msgilligan
Copy link
Collaborator Author

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()?

`

@msgilligan
Copy link
Collaborator Author

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?

@dexX7
Copy link
Owner

dexX7 commented Sep 19, 2015

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: dexX7/bitcoinj@2e77ad2.

There are a few outstanding issues, but I was able to pass the tests via mvn clean test.

@dexX7
Copy link
Owner

dexX7 commented Sep 28, 2015

... 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. :)

@msgilligan
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants