Write-up for yet EVM puzzle4

0xNorman
CoinsBench
Published in
2 min readDec 29, 2022

--

A steampunk calling on Mars

Alright, here comes our four write-up for yet another EVM puzzle, it’s the last two puzzles we have, happy hours are always short, right? Using either command line or EVM playground then here we go!

[00] PUSH1 20
[02] CALLDATASIZE
[03] GT
[04] PUSH1 21
[06] JUMPI
[07] CALLDATASIZE
[08] PUSH1 00
[0a] CALLDATASIZE
[0b] PUSH1 20
[0d] SUB
[0e] CALLDATACOPY
[0f] CALLDATASIZE
[10] DUP1
[11] PUSH1 20
[13] SUB
[14] SHA3
[15] PUSH1 e0
[17] SHR
[18] PUSH4 890d6908
[1d] EQ
[1e] PUSH1 26
[20] JUMPI
[21] JUMPDEST
[22] PUSH1 00
[24] DUP1
[25] REVERT
[26] JUMPDEST
[27] STOP

First block first

[00] PUSH1 20
[02] CALLDATASIZE
[03] GT
[04] PUSH1 21
[06] JUMPI

[21] JUMPDEST
[22] PUSH1 00
[24] DUP1
[25] REVERT

20 and CALLDATASIZE are pushed onto the stack, if data size is greater than 20, revert.

if(CALLDATASIZE > 20) revert

Second block.

[07] CALLDATASIZE 
[08] PUSH1 00
[0a] CALLDATASIZE
[0b] PUSH1 20
[0d] SUB
[0e] CALLDATACOPY
[0f] CALLDATASIZE
[10] DUP1
[11] PUSH1 20
[13] SUB
[14] SHA3
[15] PUSH1 e0
[17] SHR
[18] PUSH4 890d6908
[1d] EQ

The above codes looks long, but essentially it’s asking after copying the data into the memory, SHA3 will read it and hash it. Then if the first four bytes of our hashed value is equal to 890d6908 we are done. To be honest I am confused at first because as everyone knows SHA3 is a well known hash function and hash function is one way. It means that we cannot find the input backwards. And if we want to try out the brutal force solution it will have to try at worst 20¹⁶ times. So there gotta be a solution (since this problem is solvable). Well, the 4 bytes value remind me of the function selector, which also happens to be 4 bytes. After checking the Ethereum signature database we find that it’s the ‘solve()’ signature.

Then using the hex version of solve(): 0x736f6c76652829

CALLDATA:0x736f6c76652829

We are done! Thanks ᴍatías Λereal Λeón ⚡

--

--