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

evm command line interface adds leading zeros in odd-length input #24711

Closed
omelancon opened this issue Apr 18, 2022 · 5 comments
Closed

evm command line interface adds leading zeros in odd-length input #24711

omelancon opened this issue Apr 18, 2022 · 5 comments
Labels

Comments

@omelancon
Copy link

omelancon commented Apr 18, 2022

I am executing the following dummy (smart) contract with evm command line.

60003500
PUSH1 0x00
CALLDATALOAD
STOP

If I provide 0x101 as input I get the expected result (EDIT: see comments below, it turns out this is not the expected result):

>>> evm --code 60003500 --input 101 --debug run
0x
#### TRACE ####
PUSH1           pc=00000000 gas=10000000000 cost=3

CALLDATALOAD    pc=00000002 gas=9999999997 cost=3
Stack:
00000000  0x0

STOP            pc=00000003 gas=9999999994 cost=0
Stack:
00000000  0x101000000000000000000000000000000000000000000000000000000000000  # AS EXPECTED

Although, if I input 0x001, the heading zeros seem to be dropped by the evm (see stack state on last line).

>>> evm --code 60003500 --input 001 --debug run
0x
#### TRACE ####
PUSH1           pc=00000000 gas=10000000000 cost=3

CALLDATALOAD    pc=00000002 gas=9999999997 cost=3
Stack:
00000000  0x0

STOP            pc=00000003 gas=9999999994 cost=0
Stack:
00000000  0x1000000000000000000000000000000000000000000000000000000000000   # NOT AS EXPECTED

I am using evm version 1.10.17-stable-25c9b49f on Linux (Pop!_OS). Why does the evm drops the leading zeros? It seems like a bug to me.

@omelancon omelancon changed the title evm command line interface drops heading zeros in input evm command line interface drops leading zeros in input Apr 19, 2022
@karalabe
Copy link
Member

The stack currently seems to print decimals, not entire word slots. e.g.

Stack:
00000000  0x0

^ this was also in your trace that does the same thing as the truncation you didn't like.

I think this is deliberate to easier interpret numbers, but maybe I'm wrong? CC @holiman

@jwasinger
Copy link
Contributor

jwasinger commented Apr 20, 2022

Weird that it accepts odd-length input (--input 101 is interpreted as 0x010100000...0 which seems strange). would it make sense to explicitly disallow this?

@holiman
Copy link
Contributor

holiman commented Apr 20, 2022

The problem is that 101 is three nibbles. We might do something "wonky" on wonky input. I agree we should just exit with "please provide full bytes input"

@omelancon
Copy link
Author

omelancon commented Apr 20, 2022

That is correct. It seems that the problem is with odd length input specifically. I initially expected the call message to be filled bitwise from left to right, but that is not exactly what happens.

Here is another minimal example, both of these commands give be the same result:

evm --code 60003500 --input 1 -debug run
evm --code 60003500 --input 01 -debug run

In both case, what is pushed in the stack is 0x0100000000000000000000000000000000000000000000000000000000000000.

So the leading is zero is not dropped in the second case. It is in fact that a leading zero is added in the first one.

@omelancon omelancon changed the title evm command line interface drops leading zeros in input evm command line interface drops adds leading zeros in odd-length input Apr 24, 2022
@omelancon omelancon changed the title evm command line interface drops adds leading zeros in odd-length input evm command line interface adds leading zeros in odd-length input Apr 24, 2022
@s1na
Copy link
Contributor

s1na commented Apr 26, 2022

@jwasinger was this fixed by #24721? can I close?

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

No branches or pull requests

5 participants