CityOfZion / neo-python

Python Node and SDK for the NEO 2.x blockchain. For NEO 3.x go to our successor project neo-mamba
https://neo-python.readthedocs.io/en/latest/
MIT License
313 stars 189 forks source link

fix RIGHT and LEFT VM opcodes #1005

Closed ixje closed 5 years ago

ixje commented 5 years ago

What current issue(s) does this address, or what feature is it adding? audit of mainnet block 3602763 showed a deviation in gas consumption due to an incorrect implementation of the RIGHT VM opcode. The existing JSON tests also do not cover this. A 0 count operand should result in an empty buffer, the existing implementation used buffer[-count:] which worked fine as long as the count > 0. For the specific case of 0 it would actually return the full buffer instead of an empty buffer as needed. This would return incorrect lenghts, causing an LT->JMPIF sequence to point the IP to the wrong next instruction.

How did you solve this problem? fix implementation to be explicit. Also addressed possible issue with similar logic for the LEFT instruction.

How did you make sure your solution works? audit of the given block now passes.

Are there any special changes in the code that we should be aware of? no

Please check the following, if applicable:

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.001%) to 85.307% when pulling ca04c0be308acbdf6e5a4782e0ad6f878f57928d on ixje:fix-right-opcode into 0ea2fc5e528cdb98037baa145ad4de3663498cb8 on CityOfZion:development.