Skip to main content

Questions tagged [yul]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
21 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
30 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
53 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
  • 568
3 votes
2 answers
136 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
  • 568
4 votes
3 answers
197 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
52 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
  • 137
0 votes
2 answers
184 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
96 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
326 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
51 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
439 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
20 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
  • 137
1 vote
0 answers
40 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
58 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
19 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
242 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
165 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
  • 365
1 vote
1 answer
153 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
  • 638
0 votes
1 answer
53 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
163 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
373 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
  • 638
3 votes
1 answer
274 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
111 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
282 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
30 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
142 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
208 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
248 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
391 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
42 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
77 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
172 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
349 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
205 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
334 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
2 votes
1 answer
695 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
193 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
  • 342
3 votes
1 answer
551 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
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 { ...
Ryan Sea's user avatar
  • 638
0 votes
2 answers
33 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,312
0 votes
0 answers
410 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
  • 928
1 vote
1 answer
660 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
154 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
5 votes
1 answer
397 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 ...
Abdullah0123's user avatar
2 votes
1 answer
553 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, ...
Alex Suvorov's user avatar
0 votes
1 answer
141 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-...
Patrick Collins's user avatar
3 votes
1 answer
890 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 := ...
Emrah's user avatar
  • 1,664
1 vote
1 answer
1k 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.
Kuly14's user avatar
  • 342