Questions tagged [opcode]

operation codes specify the instructions to be performed in machine languages

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

Which contract's storage does SLOAD/SSTORE use?

A given SSTORE and SLOAD instruction uses storage from a certain smart contract. How can we know which contract that is, and do we need any additional data than the raw struct/opcode traces to find ...
1 vote
0 answers
15 views

How do RETURN and MLOAD work for high offsets?

When trying to load the 32 bytes of memory that follow a high offset (say 0x12345678), the RETURN and MLOAD opcodes give an out of gas error. Why is that ? Example PUSH1 0x20 PUSH4 0x12345678 RETURN ...
  • 137
1 vote
1 answer
21 views

EOA transfer and OPCODEs

I'm doing some research on how the transactions are made in Ethereum. I got reading the code of Geth and the Yellow Paper that a Smart Contract method call with a value on the payload will transfer ...
  • 11
0 votes
1 answer
29 views

How does the PUSH instruction get its input?

I'm trying to understand state storage, and by doing so (for the first time) looking at raw geth traces. I've hit a blocker, though, which is understanding where the arguments to PUSH instructions ...
2 votes
2 answers
238 views

OPCODES WHY DOES free memory pointer(0X40) use 0x80 as starting value?

The following opcodes 0x40 is "offset in the memory in bytes" My question is why evm uses 0x80 as a "32-byte value to write in the memory." PUSH1 0x80 PUSH1 0x40 MSTORE Sincerely
0 votes
0 answers
46 views

OPCODES How is work "CODECOPY"?

Somebody could explain how CODECOPY works in practice ? There is only one sample in evm.playground but I dont understand above-mentioned sample. Could you give me another concrete sample (with ...
1 vote
1 answer
37 views

Does the EVM revert if a call is attempted to an address that doesn't have code?

The following code would revert in high-level Solidity if the provided addr is an EOA or a contract that does not implement MyInterface: interface MyInterface { function myFunction() external; } ...
0 votes
1 answer
173 views

OPCODES How is work "CALLDATACOPY"?

I try to understand how CALLDATACOPY works. destOffset: byte offset in the memory where the result will be copied. offset: byte offset in the calldata to copy. size: byte size to copy. I try to ...
0 votes
1 answer
127 views

selfBalance() and address(this).balance gas cost

Yesterday I found out about the existence of selfbalance() and that it's cheaper than address(this).balance. I checked the EVM opcodes: opcode 31 BALANCE - The static cost is 0. If the accessed ...
0 votes
1 answer
13 views

Invalid opcode when storing value in array part of a mapped struct

I have a public function that accepts some data from users and i basically want to store this data into a struct that is mapped to an address. This is the definition of the Struct : struct ...
1 vote
1 answer
20 views

How to make submod in evm assembly?

I've been playing with huff language (assembly for EVM) and tried creating a macro for subtraction modulo n. At first, I thought it would be easy since addmod(a,n-b,n) would do the job, but this isn't ...
0 votes
0 answers
14 views

Invalid Opcode Error SHR [duplicate]

call to UniswapV2Factory.INIT_CODE_HASH call to UniswapV2Factory.INIT_CODE_HASH errored: Internal JSON-RPC error. "code": -32000, "message": "invalid opcode: SHR" I'...
  • 1
0 votes
0 answers
6 views

Accessing an internal function in my contract via assembly in another function

I have this block of code that compares hashes of bytes and I would like to convert directly into assembly: uint skipPointer; // prevents excess search if a match has been found uint ...
  • 31
1 vote
2 answers
43 views

Why do I not see CREATE or CREATE2 opcodes in traces of contract creating transactions?

I am trying to see smart contract creations from opcodes in transaction traces with debug_traceTransaction. But traces of transactions that created contracts do not seem to include the CREATE opcode. ...
  • 13
5 votes
1 answer
173 views

What are the first 128 bytes in solidity memory reserved for?

In most solidity contracts, the first few opcodes generate the free memory pointer PUSH1 0x80 PUSH1 0x40 MSTORE This places the 0x80 value (128) at location 0x40 in memory. So, why don't we start ...
1 vote
1 answer
57 views

Vyper - Why is my first memory variable placed with an offset of 0x40 (64 bytes) instead of 0x20 (32 bytes) or even 0x00 (no offset)?

I have a vyper contract, as such: @external def add_two(my_number: uint256) -> uint256: two: uint256 = 123456 return my_number + two When you compile this (with 0.3.6), a piece of the ...
0 votes
1 answer
20 views

Why is memory used by RETURN misaligned compared to how it was allocated?

I am experimenting with evmone and evmc to execute some simple assembly code snippets on EVM. I wrote a test that is supposed to return 0x42 as output data. The code goes as follows: PUSH 0x42 PUSH ...
  • 103
0 votes
0 answers
51 views

Difference in Control Flow Graph (CFG) of bytecode having vulnerability and after fixing the vulnerability in Ethereum smart contract?

I was analyzing the Control Flow Graph (CFG) extraction from ByteCode by EtherSolve and then thought about an interesting question, how CFG of vulnerable smart contract gets changed after fixing this ...
0 votes
0 answers
28 views

Under which condition "CALL" opcode does not increase the depth?

I'm currently researching EVM opcode trace data(data fetched from "debug_traceTransaction"), and I meet several cases where the opcode "CALL" does not increase the depth. I already ...
0 votes
1 answer
26 views

Ethernaut Challenge Magicnumber

This my OPCODE: INIT: PUSH 0x0a(10 OPCODES=10 bytes) = 600a PUSH 0x0c = 600c PUSH 0x00 = 6000 CODECOPY - Where, current location of runtime code, size of runtime code = ...
2 votes
1 answer
192 views

Why and When To Use uint8 instead of uint?

As far as I know uint8 costs more gas than uint256 (or uint they are same). Let's say my variable can't be bigger than 100, and I already check for it with an if statement. I saw many examples of ...
  • 304
1 vote
1 answer
75 views

is OPCODE applicable for sending ethers from wallet to another account?

I know smart contracts are converted to bytecodes and they are executing OPCODES in the EVM. But I want to know, what OPCODES does Wallet to wallet transactions have?
  • 82
1 vote
0 answers
28 views

Why does SudoSwap using opcode create not create2 to create a pair contract?

SudoSwap contract lib LSSVMPairCloner.sol source code: https://github.com/sudoswap/lssvm/blob/main/src/lib/LSSVMPairCloner.sol I don't understand why using opcode create not create2 to create a ...
  • 11
7 votes
1 answer
409 views

Why is there a `LOG` opcode being created from my solidity code when I don't have any events?

I have the following solidity code: // SPDX-License-Identifier: MIT pragma solidity 0.8.15; contract SSimpleStorage { uint256 storedNumber; function storeNumber(uint256 newNumber) external { ...
1 vote
1 answer
98 views

What do the retOffset and retSize parameters of the CALL opcode do?

When reading the data returned by CALLing another contract, RETURNDATASIZE and RETURNDATACOPY opcodes are used. They allow moving the data from an otherwise unreachable context to the memory, so it ...
6 votes
1 answer
396 views

Is the `indexed` keyword for a Solidity event no longer necessary because of subgraphs?

Context: The indexed keyword is used for Event fields when we want them to be easily searchable using the JSON-RPC method eth_newFilter. This was the best way to offchain index the interactions with ...
  • 666
1 vote
1 answer
105 views

Is it possible to get the revert reason during CREATE?

I'm trying to return the revert reason of a revert that is triggered during a CREATE opcode. I'm currently using function deployCode(bytes memory bytecode) internal returns (address payable addr) {...
  • 1,489
0 votes
0 answers
80 views

Contract initialization opcodes

Every contract I compile starts with the following opcodes: Is this just a design choice by Solidity, or a "rule" in Ethereum? Otherwise it seems like every time the EVM starts up, it would ...
0 votes
1 answer
121 views

Why dedicated ADDMOD opcode?

Is the ADDMOD that commonly used that we needed to create a specific opcode for it? Why couldn't we simply use the ADD opcode + the MOD opcode together? The same question is also valid for the MULMOD ...
0 votes
0 answers
11 views

Completely disregarding all storage costs, is compute time a sufficient metric to determine the computational cost of an opcode operation?

Completely disregarding all storage costs, is compute time a sufficient metric to determine the computational cost of an opcode operation? Or are/is there some other factor(s) that need to be ...
3 votes
0 answers
33 views

Why does a STORAGEADD op (SSTORE) add 80 bytes to state rather than 32?

According to this spreadsheet that Vitalik has referenced before, stating that it's what they used to determine gas fees for each opcode, a STORAGEADD opcode (presumably renamed to SSTORE) is ...
1 vote
1 answer
90 views

Opcode LOG3 Data Value Problem

I am trying to get the Event data from LOG3 but the data sometimes on stack5 and sometimes on stack6, can anyone help? for example, transfer amount = 1 of both two transfer functions, take a look at ...
  • 13
1 vote
0 answers
31 views

Jump within verbatim block with label

I want to inject verbatim block to my yul contract. My verbatim block is a function, I need to implement if block, to be able to implement it, I need to have ability to use labels, I need to point to ...
  • 11
0 votes
0 answers
1k views

I am getting "invalid opcode: INVALID" as error when i try to return an array of structures

I am getting error as ValueError: invalid opcode: INVALID. Is it because of use of memory and storage keyword in the function or is it because i can't return an array. My Solidity Code:- struct ...
1 vote
1 answer
71 views

What settings should a private PoA blockchain have to be free to use? ( No ether in use )

I am a total noob in creating blockchains, and I am trying to make one using geth with PoA. I want to make a PoA private blockchain where transactions and smart contracts ( usage and deployments ) are ...
1 vote
0 answers
160 views

Is there a way to call a function via a selector from within a contract?

In the case of calling a function with signature foo(uint256) from contract A, I could use this construction in solidity: address(A).call(abi.encodeWithSignature("foo(uint256)", 100)); // or ...
  • 243
1 vote
1 answer
344 views

How to get opcode trace of failed transaction without solidity source?

tldr: want to run simulated transactions against deployed bytecode on rinkeby that has no verified solidity source, and step through opcodes and view stack/memory leading up to revert. To clairfy: in ...
1 vote
0 answers
48 views

How are blocks processed while syncing Ethereum blockchain full sync mode?

I am syncing a Geth client in full sync mode and also have made some changes in the client to log the execution time , time stamp and block number of all the opcodes executed in the Ethereum virtual ...
  • 155
0 votes
1 answer
204 views

Using assembly to store more values per word

I need to store 1250 numbers 16 bits elements in an array. Storing unit256 cost 20.000 gas units each (SSTORE opcode), which at 200gwei gas price, will cost around 4.5 ETH. My understanding is that I ...
  • 103
0 votes
1 answer
247 views

Why does changing a storage slot's value from zero to non-zero cost more than non-zero to non-zero in the sstore opcode?

Why does changing a storage slot's value from zero to non-zero cost more than changing from non-zero to non-zero, zero to zero, or non-zero to zero?
1 vote
1 answer
272 views

Why do Etherscan's opcode view and opcode disassembler show different opcodes for the USDT contract?

We have USDT smart contract, which is located at 0xdac17f958d2ee523a2206206994597c13d831ec7. I am trying to decompile the smart contract (at least view it as at opcodes). What I see is that it begins ...
  • 123
1 vote
1 answer
561 views

Is the source code of any Ethereum smart necessarily contract open?

I thought that any smart contract had open code. However, from time to time I'll encounter smart contracts that have no publicly available Solidiy code, on etherscan. How can this be? Doesn't that ...
1 vote
1 answer
354 views

Is there a size limitation on create2 bytecode field?

I have the following method in my Solidity contract. function deploy(bytes memory bytecode, uint _salt) public payable returns (address){ address addr; assembly { addr := create2( ...
  • 13
2 votes
2 answers
1k views

Solidity shr opcode

What does this code mean? sender := shr(96, calldataload(sub(calldatasize(), 20))) Btw sender is an address variable.
0 votes
1 answer
301 views

SLOAD opcode working in ethereum virtual machine

How SLOAD opcode works in ethereum virtual machine and why it is one of the most computationally expensive and time consuming process. vm stats for different opcodes of evm
  • 155
1 vote
0 answers
137 views

Understanding the relationship between opcodes and the number of semicolons in source maps

Contract Take the following contract: // SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; contract Adder { function add(uint256 x, uint256 y) external pure returns (uint256 z) { ...
0 votes
1 answer
309 views

How to read the current program counter (PC) in Solidity or Yul?

I was reading about the EVM dialect in the docs, and saw this: Instruction Explanation pc() Current position in code I went to Remix to try it out: function read_pc() external view returns (uint256 ...
3 votes
2 answers
3k views

does using external over public in a library reduce any gas costs?

I have a library utils.sol library Utils { struct UtilType { unit var1; bool var2; } function addExtra(UtilType storage state, uint extra) public { state.var1 += extra; } } ...
0 votes
2 answers
340 views

Where do I find the solidity provisions of Ethereum OPCODEs?

There is Solidity Cheat Sheet: https://github.com/manojpramesh/solidity-cheatsheet There is OPCODEs list: https://github.com/crytic/evm-opcodes But is there any list that show opcode's solidity code ...
3 votes
0 answers
418 views

Solidity sourceMap and opcodes. No map entries for every code?

After compiling a simple contract, the output are these values: "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP ...