Questions tagged [evm]

EVM is the Ethereum Virtual Machine, the protected, distributed "sandbox area" (virtual machine) where contract execution occurs, replicated on every node in the network. EVM is also the name of the bytecode that runs on the virtual machine -- what Solidity, Serpent and LL get compiled down to before deployment.

Filter by
Sorted by
Tagged with
88
votes
7answers
37k views

What is an ABI and why is it needed to interact with contracts?

ABI is referenced in many places including the official Ethereum website. What is an ABI and why is it necessary to use?
59
votes
2answers
18k views

Difference between CALL, CALLCODE and DELEGATECALL

CALL and CALLCODE take the same number of operands (in the execution stack). For the exception flag being pushed on top of the stack: 0 means exception, 1 means successful execution. CALL is easy to ...
57
votes
2answers
20k views

What OPCODES are available for the Ethereum EVM?

The Ethereum virtual machine has a large number of operation codes and base level instruction sets. Is a complete listing available?
52
votes
5answers
13k views

How can you decompile a smart contract?

On the blockchain I can inspect the code of a contract, and see the EVM opcodes. Is there a way to decompile this and convert it back to (Solidity) source code?
40
votes
3answers
10k views

How were gas costs chosen for the Ethereum Virtual Machine instructions?

Different instructions of the EVM have different associated gas costs -- you can look at the list of the gas-prices in the appendix G of the yellow paper. While the rough magnitudes of those numbers ...
34
votes
2answers
3k views

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

The Yellow Paper states: These are four so-called ‘precompiled’ contracts, meant as a preliminary piece of architecture that may later become native extensions. The four contracts in addresses ...
30
votes
3answers
8k views

Difference between Memory and Storage?

What is the difference between Memory and Storage ? From both the EVM point of view and the contract design one. Thanks!
29
votes
3answers
3k views

What was the reason to invent the EVM?

What was the reason to invent the Ethereum Virtual Machine (EVM)? Why not use an existing virtual machine like the Java-VM. The big advantage would be that the existing toolsets for Java development ...
25
votes
1answer
10k views

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

The EVM instructions are in the yellow paper, or they are summed up in this answer. But their gas costs are not there. Where can I find a list of all instructions with their associated gas costs?
24
votes
4answers
6k views

Does every node execute the contract code for each transaction?

This question was asked on Reddit a while ago: When a node sends a transaction to the network and has the receiver as a contract, does every node execute the contract bytecode with the inputs to ...
23
votes
4answers
4k views

Why does a Solidity throw consume all gas?

When you throw an exception, all gas is consumed. What is the rationale for this design decision?
22
votes
1answer
4k views

When can BLOCKHASH be safely used for a random number? When would it be unsafe?

I've seen more complicated ways for a contract to generate a random number. But the Ethereum Yellow Paper itself suggests a "trivial solution" using the BLOCKHASH opcode (see below, bold is mine). ...
21
votes
1answer
2k views

How does the solidity optimizer work?

The compiler for solidity supports the flag --optimize which performs some set of optimizations to the compiled solidity code, typically resulting in a reduction of gas costs. How does the optimizer ...
20
votes
2answers
1k views

What type of operations have negative gas costs?

I understand that some operations cost negative gas because they free up space on the blockchain, such as selfdestructs. What are all the operations that can have negative gas? Does this only occur ...
19
votes
1answer
2k views

Are events permanently stored and reliably available to contracts in the future?

I've seen this forum post about using Ethereum as an event store: Events in Solidity, using blockchain as eventstore. However, it doesn't seem conclusive. For instance it says: I confirmed with ...
17
votes
2answers
4k views

Contract reading a string returned by another contract

I have 2 contracts, Parents and Child which has a public string variable - name. contract Child { string public name; function child (string _name){ name = _name; } } Parents ...
17
votes
1answer
628 views

Out of Gas invoking precompiled contracts on private blockchains

Why do precompiled contracts lead to Out of Gas on private blockchains? Some tidbits are provided in the Solidity docs but can it be explained more? It might be that you run into Out-of-Gas for ...
16
votes
3answers
3k views

How does a contract find out if another address is a contract?

Is it possible, from within a contract written in Solidity, to check if a contract is placed on a specific address or if this address does not contain any code?
16
votes
3answers
2k views

What are the limits to gas refunds?

Gas refunds are provided when clearing storage or calling SELFDESTRUCT on contracts. The Yellow Paper mentions that refunds are "being capped up to a maximum of half...". What exactly is this "half" ...
16
votes
1answer
3k views

Instrumenting EVM

I need to get all contract internal transactions. To do it, I'll need to instrument Ethereum EVM. My question is: what I should do to get the transaction details? Right now, I'm looking to the code ...
16
votes
2answers
1k views

What does bytecode of blank contract do?

When I compile a blank contract: contract A {} with solc --optimize --optimize-runs 300000 --opcodes test.sol I get: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x6 DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY ...
16
votes
2answers
2k views

Why are local variables allocated to storage instead of memory?

Local variables (i.e. variables declared inside functions) are held in persistent storage by default instead of non-persistent memory (source). The value of a local variable can not persist in ...
15
votes
1answer
5k views

Usage of memory, storage and stack areas in EVM

In solidity contracts, I can understand that based on variable usage and expensiveness, I can determine that which one should use (memory, storage or stack). But I faced some situations where only ...
14
votes
1answer
1k views

Is functional programming possible on the EVM?

Is there a technical limitation preventing functional programming on the EVM? For instance the cost of computation? I have heard that FP is "too costly". Is that correct? If it is, why? Because "...
13
votes
2answers
2k views

Can a contract access another contract's storage?

I have a contract with numerous complex structs. Is it possible for a second contract to iterate over this data directly? I can't really use public accessor/getter methods as it's not possible to use ...
13
votes
1answer
1k views

How does EIP 150 change the call depth attack?

It seems that EIP 150 (https://github.com/ethereum/EIPs/issues/150) introduced a more expensive gas based restriction on the call stack and completely removed the previous 1024 hard stack limit. Is ...
12
votes
2answers
3k views

isContract function using EVM assembly to get the address' code size

My problem is that I need to make sure my contract processes only the transactions coming from EOA (externally owned accounts). For this I need to determine the type of account I'm dealing with. In ...
12
votes
2answers
788 views

Why does a simple function returning a 'string', call another contract?

This trivial contract: contract Test { function test() returns (string) { return "foobar"; } } Results in assembly code output (in the solidity web compiler) for the function 'test' ...
11
votes
3answers
3k views

what is block.timestamp

In a function, does block.timestamp record the time the transaction was processed, or the time the block.timestamp computational step was processed? Is block.timestamp the time the transaction is ...
11
votes
2answers
5k views

What does a “bad JUMPDEST” error mean?

When I send a transaction to call my contract, it's causing a bad JUMPDEST error. The Ethereum wiki says this error is caused when a JUMP instruction jumps to a location that wasn't marked as a jump ...
11
votes
1answer
323 views

How growing contract storage increases the gas spending?

I have some further questions about this and this threads. For simplicity, let's imagine that I want to create a cryptocurrency on top of ethereum. The contract that "handles" this cryptocurrency ...
11
votes
1answer
1k views

Is there a formal specification for the EVM?

The yellowpaper specifies the EVM, albeit in a fashion that favors formalism over readability: But there's no indication if this is up to date with the current state of the Ethereum ecosystem or not, ...
11
votes
1answer
2k views

How does the stack depth attack make a send() silently fail?

From a blogpost on security from Christian Reitwiessner: Because of the maximal stack depth of 1024 the new bidder can always increase the stack size to 1023 and then call bid() which will cause the ...
11
votes
1answer
3k views

What is eWASM and why is it the direction for the next version of the EVM?

eWASM was first proposed in EIP 48 with performance advantages over the EVM. Are there other advantages since the EIP was written in 2015? The initial benchmarks are also gone and are there any ...
10
votes
2answers
3k views

Is it possible to call the constructor function of an existing contract?

In theory, a constructor is just a function like any other function, but only gets called once at construction time. Because the EVM doesn't know the notion of a constructor, in theory, a constructor ...
10
votes
1answer
690 views

Why are contracts limited to only the previous 256 block hashes?

Why are contracts limited to only the previous 256 block hashes using the BLOCKHASH opcode (and corresponding functions in Solidity and Serpent)? Why does another contract, such as this, need to be ...
9
votes
3answers
4k views

How does the EVM find the entry of a called function?

I read the source code of go-ethereum and confused about how does the EVM find the entry of a called function. As the specification said, the data field in a transaction specifies the function and the ...
9
votes
4answers
435 views

What is the shortest bytecode that will publish a contract with non-zero bytecode?

Yes, it's golf. So sue me. Rules The response to getCode() should have some characters that aren’t either 0 or x. To test it out, you can use the following with a local testrpc: web3.eth....
8
votes
3answers
1k views

Create new contract via .call()

If _tois left empty, and bytecode is a new contract, should _to.call(bytecode) create a new contract ? Or is it so that when a _to address is included in the transaction then the EVM processes it as a ...
8
votes
1answer
600 views

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

Do these have a separate cost? sstore(1, 10) # first time adding a value to storage with this key sstore(1, 20) # changing the value in storage. I looked for a list of gas costs / opcodes, and the ...
8
votes
1answer
405 views

What is the cryptic part at the end of a solidity contract bytecode?

Given the following contract: pragma solidity ^0.4.11; contract Simple { bytes32 public v; function set(bytes32 _v) { v = _v; } } When disassembling, neither remix, solc or evm ...
8
votes
1answer
349 views

Smart Contract execution in Casper

Once the Casper POS update releases, will miners still be using GPU to execute smart contracts and power the EVM? My understanding is that this form of 'mining' will still exist, but it wont lead to ...
8
votes
1answer
862 views

Can a contract access the code of another contract?

Using web3.js, the EVM (bytecode) of a contract can be obtained by web3.eth.getCode(addressOfContract). Can this be performed by a contract using the address of another contract? If so, how? ...
8
votes
1answer
645 views

Are linkable ring signatures available in Ethereum?

Are transactions with ring signatures available in Ethereum? There should be as anonymity/fungibility is important. Also, I think Vitalk Buterin mentioned it may be possible to implement an EVM ...
8
votes
1answer
207 views

Extra byte in the TheDAO v1 bytecode

I tried decompiling the TheDAO v1 bytecode with disasm and it seems to fail for me. I entered the TheDAO bytecode here and found that the last instruction was [10836] PUSH16 ...
8
votes
2answers
1k views

What would be the actual gas cost of a mapping and are there any size limitations?

I want to get an estimation of how much it would cost to store arbitrarily many elements in a mapping of the form BYTES32 -> BYTES32. I see here that a STORAGEADD operation costs 20000 gas, which ...
7
votes
1answer
884 views

How to map EVM trace to contract source?

In other words, how to get "classic stacktrace" of failed transaction? E.g. we have a trace (don't look at "Missing opcode 0xfd" - its the revert instruction) and the contract solidity source. How ...
7
votes
1answer
2k views

Is there any profit from using pure and view functions modifiers?

I have a function that does not read or modify contract's state: contract C { function add(uint a, uint b) public returns (uint) { uint res = a + b; return res; } } Does it ...
7
votes
6answers
1k views

What would happen if EVM didn't exist in Ethereum?

It's not clear to me the importance of the Ethereum Virtual Machine and why it is used. So it is natural to ask what would happen if EVM didn't exist? or Ethereum didn't use it.
7
votes
2answers
2k views

Clarification of “256 bit word” semantics

EVM has "256bit words". Some cases treat strings shorter than 32 bytes (256 bits) as left-justified ascii (packed into the most significant bytes of the word). Does this mean that the word value of ...