Questions tagged [yul]
The yul tag has no usage guidance.
72 questions
0
votes
1
answer
14
views
How is Nethermind's Clear formal verification tool different from Certora and Runtime Verification's KEVM?
Nethermind has released a new formal verification tool called Clear.
How is it different from more established tools like Certora and Runtime Verification's KEVM?
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 ...
1
vote
0
answers
36
views
Does Solidity require pointer alignment in memory?
Solidity seems to allocate memory under pointers being multiples of 32. This is understandable since most allocation sizes are multiples of 32. But is it a requirement or is it fine if a Yul inline ...
3
votes
1
answer
31
views
If the `Free pointer` is stored at `0x40` what do the rest of `0x41` to `0x5f` do?
Layout in Memory
Solidity reserves four 32-byte slots, with specific byte ranges (inclusive of endpoints) being used as follows:
0x00 - 0x3f (64 bytes): scratch space for hashing methods
0x40 - ...
0
votes
1
answer
54
views
call getReserves() function using yul in solidity
what wrong with getReserves2 in A contract, why I cannot staticcall to Pair contract?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Pair {
function getReserves() external ...
0
votes
1
answer
24
views
Convert the following address sum function to optimized assembly via both memory and storage. Slots are dynamic
I'm looking to convert the entire function getCurrentSupply() to assembly code as the potential gas savings in this use case are significant. Note that everything should be within a single assembly{} ...
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 ...
4
votes
3
answers
347
views
Calling private functions using Yul ( Solidity )
I'm currently learning Yul in Solidity and experimenting with the call() function to call other functions in inline assembly. I've noticed that as soon as a function is set to private, I receive a ...
2
votes
1
answer
82
views
Assembly 'create2' and 'new' with salt not determining the same address
Since solidity 0.8.0, we can now specify the salt for contract creation using new keyword
Using 'new'
bytes32 _salt = bytes32("0x4");
address addr = address(new DummyContract{salt: _salt}());...
0
votes
2
answers
227
views
reading and writing to a packed nested struct using inline assembly
I've been racking my brain with this for some time, and have been unable to increment and decrement specific fields inside nested structs as per the example below.
// SPDX-License-Identifier: ...
0
votes
1
answer
165
views
Unknown key "viaIR"
Unknown key "viaIR"
Error HH600: Compilation failed
I'm encountering the above error when I try to compile.
Here is my hardhat.config.ts
import { HardhatUserConfig } from "hardhat/...
0
votes
2
answers
492
views
How do I compile a smart contract written in pure yul using Foundry?
Basically I want to do a written tutorial on how to compile and deploy this CREATE2 proxy contract, written in pure Yul.
https://github.com/Arachnid/deterministic-deployment-proxy/blob/master/source/...
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 ...
0
votes
2
answers
577
views
Make Uniswap v2 swap through inline assembly
I'm trying to make swap tokens in smart contract using Uniswap V2. My main goal is to make part where you need to work with Uniswap router as assembly block.
I'm not good in assembly, so I need your ...
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
0
answers
45
views
What am I doing wrong in my assembly code?
This function doesn't work if I put amountOut variable in it. Can't understand why.
function swap(
address token,
address pair,
uint256 amountIn,
uint256 amountOutMin,
uint256 ...
1
vote
1
answer
78
views
Cannot getting a storage variable from another contract using inline-assembly
I am trying to develop myself on inline-assembly. There are two contracts: CryptoDevs and Whitelist. In the assembly, i copied the whole code of whitelist contract instance into cryptodevs memory. ...
0
votes
1
answer
21
views
What is the Purpose of Checking lt(fpm, ptr) in Buffer.sol?
Recently I checking Buffer.sol smart contract and I found this Code
Link = https://github.com/ensdomains/buffer/blob/master/contracts/Buffer.sol
function init(buffer memory buf, uint capacity) ...
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 ...
1
vote
1
answer
190
views
How to shift elements in array using inline assembly?
Taking a memory array [1,2,3], is it possible to us shr/shl to make the array [2,3,1]?
0
votes
1
answer
63
views
How to identify the calling function from within a modifier?
Two Solidity functions foo and bar both calling modifier m which emits an event Called with a unique identifier for the calling function. It could be any identifier, but it has to be unique per ...
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 ...
3
votes
3
answers
455
views
How to decode a nested encodePacked?
The structure of the encoding is
abi.encodePacked(
abi.encodePacked(
address,
uint256,
uint256,
address,
uint256,
address,
...
3
votes
1
answer
322
views
How does `shr` read from storage?
The following a code snippet from a Clone.sol. In this code, the function _getArgAddress returns the address value from storage.
function _getArgAddress(
uint256 argOffset
) internal pure ...
1
vote
1
answer
167
views
Why doesn't the Yul instruction `div` work just like the high-level division operator?
I noticed that the following Solidity functions are not equivalent:
function a(int256 x) pure returns (uint256 result) {
assembly {
result := div(sub(0, x), x)
}
}
function b(int256 ...
0
votes
1
answer
305
views
Is it safe to enable the IR flag in the current version of Solidity?
When the IR flag is enabled, it generates a different bytecode from the old compiler since it's using the YUL optimizer.
It's still in active development. So is it safe to enable? Or not yet?
Any ...
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 ...
4
votes
2
answers
2k
views
Yul/Inline Assembly: Revert with a custom error message
I am learning Yul for my Bachelor's thesis and I am currently stuck on understanding a small code segment with require and revert functions.
A simple require function in Solidity ...
require(...
1
vote
2
answers
252
views
Why does storing values at non-32 multiple memory locations spill over to next location?
Take this line for example (Yul):
mstore(0x24, 0x0443455243)
If it was mstore(0x20, 0x0443455243), then the entire value would have been stored at location 0x20.
However, if 0x24 is used, I'd expect ...
1
vote
1
answer
281
views
Solidity Yul nested mappings in storage
I'm trying to save in storage some values in a nested mapping.
Found some results of a similar problem, tried the solutions, but no success, also read the documentation of https://docs.soliditylang....
0
votes
1
answer
441
views
Solidity Yul push struct to dynamic array in storage
So like the title says I'm trying to push a struct to a dynamic array with yul.
This is my code:
contract Spiral {
struct Chunk {
int256 x;
int256 y;
}
Chunk[] public ...
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
81
views
Free memory point manipulation in solmate library
I am trying to learn a little bit of yul and came across a scenario in the solmate library I don't quite understand. In all of the instances when they are appending addresses to the free memory ...
0
votes
1
answer
185
views
Translating Yul to Solidity
I have this Yul function that I am trying to reverse to Solidity for learning purposes.
My results with the solidity function are different than the original functions and I don't see what I am ...
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 ...
1
vote
1
answer
213
views
single param yul for loop
I am trying to understand this for loop pattern:
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
...
1
vote
1
answer
376
views
How to push a value in an array in Yul
How would you push the z value at the end of the for loop in this function ?
contract Math {
uint256[] nums;
function fpow(
uint256 x,
uint256 n,
uint256 baseUnit
) ...
3
votes
1
answer
792
views
How do I return a string in a pure Yul contract?
I am writing a contract in pure Yul and I want to return a string from a function.
Imagine the ABI as:
function getString() view returns (string memory);
But in Yul, how can I do this?
2
votes
1
answer
228
views
How to deploy .yul contract with Hardhat?
I would like to deploy a contract written in pure Yul with Hardhat but I'm not sure how to do it.
Is there some plugin for it, or do I just need to add special fields to the hardhat.config.js file?
...
3
votes
1
answer
650
views
meaning of `slot` property in Yul?
I was reading through the implementation of ERC721A Upgradable's ERC721AStorage.sol and found this function
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;...
2
votes
1
answer
2k
views
How does console.logging work (e.g. Foundry's Console.sol)?
The main block of code in Forge's Console.sol is
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
...
0
votes
2
answers
35
views
Is Ethereum capable of having dynamicly typed languages?
I am wondering if it is at least theoretically possible for Ethereum to have a language that is loose/weak typing.
From what I've seen all the languages on Ethereum are static typed.
My understanding ...
0
votes
0
answers
472
views
Get functions selectors of contract
Is it possible to get all the function selectors from a contract using only Solidity and/or assembly?
Thanks!
1
vote
1
answer
749
views
Solidity YUL-inline assembly, acces double mapping and updtade it
Hello im stuck with yul inline assembly when i want to access a double mapping.
mapping(address => mapping(address => uint256)) public approval_;
function approve(address spender, uint256 ...
3
votes
1
answer
156
views
Is there any difference between the "new Contract()" syntax and the assembly "create" opcode?
Is there any difference between the two following ways of creating a smart contract via a smart contract?
function create_v1() external {
Contract c = new Contract();
}
function create_v2() ...