Hot answers tagged

99 votes
Accepted

What OPCODES are available for the Ethereum EVM?

All of the opcodes and their complete descriptions are available in the Ethereum Yellow paper. For convenience, though, I've made a handy reference list of them all: 0s: Stop and Arithmetic Operations ...
user avatar
53 votes
Accepted

How can you decompile a smart contract?

Compilation back to the original source code is impossible because all variable names, type names and even function names are removed. It might be technically possible to arrive at some source code ...
user avatar
  • 3,212
43 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. ...
user avatar
  • 78.7k
36 votes

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

Even though I do not know the real reason, I will try to guess. There would be the following considerations: Size of the namespace. There are not so many possible opcodes, so these need to be ...
user avatar
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 ...
user avatar
  • 8,702
14 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 ...
user avatar
  • 8,702
13 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 ...
user avatar
  • 17.6k
12 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 ...
user avatar
  • 78.7k
12 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 ...
user avatar
  • 10.8k
11 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 ...
user avatar
  • 1,516
10 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 ...
user avatar
  • 34.4k
9 votes

Can a contract access the code of another contract?

The Yellow Paper mentions an EVM opcode EXTCODECOPY which copies an account's code to memory. The answer appears to be yes: a contract can access the code of another contract. Solidity 0.3.1 now ...
user avatar
  • 78.7k
9 votes
Accepted

Are linkable ring signatures available in Ethereum?

In a January 15 2016 blog post, Vitalik mentions: Ring signatures are more mathematically involved than simple signatures, but they are quite practical to implement; some sample code for ring ...
user avatar
  • 78.7k
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 ...
user avatar
  • 8,702
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 ...
user avatar
7 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 ...
user avatar
  • 3,212
7 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 ...
user avatar
7 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.
user avatar
  • 401
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/
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 ...
user avatar
  • 8,702
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 *...
user avatar
  • 3,426
6 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 ...
user avatar
  • 463
5 votes

What are the two arguments to a RETURN opcode?

The 2 arguments to the RETURN opcode are offsets into memory: the starting and ending offset. The EVM execution is stopped and data consisting of the memory bytes from [start, end-1] are the output ...
user avatar
  • 78.7k
5 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 ...
user avatar
  • 421
5 votes
Accepted

How are storage pointers implemented in the EVM layer?

Yes, the compiler handles the pointer functionality. You do not need to explicitly de-reference a storage pointer when you want to write to or read from the storage location it points to. I think the ...
user avatar
  • 9,157
5 votes
Accepted

Solidity 0.6.0 address(this).balance throws error invalid opcode

I managed to fix it by explicitly defining the EVM version in my truffle config file. It's still weird because Remix supports this (as seen in the attached image) as well but still fails. compilers:...
user avatar
  • 1,122
5 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 ...
user avatar
  • 10.8k
4 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=...
user avatar
  • 17.6k
4 votes

How can you decompile a smart contract?

In general as other users commented it is not possible to get back the original source code in practice. In theory, however, both compiled and source applications should produce exactly the same ...
user avatar
4 votes

Why are there missing opcodes when using the disassembler on bytecode from the blockchain?

I've written another disassembler to help me understand some of this stuff, and because I really wanted offsets beside the instructions. You can find it here. https://github.com/jamiehale/evm_disasm
user avatar
  • 1,005

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