Hot answers tagged

114

The ABI, Application Binary Interface, is basically how you call functions in a contract and get data back. An ABI determines such details as how functions are called and in which binary format information should be passed from one program component to the next... An Ethereum smart contract is bytecode deployed on the Ethereum blockchain. There could be ...


108

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 that the receiving contract will treat the storage well. DELEGATECALL was a new opcode that was a bug fix for CALLCODE which did not preserve msg.sender and ...


105

ABI stands for application binary interface. In general, an ABI is the interface between two program modules, one of which is often at the level of machine code. The interface is the de facto method for encoding/decoding data into/out of the machine code. In Ethereum, it's basically how you can encode Solidity contract calls for the EVM and, backwards, ...


98

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 0x00 STOP Halts execution 0x01 ADD Addition operation 0x02 MUL Multiplication operation 0x03 SUB Subtraction ...


49

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 that is similar to the original source code but that is very complicated, especially when the optimizer was used during compilation. I don't know of any tools ...


40

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. Historically: A spreadsheet of opcodes and their gas costs that Ethereum launched with are here. It has some analysis per How were gas costs chosen for the Ethereum ...


38

This works: function isContract(address _addr) private returns (bool isContract){ uint32 size; assembly { size := extcodesize(_addr) } return (size > 0); } The assembly language that all Ethereum contracts compile down to contains an opcode for this precise operation: EXTCODESIZE. This opcode returns the size of the code on an address. If ...


34

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 allocated very sparingly. The space of contract addresses, on the other hand, is practically unlimited for all practical purposes. Risk of name re-use. It is a good ...


31

I share with you the spreadsheet which explains the formula behind the gas cost of each OPCODE. Version 1.0 was created by Core Devs of Ethereum. I look forward how to articulate future updates of it. It is a meta-consensus challenge to resolve.


31

Memory is temporary. Storage is permanent. For example, you would perform intermediate computations using memory, and then save the result to storage. Details from the EVM perspective, their structure and gas costs. Storage is a key/value store where keys and values are both 32 bytes. It is sparse (like a hash table), and there are no inherent gas savings ...


31

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 that events are the result of LOG opcodes being executed in the EVM. For an analogy, "internal transactions" are derived by executing transaction data through ...


29

Just to clarify, the "trivial solution" referred to is about how to produce a series of random numbers from a single random seed. As a general rule, BLOCKHASH can only be safely used for a random number if the total amount of value resting on the quality of that randomness is lower than what a miner earns by mining a single block. To see why this is the ...


29

They are analogous to memory and hard drive storage in a computer. The contract can use any amount of memory (as long as it can pay for it of course) during executing its code, but when execution stops, the entire content of the memory is wiped, and the next execution will start fresh. The storage on the other hand is persisted into the blockchain itself, so ...


28

Vitalik Buterin gave a presentation about Ethereum to Hyperledger April 28 2016 and had this slide: EVM Requirements ● Small code size (so that very many contracts from many users can be stored by one node) ● VM security designed around running untrusted code from arbitrary parties ● Multiple implementations (for cross-checking, and to mitigate developer ...


27

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 modified parts of the storage, along with the program counter, current opcode, gas left, and other data. It's also called when an error occurs that causes a ...


27

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 for resetting a location to 0.) The reason is that a contract's storage values are stored on the blockchain forever which has a real-world cost. It's also 200 gas ...


25

The following opcodes trigger a refund SELFDESTRUCT SSTORE[x] = 0 (i.e. deletion) SELFDESTRUCT refunds 24.000 and SSTORE clear refunds 15.000 gas. The accumulated refund can not exceed half the gas used for the current context (i.e. the initial call). Let's take the following example: Current state of the contract's storage 0x00: 1 0x01: 1 And the ...


25

The optimizer seems like magic even to me. chriseth (He is the main DEV developer of solidity) would probably be in a better position to answer your question than myself. Here is an interesting high level overview though, which I hope answers your question. Everything below is from the solidity docs. Internals - the Optimizer The Solidity optimizer operates ...


23

The only two OPCODEs with negative gas costs are STORAGEKILL(-15000) and GSUICIDEREFUND(-24000). These occur when storage values are deleted or contacts are suicided. These OPCODEs grant gas refunds because they free up space in the blockchain. The prices of all OPCODEs can be found here


23

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 EVM code. Out of Gas is the former. Now there are errors such as stack underflow, invalid JUMP, and invalid opcode: they can be called "exceptions" but they ...


22

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 blockchain for which cost? (Knowing that a single java method can have a size up to 64KB) thus such VM or language isn't space-saving. 2- useless features and ...


21

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 end, my implementation still does not handle cross-contract calls. (There seems to be no way to figure out which contract address a particular program counter ...


20

Yes, the answer is quite logic. Every node has to verify the results of a transaction which invokes a smart contract. The result is that at least every full node will execute the code. The hash of the transaction isn't relevant until it is being stuffed into a merkle tree. When running the execution, all we care about is the amount of gas, the data being ...


20

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, you can call it for example through web3.js without needing a transaction, without any gas cost and without confirmation delay. Currently, it will not reduce ...


19

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 specification. Note the function names and input parameters are hashed during compilation. Therefore, for another account to call a function, it must first be given the ...


18

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 because they are considered not to be precise enough. Ethereum contracts need to be 100% deterministic, and always run the same way on all hardware. Solidity ...


17

A contract cannot access another contract's storage directly. Given contracts C1 and C2, C1 can only access the storage of C2 by invoking a method on C2 that returns data from C2's storage. Since you are writing C2, you can access its storage from C1 and can make progress. A more specific question may help provide a more specific answer about designing ...


17

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 store addresses and big values for crypto computations, and unlimited values are too hard to make a secure gas model around. 32 bytes is ideal because it is ...


17

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 know what a function is. The way functions are implemented in Ethereum is that the compiler includes a check at the beginning of the code which compares the ...


17

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 CALLs in, it will be max X * (63/64)^n. And to be correct, the gas is even less than that, since 63/64 is defined as "all but one 64th" of N as N - floor(N / ...


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