Questions tagged [opcode]
operation codes specify the instructions to be performed in machine languages
172
questions
0
votes
1
answer
22
views
Solidity - Function Selector Loading onto the stack: why DIV instead of SHR?
I'm currently learning about how the function selector is loaded from calldata. The algorithm is like so:
PUSH4 ffffffff
PUSH29 0100000000000000000000000000000000000000000000000000000000000000
PUSH1 ...
0
votes
1
answer
10
views
Reliably disassamble bytecode to opcodes across various evm versions
Is there a reliable way of disassembling bytecode into opcodes across different EVM versions, to make it agnostic to the EVM version used during compilation?
As the second best option - is there a ...
1
vote
1
answer
54
views
Run optimizer on opcodes
According to documentation, one of the steps of solidity compilation is the optimization on opcodes level, with the following set of rules.
How can I apply optimization directly on opcodes?
Details
...
3
votes
1
answer
55
views
How do old smart contracts that contain certain opcodes behave when those opcodes get deprecated/removed in hard fork upgrades?
For example say a contract with a compiler version of 0.7.5 (pragma solidity 0.7.5) contained selfdestruct(payable(address))
what happens to the contract when the self destruct opcode gets deprecated ...
2
votes
1
answer
35
views
Is there a way to stop wallet homomorph attacks without ditching the create2 opcode?
Losses from create2 wallets that look similar to recently active wallets has surpassed $60m:
https://gbhackers.com/create2-bypass-wallet-security-alerts/
Even today I made a transaction, and noticed ...
0
votes
1
answer
45
views
Invalid OpCode while deploying "HelloWorld"
I'm receiving the following error message trying to deploy a very simple contract to Ganache. How can I resolve this?
Contract:
pragma solidity ^0.8.21; // ^0.4.24;
contract HelloWorld {
string ...
2
votes
1
answer
338
views
Beacon contract contructor seems to call address 0x02?
The Beacon (Eth 2.0 deposit) contract was once deployed using a certain (constructor) script, like every other contract on the EVM blockchain. While analyzing that constructor script, it seems that it ...
1
vote
2
answers
98
views
What does FE stand for in "InvalidFEOpcode"?
I've seen the name InvalidFEOpcode used in client implementations, e.g. in REVM:
https://github.com/bluealloy/revm/blob/8206193e65ad199a1dde1e79e38bf9ffe38118c9/crates/interpreter/src/...
0
votes
1
answer
42
views
Can I edit in the msg.sender value for the called contract?
let's assume following solidity contracts:
contract EntryPointContract {
address one = '0x...';
address two = '0x...';
address delegateContract;
constructor(address ...
0
votes
1
answer
55
views
Determining if a smart contract is using delegatecall
Let's say that I have the bytecode of a smart contract deployed on ethereum (which I got with a call to eth_getCode).
How can I programmatically determine if this smart contract uses delegatecall ...
1
vote
2
answers
22
views
Where is the return data from an external call stored?
In ethervm.io, RETURNDATASIZE is described as follows.
RETURNDATASIZE : Byzantium hardfork, EIP-211: the size of the returned
data from the last external call, in bytes
The smart contract has 3 ...
2
votes
1
answer
25
views
Should all method hashes be found in a smart contract's opcodes?
I have a compiled/deployed solidity smart contract for which I have encoded all the functions signatures. (4-byte hashes)
With the deployed bytecode, I have parsed the pushdata into an array for all '...
0
votes
1
answer
24
views
what does it mean "JUMPDEST occupies position 43"
I'm looking at the minimal proxy posted by OpenZeppelin(link). I don't know what the text below means.
The entire set of instructions for this EVM runtime code is made up of
45 bytes, and JUMPDEST ...
0
votes
1
answer
20
views
EVM opcodes for Boolean AND operations
What opcodes does the EVM use in performing boolean AND (&&) operations
0
votes
1
answer
97
views
Inline Assembly: RETURN opcode can't not work. Failed to decode output
I know that: return(p, s): end execution, return data mem[p…(p+s)).
I want to return something in memory but not a multiple of bytes32. For example, I want to return 1 byte:
pragma solidity 0.8.20;
...
0
votes
0
answers
26
views
Is there a way to calculate all the gas used in a transaction from within a smart contract?
If I use gasleft() and the beginning and end of the function then I only capture the amount of gas used between those two points. Is there a way to capture all of the gas used then to multiply that ...
1
vote
1
answer
492
views
How does opcode PUSH0 work in EVM?
PUSH0 is a new opcode that appeared in solidity 0.8.20 to replace PUSH1 00.
Q1) Do PUSH0~32 need numbers(data) to be pushed next to it unconditionally?
example : PUSH1 00 || PUSH2 05
Q2) PUSH0 ...
7
votes
3
answers
7k
views
invalid opcode: opcode 0x5f not defined
I'm new to Solidity and it's my first try to write a smart contract using Openzeppelin, Pancakeswap and BEP20 libraries basically to make a BEP-20 token.
When i try to deploy the smart contract, i get ...
1
vote
1
answer
147
views
When did each opcode get added to the EVM?
After the original set defined in the Ethereum yellow paper,
many new opcodes have been added.
I'm after a list of when each one was added (by fork).
1
vote
1
answer
82
views
How do the LT and GT opcodes differ from SLT and SGT respectively?
When reading the Opcodes for the EVM article, I saw that the LT and SLT opcodes are evaluated to the same expression (a < b), as well as the GT and SGT opcodes (a > b).
How do LT and GT differ ...
3
votes
2
answers
103
views
Remix Assembly vs. Solidity Compiler Assembly
I am just diving into EVM assembly and am a little confused about the following.
I have the following simple contract:
pragma solidity >=0.8.1;
contract MyTest {}
When I compile it using Remix, I ...
2
votes
1
answer
83
views
Question about a function implementation in Ethereum Account Abstraction
function numberMarker() internal view {
assembly {mstore(0, number())}
}
I'm studying about Account Abstraction, and exploring through the implementation code of EntryPoint.sol by Infinitism. ...
1
vote
2
answers
58
views
Why don't specify add/sub/div/mul in the bytecode opcodes?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract Test {
uint num = 2 * 2 + 10;
}
For example, when compiling the above code in Remix,
PUSH1 80 PUSH1 40 MSTORE PUSH1 0e PUSH1 00 ...
2
votes
1
answer
106
views
Is the deploying of the contract anonymous?
Is the deploying of the contract anonymous? is it possible to find the owner who posted the contract? Is the only mention of it a link to the wallet from which the smart contract was first replenished ...
1
vote
0
answers
20
views
Hardhat: setPrevRandao does not work
I'm trying to simulate prevrandao but it does not work out.
To check it, I've written a contract and a test.
contracts/AnotherContract.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;...
1
vote
0
answers
63
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
1
answer
36
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
...
1
vote
1
answer
144
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 ...
0
votes
1
answer
90
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 ...
3
votes
2
answers
578
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
1
answer
263
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
2
answers
315
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
1k
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
437
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
22
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
70
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
17
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'...
0
votes
0
answers
28
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 ...
1
vote
2
answers
172
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.
...
5
votes
1
answer
364
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
85
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
32
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 ...
0
votes
0
answers
93
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
40
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
34
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
469
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 ...
1
vote
1
answer
151
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?
1
vote
0
answers
39
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 ...
7
votes
1
answer
525
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
287
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 ...