Skip to main content

Questions tagged [yul]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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?
Paul Razvan Berg's user avatar
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 ...
Zulu Dykes's user avatar
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 ...
CodeSandwich's user avatar
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 - ...
shadow's user avatar
  • 307
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 ...
Anh DH's user avatar
  • 3
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{} ...
Ashraile's user avatar
  • 125
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 ...
tsknakamura's user avatar
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) { ...
imelon2's user avatar
  • 590
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 ...
imelon2's user avatar
  • 590
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 ...
Pintus20's user avatar
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}());...
Xirexor's user avatar
  • 176
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: ...
jlbl's user avatar
  • 11
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/...
Ruwaifa Tahir's user avatar
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/...
Priyank Gupta's user avatar
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 ...
owl's user avatar
  • 13
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 ...
Fuga14's user avatar
  • 23
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 ...
Xirexor's user avatar
  • 176
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 ...
Mehul Singh Rathore's user avatar
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. ...
Recep Çankaya's user avatar
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) ...
Saurabh Bhai's user avatar
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;...
Bobo's user avatar
  • 21
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 ...
Iaroslav's user avatar
  • 410
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]?
Ryan Sea's user avatar
  • 668
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 ...
mattes's user avatar
  • 101
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 ...
Sebastian Dine's user avatar
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, ...
Ryan Sea's user avatar
  • 668
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 ...
Patrick Collins's user avatar
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 ...
Paul Razvan Berg's user avatar
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 ...
Aminadav Glickshtein's user avatar
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....
Leeren's user avatar
  • 269
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 ...
Malik Aremu's user avatar
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 ...
Alexandr Dorofeev's user avatar
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(...
EyeEmmaJedi's user avatar
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 ...
Sohail Saha's user avatar
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....
Peter's user avatar
  • 21
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 ...
Peter's user avatar
  • 21
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 ...
Netanel's user avatar
  • 51
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 ...
FuryokuSyndicate0x1's user avatar
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 ...
Cizia's user avatar
  • 263
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 ...
Marty's user avatar
  • 11
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 { ...
Cizia's user avatar
  • 263
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 ) ...
Cizia's user avatar
  • 263
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?
Jesper - jtk.eth's user avatar
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? ...
Kuly14's user avatar
  • 362
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;...
njwags's user avatar
  • 133
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 { ...
Ryan Sea's user avatar
  • 668
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 ...
zunior's user avatar
  • 1,322
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!
dNyrM's user avatar
  • 948
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 ...
chixx.eth's user avatar
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() ...
Paul Razvan Berg's user avatar