Questions tagged [yul]
The yul tag has no usage guidance.
65
questions
0
votes
0
answers
2
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
28
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
1
answer
39
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
28
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
104
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
41
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
121
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
17
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
31
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
35
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
18
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
141
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
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 ...
1
vote
1
answer
95
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
43
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
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 ...
3
votes
3
answers
270
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
190
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
71
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
221
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 ...
1
vote
0
answers
40
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
29
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
0
answers
27
views
How to shift an array of structs so that the first index is the last— with Yul?
Is it possible to use Yul to shift an array of structs? Have been trying (including by encoding the struct array) to no success.
Using this for a an array of struct with 2 uint256 members:
assembly { ...
0
votes
2
answers
86
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
2
answers
999
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
137
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 ...
0
votes
0
answers
104
views
yul constructor ABI
I am using an interface as my ABI for ethersJs instead of using an hardcoded Interface like the following.
const iface = new Interface([
// Constructor
"constructor(string symbol, string name)...
0
votes
1
answer
191
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
298
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
41
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
67
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
152
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
279
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
184
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
262
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
) ...
1
vote
1
answer
472
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?
1
vote
0
answers
158
views
How to deploy .yul contract with hardaht?
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 change the hardhat configuration somehow?
Thanks
2
votes
1
answer
403
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
1k
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
32
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
307
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
518
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
141
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() ...
5
votes
1
answer
360
views
Why is constant variable value changing?
I wrote a simple contract in solidity.Constant variable's value can be changed in Yul (assembly). But how and why is it changing?.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract ...
2
votes
1
answer
461
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, ...
0
votes
1
answer
127
views
SimpleStorage 100% in Yul
What would a solidity simple storage contract look like 100% in yul?
I haven't seen a solid example. I know what this would look like in huff, but would love to see a yul example.
// SPDX-License-...
2
votes
1
answer
718
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 := ...
1
vote
1
answer
807
views
Is it possible to compile to YUL?
So the solidity compiler compiles solidity first to YUL and then to machine code. Is it possible to compile it just to YUL and look it over?
It would be really helpful to learn how YUL works.
Thanks.
4
votes
1
answer
1k
views
Why would I not want to use intermediate representation (IR) in Solidity v0.8.13 and above?
In Solidity v0.8.13, the intermediate representation (IR) codegen feature has been brought out of the experimental stage. We can now run the compiler with --via-ir flag to enable Yul IR, which makes ...
0
votes
1
answer
124
views
What does dataoffset do?
in the doc it says:
... Can only take string literals (the names of other objects) as arguments and return the size and offset in the data area
but I'm still confused, could anybody give me an example ...