Skip to main content
Share Your Experience: Take the 2024 Developer Survey
140 votes
Accepted

Difference between CALL, CALLCODE and DELEGATECALL

DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the sending contract which needs to trust ...
eth's user avatar
  • 85.9k
56 votes
Accepted

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

This works: function isContract(address _addr) private returns (bool isContract){ uint32 size; assembly { size := extcodesize(_addr) } return (size > 0); } The assembly language that ...
Thorkil Værge's user avatar
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
  • 85.9k
34 votes
Accepted

Usage of memory, storage and stack areas in EVM

Storage Let's consider storage first. Storage is extremely expensive. It costs 20000 gas to set a storage location from zero to a value, and 5000 gas to change its value. (You do get some gas back ...
benjaminion's user avatar
  • 9,297
33 votes

What was the reason to invent the EVM?

Vitalik Buterin gave a presentation about Ethereum to Hyperledger April 28 2016 (agenda, minutes) and had this on slide 8: Buterin clarified the third point as the developer centralization observed ...
eth's user avatar
  • 85.9k
33 votes
Accepted

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

Firstly, events are not accessible to contracts. The simple answer is Yes, events are permanently stored. The nuanced answer is Yes, events are as permanent as the blockchain. It helps to realize ...
eth's user avatar
  • 85.9k
32 votes
Accepted

Instrumenting EVM

To do this, you need to define a VM log collector, which implements StructLogCollector. This function gets called on every step of the VM, and is provided with copies of the memory, stack, and ...
Nick Johnson's user avatar
  • 8,174
29 votes
Accepted

What was the reason to invent the EVM?

So the important point in your question is why a new VM and not a java VM. ok let's choose a Java VM instead, what do we get? : 1- complex and voluminous Bytecode => how to store it, in the ...
Badr Bellaj's user avatar
  • 18.8k
29 votes
Accepted

Why does ++i cost less gas than i++?

They do not work the same. i++ gets compiled to something like j = i; i = i + 1; return j while ++i gets compiled to something like i = i + 1; return i; Long story short, i++ returns the non-...
Foxxxey's user avatar
  • 4,327
26 votes

How to map EVM trace to contract source?

I went down this rabbit hole and got a proof of concept to work at the end. I can not recommend the journey. There's impedance mismatches on many levels, requiring lots of format conversions. In the ...
Remco's user avatar
  • 413
24 votes

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

Contract Defintion: Formal definition in high-level code (e.g. solidity). Compiled Contract: The contract converted to byte-code to run on the Ethereum Virtual Machine (EVM), adhering to the ...
Lee's user avatar
  • 8,558
24 votes

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

Full credit to @AnAllergyToAnalogy for the caution item. I made an example to demonstrate that a constructor will trick this method. Posting for others who might come across this thread. In practice, ...
Rob Hitchens's user avatar
  • 55.3k
24 votes
Accepted

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

If you can make your function pure, you should always make it pure. Otherwise, if you can make your function view, you should always make it view. Advantages: If you make your function pure or view, ...
Jesbus's user avatar
  • 10.5k
23 votes
Accepted

Why does a Solidity throw consume all gas?

All gas is consumed because the EVM essentially only has 1 exception: Out of Gas. To see this clearer, take a look at the difference between a "pure" exception, and an error due to bad/buggy/invalid ...
eth's user avatar
  • 85.9k
22 votes
Accepted

What is the maximum value an int and uint can store

An uint is short for uint256, so it can store 2^256 values - because it's unsigned the maximum value is 2^256-1 (zero needs one space). What is the maximum input value for function uint256 parameter? ...
Lauri Peltonen's user avatar
20 votes

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

think of "ABI" as an "API" at a low level. Think of it as the compiled version of an API (or as an API on the low level). As you know the contracts are stored as bytecodes in a binary format into ...
Badr Bellaj's user avatar
  • 18.8k
20 votes
Accepted

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

The constructor function is actually not just a regular function, and actually is called exactly once and cannot be called again. Not only does the EVM not know what a constructor is, it also doesn't ...
Tjaden Hess's user avatar
  • 37.1k
19 votes

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

Since this is security related, it's helpful to emphasize https://stackoverflow.com/questions/37644395/how-to-find-out-if-an-ethereum-address-is-a-contract: The top-voted answer with the isContract ...
eth's user avatar
  • 85.9k
19 votes

Max/min values of standard data types

I assume you mean the integer types, because those are really the only types in Solidity that have a maximum and a minimum. Solidity does not support floating point types, and most likely will never ...
Jesbus's user avatar
  • 10.5k
19 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,221
18 votes
Accepted

Rationale behind 256-bit words in EVM

Quote from Ethereum Design Rationale: 32 byte word size - the alternative is 4 or 8 byte words, as in most other architectures, or unlimited, as in Bitcoin. 4 or 8 byte words are too restrictive to ...
Fedor T.'s user avatar
  • 196
18 votes
Accepted

How does EIP 150 change the call depth attack?

The previous limit has not been removed, it's just become practically unreachable. With the new rules, the call cannot consume more than 63/64 of the gas of the parent. So if your gas is X, then N ...
mhswende's user avatar
  • 296
18 votes
Accepted

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

EDIT: The function will return false if it is invoked from a contract's constructor (because the contract has not been deployed yet). The code should be used very carefully, if at all, to avoid ...
eth's user avatar
  • 85.9k
16 votes
Accepted

How does the cost of EVM memory scale?

The gas cost of memory expansion is defined in the Yellow Paper Appendix H, as follows, G_memory is 3, and a is the number of 256-bit words (ints) allocated. For a=24^2 this comes to 3 * 576 + 648 = ...
benjaminion's user avatar
  • 9,297
15 votes
Accepted

How growing contract storage increases the gas spending?

Stored data is stored entirely in the state. None of the storage needs to be loaded into VM memory in order to execute transactions on the contract, other than those entries that your contract ...
Nick Johnson's user avatar
  • 8,174
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
  • 85.9k
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
13 votes
Accepted

How is an ABI stored in bytecode?

It's the job of the compiler to produce the correct EVM bytecode so that as you say the MethodID "piece of data will end up jumping to the appropriate address for that function in the bytecode of ...
eth's user avatar
  • 85.9k
13 votes
Accepted

Max/min values of standard data types

Updated 2020 Solidity 0.6.8 introduced min and max keywords that can now natively tell you the min and max of an expected type. From the release page: Implemented type(T).min and type(T).max for ...
Shane Fontaine's user avatar

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