Skip to main content
46 votes
Accepted

Is there a table of EVM instructions and their gas costs?

The Yellow Paper is actively maintained and should always be current, and it's not as easy as a table, but the gas costs are there in Appendix G. Fee Schedule and read it with Appendix H. ...
eth's user avatar
  • 86k
21 votes
Accepted

invalid opcode: opcode 0x5f not defined

This is because solidity 0.8.20 introduces the PUSH0(0x5f) opcode which is only supported on ETH mainnet and not on any other chains. That's why other chains can't find the PUSH0(0x5f) opcode and ...
Zartaj Afser's user avatar
  • 4,474
20 votes
Accepted

does using external over public in a library reduce any gas costs?

Declaring a function as external rather than public does not affect gas usage at all, neither in contracts nor in libraries. In earlier versions of Solidity, only external functions could take ...
cameel's user avatar
  • 2,251
15 votes
Accepted

Understanding solidity inline assembly code

Within the assembly code, _data is the memory address of the start of the array data. However, the first memory word (32 bytes = 0x20 bytes) is reserved for the length of the array, so we need to ...
benjaminion's user avatar
  • 9,297
15 votes
Accepted

CREATE opcode: what does it really do?

CREATE, in a way, does a built in CALL. What actually happens is that the data passed to call isn't the contract bytecode, it's the init bytecode. When CREATE opcode is executed, the EVM creates a ...
natewelch_'s user avatar
  • 12.1k
14 votes

what is block.timestamp

As per the documentation you will find timestamp of the current block in seconds since the epoch so you have a single timestamp (when it is created) per block therefore time1=time2 read more ...
Badr Bellaj's user avatar
  • 18.8k
14 votes

What's a precompiled contract and how are they different from native opcodes?

Not an authority, but I know of someone who is... From Vitalik's article, A Prehistory of the Ethereum Protocol The second was the idea of “precompiles”, solving the problem of allowing complex ...
benjaminion's user avatar
  • 9,297
14 votes
Accepted

Is the cost of updating storage different than the cost of adding to storage?

Yes, using storage has different gas costs: 20,000 gas when a value is set to non-zero from zero; 5,000 gas when writing to existing storage or setting a value to zero; and a 15,000 gas refund when a ...
eth's user avatar
  • 86k
13 votes

EVM SIGNEXTEND Opcode explanation

Awesome! That is a great way to learn about the EVM. The answer may be verbose but it will be complete. Two's Complement Two's complement is a way to represent integers in binary. It enables us to ...
foba's user avatar
  • 543
12 votes

What is the difference between the STATICCALL and CALL EVM opcodes?

Additionally, Since byzantium staticcall can be used as well. This is basically the same as call, but will revert if the called function modifies the state in any way.
Smye's user avatar
  • 491
11 votes

What does bytecode of blank contract do?

A user on Reddit kindly posted an opcode-by-opcode analysis for you: PUSH1 0x60 PUSH1 0x40 MSTORE Store 0x60 at memory location 0x40. I think this is normally used for variable indexing if you have ...
Tjaden Hess's user avatar
  • 37.2k
9 votes
Accepted

Why does PUSH1 0x60 PUSH1 x40 MSTORE store 0x60 at memory location 0x50 (and not 0x40)?

Each word in the EVM is 32 = 0x20 bytes wide, so when you use PUSH1 40 to store a word at 0x40 it fills up all the bytes up to 0x5f. The EVM uses "big-endian" format, so the least significant bytes of ...
benjaminion's user avatar
  • 9,297
9 votes

Solidity shr opcode

shr(a, b) shifts b right by a bits, so in this case it shifts the result of calldataload right by 96 bits. This code essentially takes the last 20 bytes from the calldata (a.k.a. msg.data) and removes ...
Morten's user avatar
  • 6,027
8 votes
Accepted

What does bytecode of blank contract do?

The "data" section mentioned in the yellow paper is the part that follows the PUSH instruction, i.e. the yellow paper only talks about push data. What you see in the assembly output is a higher-level ...
chriseth's user avatar
  • 3,412
8 votes

Is there a table of EVM instructions and their gas costs?

If you're looking for such a table for the purpose of golfing down contract gas cost, I'd recommend you bookmark protocol_params.go. It is good for two reasons: It is the source of truth. The gas ...
user2754799's user avatar
8 votes
Accepted

Parameters on evm opcode create

This is because memory variables are treated as pointers from in solidity assembly - and that pointer points to the start in memory of the variable. The way arrays are stored in memory in Solidity is ...
natewelch_'s user avatar
  • 12.1k
8 votes

How to implement the CREATE2 in Python

Sorted, just in case it helps anyone: @pytest.mark.parametrize('address, salt, init_code, expected_address', [ ( '0x0000000000000000000000000000000000000000', '...
vnavascues's user avatar
7 votes

what is block.timestamp

In reference to your comment about transaction timestamps, the timestamps of all transactions in a block are the same. There can be many transactions in a block, all have the same timestamp, and all ...
Thomas Jay Rush's user avatar
7 votes
Accepted

why is the EVM stack limited to 1024?

Because if it was very large, then executing a contract would be more expensive (ie, require more memory). I think 1024 was a very conservative value to be as safe as possible I think the ...
Earlz's user avatar
  • 471
7 votes
Accepted

Solidity shr opcode

The shr function is used to extract variables from the calldata. The calldata is the msg.data you're passing to the contract with the function. Imagine your calldata is this: ...
Merunas Grincalaitis's user avatar
6 votes

How can you decompile a smart contract?

There is a project Porosity now https://github.com/comaeio/porosity It's also integrated into Quorum toolchain https://www.coindesk.com/first-ethereum-decompiler-launches-jp-morgan-quorum-integration/
xvorsx's user avatar
  • 161
6 votes

Are new Opcodes approved in EIP's implemented in Solidity before they are introduced in a hardfork?

Yes, they are indeed available now in Solidity as opcodes in assembly, along with CREATE2, and you are free to use them. However, for the time-being they will just fail with "invalid opcode" if any ...
benjaminion's user avatar
  • 9,297
6 votes
Accepted

What’s the opcode chain for sending ethereum from a smart contract?

The EVM is a stack machine, so arguments to instructions are put on a stack before the instruction is executed. You can find the parameters each instruction takes as well as their order in the yellow ...
mafrasi2's user avatar
  • 938
6 votes
Accepted

How can we implement a new opcode in the Ethereum Virtual Machine.

I can only give you a general guide on how to do this: 1) Modify core/vm/instructions.go to add your instruction code, something like: func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *...
Nulik's user avatar
  • 4,061
6 votes

How to separate functions in evm bytecode?

How to separate functions in evm bytecode? Solidity will create a dispatcher block for function calls at the beginning of the bytecode. Similar to an if .. elseif .. elseif .. else Single function ...
ivicaa's user avatar
  • 7,519
6 votes

invalid opcode: opcode 0x5f not defined

0x5f is the PUSH0 opcode which Solidity 0.8.20 started generating: This compiler switches the default target EVM version to Shanghai, which means that the generated bytecode will include PUSH0 ...
eth's user avatar
  • 86k
5 votes

what is block.timestamp

block.timestamp is the value what miner decides to publish there when he or she finds a block. It is subject to some interpretation and can be skewed, though only for a while. In practice this is not ...
Mikko Ohtamaa's user avatar
5 votes

What are the two arguments to a RETURN opcode?

The 2 arguments to the RETURN opcode are a starting offset and length specifying a segment of memory. The EVM execution is stopped and data consisting of the memory bytes from [start, start+len-1] are ...
eth's user avatar
  • 86k
5 votes

How can you decompile a smart contract?

List of Modern Tools (2022 and beyond) Etherscan's Bytecode to Opcode Disassembler. EtherVM's Online Solidity Decompiler.
Paul Razvan Berg's user avatar
5 votes

How can you decompile a smart contract?

it is impossible to return back to the solidity code. you could just decode the Bytecode into opcodes. look at this exemple : https://etherscan.io/opcode-tool?a=...
Badr Bellaj's user avatar
  • 18.8k

Only top scored, non community-wiki answers of a minimum length are eligible