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
90
votes
7answers
39k 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?
60
votes
2answers
19k 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 ...
53
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?
31
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!
25
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 ...
25
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). ...
41
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 ...
24
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?
17
votes
3answers
3k 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" ...
14
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 ...
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?
35
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 ...
17
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 ...
6
votes
2answers
795 views

Why does an empty message still invoke the code of the contract?

An empty message still invokes the code of the contract and is the mechanism that allows Solidity to implement a feature of a fallback function per contract. But when msg.data is empty, why does ...
27
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?
30
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 ...
13
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 ...
6
votes
1answer
2k views

How is an ABI stored in bytecode?

I'm trying to understand how a simple hex string like 0x25d8dcf2 is enough information to execute a function in a contract. I've read up on the ABI and understand that the hex string is basically just ...
12
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 ...
15
votes
1answer
1k views

How does EIP 150 change the call depth attack?

It seems that EIP-150 introduced a more expensive gas based restriction on the call stack and completely removed the previous 1024 hard stack limit. Is this true? It seems it took cues from EIP-90 &...
18
votes
1answer
645 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 ...
5
votes
1answer
3k views

How to check the VM trace using Geth?

How to check the VM trace using Geth? I've ran geth with --verbosity 6, and stuff like this gets logged: I0525 01:26:12.418607 core/vm/vm.go:157] running byte VM b82addc7 I0525 01:26:12.419818 core/...
18
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?
21
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 ...
21
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 ...
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 ...
8
votes
1answer
439 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 ...
12
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 ...
18
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 ...
7
votes
2answers
2k views

Is it possible to access storage history from a contract in solidity?

With web3, I can access the history of the blockchain like this: web3.eth.getBalance('0x1234') // returns current balance at address 0x1234 web3.eth.getBalance('0x1234', 1000) // returns balance at ...
1
vote
1answer
348 views

On which node smart contract get executed

I have a general question in my mind please do correct me if i am thinking wrong . Suppose if i deploy the smart contract on the ethereum blockchain having a functionality to pay some tokens at ...
16
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 ...
10
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 ...
17
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 ...
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
877 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? ...
6
votes
1answer
644 views

How are contracts executed on nodes?

How are contracts executed on full nodes? Do they run one by one on first-in first-served basis, or simultaneously in the isolated environments? If they run in parallel, I guess it may exhaust the ...
8
votes
1answer
622 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 ...
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 ...
4
votes
2answers
524 views

What is the program counter at the start of an Ethereum method execution?

When a method in a deployed contract is called (either by an externally controlled account or by another smart contract), what will the program counter be at the beginning of the method call? In other ...
3
votes
1answer
652 views

Difference between STOP and INVALID opcode

STOP halts execution and according to this mentions INVALID is used as an abort. Is the difference between these opcodes purely semantical?
23
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 ...
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
1k views

Is it possible to call another contract from a contract maintaining the msg.sender of the original caller?

Imagine that Alice calls a contract method C1 and that method calls another method in contract C2. Regularly msg.sender equals the Alice Account in the C1 method. And msg.sender equals the C1 ...
3
votes
2answers
656 views

Get variable state at specific block number

Is it possible to get a variable state at a specific block number? Let's take the balance mapping in an ERC20 contact for example. I want to know which user had what balance at a specific time (...
13
votes
2answers
799 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' ...
9
votes
1answer
213 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 ...
7
votes
1answer
3k views

Rationale behind 256-bit words in EVM

What were the design factors driving having EVM native words as 256-bit? It feels excessive, especially if one needs to process as large data set as blockchain.
3
votes
1answer
980 views

How are the arguments of the constructor encoded in the contract creation transaction?

The Ethereum ABI defines how arguments are encoded and passed when a method is called. But how are the arguments to the constructor encoded in the contract creation transaction which creates the smart ...
4
votes
1answer
765 views

How does a Solidity fallback function work with the raw CALL opcode of the EVM?

Since a fallback function is a Solidity feature, how does it work if the EVM opcode CALL is used? If msg.data is empty, how can Solidity run the fallback function? Shouldn't the EVM just transfer ...