All Questions
19 questions
2
votes
1
answer
72
views
Difference between `tx.gasprice`, `assembly { gasPrice := gasprice() }` and `block.basefee`
I created the following contract and deployed on Sepolia, including an inline assembly call which returns gas price for the transaction.
The question is how and why does the ... := gasprice() output ...
0
votes
1
answer
33
views
Is it safe to reuse same memory slots for both inputs and ouputs when working with assembly call?
Is it safe to reuse memory for both inputs and ouputs when working with assembly call?
If not, what can go wrong?
Contract below uses assembly to call Target
contract YulStaticCall {
function ...
1
vote
2
answers
71
views
How are bytes and bytes32 different in inline-assembly?
function mloadTest1() public pure returns(bytes memory) {
bytes memory a;
assembly {
a :=mload(0x40)
}
return a; // 0x20
}
function mloadTest2() public pure returns(bytes32) {
...
3
votes
2
answers
226
views
Why does mload(0x40) result in 0x20?
I ran the code below and had a question.
function mloadTest1() public pure returns(bytes memory) {
bytes memory a;
assembly {
a :=mload(0x40)
}
return a;
}
mload(x) is a Yul ...
1
vote
1
answer
59
views
how come loading the funcSig from data isn't enough, you have to shift it also to use it in the rest of the code/function
basically we have this function
function FlaggedMethods(
bytes memory data
) public returns (address) {
bytes4 funcSig;
assembly {
// Shift right by 224 bits ...
1
vote
1
answer
24
views
When declaring a variable inside a function, why EVM always pushes 0 before any primitive value onto stack?
A simple declaration inside a function such as:
uint256 var = 0xffff;
has it's line executed in assembly (from Remix) like the following:
push0
push1 0xffff
swap1
pop
Why was the 0 pushed to be ...
1
vote
1
answer
307
views
Dynamic arrays in memory layout
I think i've figured out dynamic memory layout for dynamic arrays, but could use a check on my reasoning. Consider the contract :
pragma solidity >=0.8.4;
struct state_type {
bytes b;...
1
vote
1
answer
239
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
209
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
0
answers
46
views
What's the benefit of encapsulating storage slots as structs?
Often times you'll see the following pattern for reading and writing to storage slots:
struct Slot {
address value;
}
...
function getSlot(bytes32 slot) returns (Slot storage s) {
assembly { s....
1
vote
1
answer
32
views
Can someone explain to me how returns work under the hood in solidity?
Can someone explain how I will be successfully able to return this
function reddish(uint256 _red) public view returns (bytes memory) {
bytes memory err = abi.encode(msg.sender, _red);
assembly ...
0
votes
2
answers
200
views
Translate EVM to YUL
Is there any method to retrieve compilable YUL from EVM byte code?
I've found EVMToEWasmTranslator.cpp at Solidity main repo, but it seems to be designed to translate between YUL dialects.
Maybe there ...
3
votes
0
answers
44
views
Classical bit-fiddling tricks that don't work in the EVM
Many classical bit-fiddling/bit-hacking tricks work very well on the EVM and allow one to save a significant amount of gas when programming in Yul/Solidity (for a reference to the classics, see Sean ...
0
votes
1
answer
367
views
What are the tradeoffs associated with using the `via-ir` build flag?
I am working on a project where the via-ir build flag has been tremendously useful. However, I haven't been able to find the tradeoffs associated with using the flag beyond minor semantic changes that ...
2
votes
1
answer
600
views
What is the best practice for memory allocation in EVM assembly?
As far as I know, this is the standard way of the memory allocation in assembly:
assembly {
let firstFreeMemoryPointer := mload(0x40)
mstore(0x40, add(firstFreeMemoryPointer, ...
3
votes
1
answer
968
views
Confusion about mload opcode
This code is used to return keccak256 of function input and taken from this question:
function assemblyKeccak (bytes memory _input) public pure returns (bytes32 x) {
assembly {
x := ...
0
votes
0
answers
34
views
Figure out the address used at construction time for a regular smart contract
Is there anyway to figure out what was the address used at construction time and find it in the bytecode?
For example I know that for libraries they are storing it in the contract in order to be able ...
1
vote
1
answer
246
views
Access contract's runtime code from one of its functions
Is there anyway to access the runtime code of a function from its contract? Using assembly may be?
Thanks
2
votes
1
answer
480
views
Q: `extcodesize` is non-zero after `selfdestruct`
I ran into an EVM edge case. Is it correct that extcodesize(addr) is not zero, after calling selfdestruct on addr in the same transaction?
This behavior seems strange and I could not find any ...