LearnBitcoin

Bitcoin Dev Archive 2012

script tests - invalid script in script_valid.json?

9 messages, 29 to 31 Jul 2012. Started by Amir Taaki.

Amir Taaki (3), Stefan Thomas (2), Jeff Garzik, Gavin Andresen, Pieter Wuille, Matt Corallo

Permalink Original thread on gnusha.org

Amir Taaki permalink original

Hi!

Is this a valid script?

["1 0 1", "WITHIN NOT"]

The first value (1) is tested to make sure it is between the lower (0) and upper (1) value. This evaluates to true, placing on the stack a single byte of [01]. NOT then inverses this to a 0 byte false value of [].

What am I missing here?

Thanks

Stefan Thomas in reply to Amir Taaki permalink original

OP_WITHIN is lower-bound-inclusive, but upper bound exclusive, so 1 0 1 WITHIN is false.

bool fValue = (bn2 <= bn1 && bn1 < bn3);

https://github.com/bitcoin/bitcoin/blob/master/src/script.cpp#L854

On 7/29/2012 6:31 PM, Amir Taaki wrote:

Quoted text (23 lines)
> Hi!
>
> Is this a valid script?
>
> ["1 0 1", "WITHIN NOT"]
>
> The first value (1) is tested to make sure it is between the lower (0) and upper (1) value. This evaluates to true, placing on the stack a single byte of [01]. NOT then inverses this to a 0 byte false value of [].
>
> What am I missing here?
>
> Thanks
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Bitcoin-development mailing list
> Bitcoin-development@lists•sourceforge•net
> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>
Amir Taaki in reply to Stefan Thomas permalink original

oh, bitcoin...

Thanks justmoon :D

----- Original Message ----- From: Stefan Thomas <moon@justmoon•de> To: bitcoin-development@lists•sourceforge•net Cc: Sent: Sunday, July 29, 2012 1:33 PM Subject: Re: [Bitcoin-development] script tests - invalid script in script_valid.json?

OP_WITHIN is lower-bound-inclusive, but upper bound exclusive, so 1 0 1 WITHIN is false.

bool fValue = (bn2 <= bn1 && bn1 < bn3);

https://github.com/bitcoin/bitcoin/blob/master/src/script.cpp#L854

On 7/29/2012 6:31 PM, Amir Taaki wrote:

Quoted text (23 lines)
> Hi!
>
> Is this a valid script?
>
> ["1 0 1", "WITHIN NOT"]
>
> The first value (1) is tested to make sure it is between the lower (0) and upper (1) value. This evaluates to true, placing on the stack a single byte of [01]. NOT then inverses this to a 0 byte false value of [].
>
> What am I missing here?
>
> Thanks
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Bitcoin-development mailing list
> Bitcoin-development@lists•sourceforge•net
> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>
Stefan Thomas in reply to Amir Taaki permalink original

I was baffled by this exact script, too. :)

Big props to Gavin for adding those data-driven test cases. I can't overstate how useful they are.

Is there interest to port more tests (P2SH, checksig, checkmultisig, block verification, maybe even DoS rules) into data-driven format? It might be something that I'd like to help with if pull requests in that direction are welcome.

On 7/29/2012 6:42 PM, Amir Taaki wrote:

Quoted text (68 lines)
> oh, bitcoin...
>
> Thanks justmoon :D
>
>
>
> ----- Original Message -----
> From: Stefan Thomas <moon@justmoon•de>
> To: bitcoin-development@lists•sourceforge•net
> Cc:
> Sent: Sunday, July 29, 2012 1:33 PM
> Subject: Re: [Bitcoin-development] script tests - invalid script in script_valid.json?
>
> OP_WITHIN is lower-bound-inclusive, but upper bound exclusive, so 1 0 1 WITHIN is false.
>
>
> bool fValue = (bn2 <= bn1 && bn1 < bn3);
>
> https://github.com/bitcoin/bitcoin/blob/master/src/script.cpp#L854
>
> On 7/29/2012 6:31 PM, Amir Taaki wrote:
>> Hi!
>>
>> Is this a valid script?
>>
>> ["1 0 1", "WITHIN NOT"]
>>
>> The first value (1) is tested to make sure it is between the lower (0) and upper (1) value. This evaluates to true, placing on the stack a single byte of [01]. NOT then inverses this to a 0 byte false value of [].
>>
>> What am I missing here?
>>
>> Thanks
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Bitcoin-development mailing list
>> Bitcoin-development@lists•sourceforge•net
>> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Bitcoin-development mailing list
> Bitcoin-development@lists•sourceforge•net
> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Bitcoin-development mailing list
> Bitcoin-development@lists•sourceforge•net
> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>
Jeff Garzik in reply to Stefan Thomas permalink original

On Sun, Jul 29, 2012 at 1:35 PM, Stefan Thomas <moon@justmoon•de> wrote:

Quoted text (2 lines)
> Big props to Gavin for adding those data-driven test cases. I can't
> overstate how useful they are.

+1 they are a useful, cross-platform test tool.

pynode will be making use of them shortly.

Gavin Andresen in reply to Stefan Thomas permalink original
Quoted text (4 lines)
> Is there interest to port more tests (P2SH, checksig, checkmultisig,
> block verification, maybe even DoS rules) into data-driven format? It
> might be something that I'd like to help with if pull requests in that
> direction are welcome.

Yes, more tests are definitely welcome.

check*sig tests are tricky, because they have to refer to previous unspent transactions and private keys (so require a particular block chain to test against). Brilliant ideas on a simple data-driven format welcome.

block verification tests would be great; a collection of good/bad block chains, starting from a common chain (maybe the testnet3 tesnet-in-a-box chain) would be very useful for regression testing.

Amir Taaki in reply to Gavin Andresen permalink original

Yep, I want to chip in and also express my gratitude for these useful tests. I sent a personal email to Gavin before.

I plan to make some more complex tests by combining several of the simpler ones.

----- Original Message ----- From: Gavin Andresen <gavinandresen@gmail•com> To: Stefan Thomas <moon@justmoon•de> Cc: bitcoin-development@lists•sourceforge•net Sent: Sunday, July 29, 2012 9:52 PM Subject: Re: [Bitcoin-development] script tests - invalid script in script_valid.json?

Quoted text (4 lines)
> Is there interest to port more tests (P2SH, checksig, checkmultisig,
> block verification, maybe even DoS rules) into data-driven format? It
> might be something that I'd like to help with if pull requests in that
> direction are welcome.

Yes, more tests are definitely welcome.

check*sig tests are tricky, because they have to refer to previous unspent transactions and private keys (so require a particular block chain to test against). Brilliant ideas on a simple data-driven format welcome.

block verification tests would be great; a collection of good/bad block chains, starting from a common chain (maybe the testnet3 tesnet-in-a-box chain) would be very useful for regression testing.

Pieter Wuille in reply to Gavin Andresen permalink original

On Mon, Jul 30, 2012 at 2:52 AM, Gavin Andresen <gavinandresen@gmail•com> wrote:

Quoted text (4 lines)
> check*sig tests are tricky, because they have to refer to previous
> unspent transactions and private keys (so require a particular block
> chain to test against). Brilliant ideas on a simple data-driven format
> welcome.

Ultraprune changes the block validation mechanism to only use a set of coins and the latest block pointer as state. This state is represented by an abstract class with several implementations. It would be easy to have a testset run with a memory-backed coin set as state, with the list of coins and blocks loaded from a file.

Matt Corallo in reply to Gavin Andresen permalink original

On Sun, 2012-07-29 at 20:52 -0400, Gavin Andresen wrote:

Quoted text (16 lines)
> > Is there interest to port more tests (P2SH, checksig, checkmultisig,
> > block verification, maybe even DoS rules) into data-driven format? It
> > might be something that I'd like to help with if pull requests in that
> > direction are welcome.
>
> Yes, more tests are definitely welcome.
>
> check*sig tests are tricky, because they have to refer to previous
> unspent transactions and private keys (so require a particular block
> chain to test against). Brilliant ideas on a simple data-driven format
> welcome.
>
> block verification tests would be great; a collection of good/bad
> block chains, starting from a common chain (maybe the testnet3
> tesnet-in-a-box chain) would be very useful for regression testing.
>

I wrote a simple block chain tester (that is capable of forking, checking invalid blocks, etc) as a part of the bitcoinj test suite. Its more targeted at testing bitcoinj directly and keeping the bitcoinj test suite light weight, so if it were to be more generic some tweaks could be done (not requiring tweaking the minimum difficulty/genesis block hash/etc would be first). It doesn't have that many test cases yet, but it is capable of sanity-testing reorgs/etc. Its mostly the first two commits listed at http://code.google.com/r/bluemattme-bitcoinj/source/list?name=fullverif

Matt