Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
3 votes
1 answer
32 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
1 vote
1 answer
35 views

Assigned variable in memory location 0x40 is returned in 0x80

I'm trying to understand how assembly works with memory and the free memory pointer. Given the following: function test() public pure returns(uint){ assembly { ...
Delvir0's user avatar
  • 137
3 votes
1 answer
90 views

Is it possible to emit generic events using assembly?

I'm trying out a proxy / upgrade pattern where the deployed contract is an ERC-721 but it delegates as much functionality to a "controller" contract as possible. The storage is split between ...
okwme's user avatar
  • 335
0 votes
1 answer
30 views

Inheritance in solidity

Are private variables in solidity inherited ? Please I need a bit of clarification here from most text I have read about inheritance in solidity they state clearly that private variables of parent ...
Emmanuel Anah's user avatar
1 vote
1 answer
48 views

assembly mload offset understanding

I tried asking chat-gpt but it kept shitting the be for the explaination. I have some code which looks like so: function getAuthorityScope(bytes memory authorityScope) public pure returns (address, ...
RitzyDevUk's user avatar
0 votes
1 answer
40 views

Interact with Deployed Contract

Can we interact with a deployed contract without web3 library meaning through another contract. Can we make a call to another contract inside of a contract through may be assembly keyword that makes ...
seojunchian's user avatar
0 votes
2 answers
194 views

How to use `MCOPY`?

I'm a student who's learning smart contract develop. I want to write some assembly codes to solve this problem. function convert() public pure returns (bytes memory) { ...
Marco Chang's user avatar
0 votes
1 answer
61 views

Multiplication of two uint256

How do I compute the multiplication of two uint256 so the result doesn't overflow? In the end, this multiplication is an intermediate step within a larger operation, in case this extra piece of info ...
dNyrM's user avatar
  • 948
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
0 votes
1 answer
47 views

Why the method _castToPure in hardhat/console.sol can convert a view method to a pure one?

I have a question when read the console.sol. There is a method named _castToPure that can convert a view method _sendLogPayloadImplementation into a pure method. I cant understand the reason and ...
Alvan's user avatar
  • 31
0 votes
1 answer
172 views

Runtime bytecode not contained in creation bytecode

I'm currently delving into EVM and contract bytecode. My understanding is that by sending a transaction to the NULL address with both the initcode and contract code, and ensuring that the init code ...
kaspyjrefluss8's user avatar
0 votes
0 answers
47 views

Solidity inline assembly custom error revert foundry testing

I have written test cases for the original high level code to test the reverting case of a custome error - ERC20InsufficientBalance(address,uint256,uint256) with the following code: function ...
Xenox's user avatar
  • 1
1 vote
1 answer
71 views

Manipulate bytes with assembly

Using assembly only, how do I switch, for A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, the last 20 bytes of the second 32-bytes from the bytes variable below, and keep the rest as it is? Original bytes: ...
dNyrM's user avatar
  • 948
1 vote
1 answer
93 views

Inline assembly, how to get string from struct in mapping with Yul?

I don't get how to get next element in struct. I can take id value, but what to do next? i assume, i need to add 1 to slot, to get string value but what it return, reference to the string? and what i ...
Gleb Protasov's user avatar
1 vote
1 answer
56 views

generate url in smart contract, based on block.chainid and address(this)

For the past few days I have been looking into creating a simple function to generate a url based on block.chainid (uint256) and address(this). The idea is as follows: function url() public view ...
Cloudronaut's user avatar
3 votes
2 answers
229 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
352 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
1 vote
0 answers
18 views

Solidity assembly: `target_slot`. Is it an opcode or other stuff?

I found this strange variable or opcode in inline assembly, but I'm not sure: target_ slot. I couldn't find its definition in the contract. I prefer it to be an opcode, but I didn't seem to find it ...
LEVI_104's user avatar
0 votes
1 answer
87 views

What is the reason for this assembly code?

I am looking at the following contract, specifically the following assembly code....I think I decoded that it means make sure that if the contents of slot 0 equals 2, then store 3980109478 (which is ...
user127148's user avatar
1 vote
1 answer
27 views

Inline assembly loop doesn't update memory

I want to copy in inline assembly from calldata the last two bytes of every 32 byte slices to the lower half of the first free memory slot(32 bytes). free = free memory pointer + 14 (bytes) moffset = ...
Igor József Vass's user avatar
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
2 votes
1 answer
245 views

Grab first 20 bytes of 32-bytes input

In solidity casting or assembly, how do I grab the first 20 bytes of this 32-bytes input: 0x00010000c900c90062fceaad00000000000000000002af416812f9bb6f2fdff5? Thanks!
dNyrM's user avatar
  • 948
2 votes
1 answer
197 views

Is there a shortcut for "greater than or equals to" in Solidity assembly?

I have some code where I was experimenting with the Math library, namely the logarithm functions, and I figured these would be the perfect functions to optimize with assembly, after slightly improving ...
Ashraile's user avatar
  • 125
0 votes
1 answer
82 views

Is it possible to make my CREATE2 factory so that the calculated address is totally independent of the address my factory is deployed on?

Is it possible to make my CREATE2 factory so that the calculated address is totally independent of the address my factory is deployed on. For example, this is the formula listed on solidity-by-example ...
Priyank Gupta's user avatar
0 votes
1 answer
86 views

Converting an optimized for addition loop into inline assembly (0.8.20)

I have to loop through an array that will contain <10 addresses. I've already optimized for gas costs as much as possible using native Solidity. But I realized this loop can be improved further ...
Ashraile's user avatar
  • 125
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
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
2 votes
0 answers
14 views

How can i implement `MinimalBeaconProxy`?

I'm trying to make MinimalBeaconProxy. But seems like the assembly codes don't work. Can I get some advice of this codes? Contracts contract BeaconProxyCreator { constructor(address beacon) ...
Dongwu Kim's user avatar
0 votes
1 answer
237 views

Inline Assembly: RETURN opcode can't not work. Failed to decode output

I know that: return(p, s): end execution, return data mem[p…(p+s)). I want to return something in memory but not a multiple of bytes32. For example, I want to return 1 byte: pragma solidity 0.8.20; ...
LEVI_104's user avatar
2 votes
1 answer
532 views

Trying to use CREATE opcode to deploy a new contract instance using bytecode of a deployed contract

I am trying to get the bytecode from a deployed contract, then by using that bytecode, use the CREATE opcode to deploy a new instance of that contract. Here is the code I'm trying out (but to no avail)...
Allan's user avatar
  • 41
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
3 votes
2 answers
211 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
459 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
1 vote
0 answers
81 views

I have low level method that calculates log2, but I don't exactly understand how it works

Somebody, please, can you explain step by step how it assembly code exactly works? function log2(uint x) private pure returns(uint y) { assembly { let arg := x x := sub(x,1) ...
Peter Ivanoff's user avatar
1 vote
1 answer
767 views

Is it possible to reverse the gas used in case of using revert?

I try to refund gas to the minimum even after using revert with the following example. uint A = IERC20(base).balanceOf(address(this)); IERC20(token).transfer(owner,1000000); then I run swaps ...
jhonatanalfred's user avatar
0 votes
1 answer
33 views

I m trying to add additional parameter in fulfillBasicOrder but it gives me error

When I add additional parameter in fulfillBasicOrder it gives me error of InvalidBasicOrderParameterEncoding Please help me out how can I add additional parameter in this function as I have less ...
Umeraqeel's user avatar
1 vote
1 answer
169 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
4 votes
2 answers
2k views

What is calldata offset for dynamic calldata arrays?

The Solidity docs say this about dynamic calldata arrays: For dynamic calldata arrays, you can access their calldata offset (in bytes) and length (number of elements) using x.offset and x.length But ...
Paul Razvan Berg's user avatar
2 votes
0 answers
85 views

Is there any way to bubble up custom errors without using low-level assembly?

Is there any way to bubble up custom errors without using low-level assembly? Say you have a custom error defined like this: contract For { error Unauthorized(); function reverWithError() ...
Paul Razvan Berg's user avatar
2 votes
2 answers
590 views

Is it safe to open SLOAD to any contract?

I am running into issue of contract size over the limit when deploying my contract. So, I have decided to open SLOAD in my getter so that any contract can read from it. function readBySlot(uint256 ...
Mr.SsS's user avatar
  • 435
0 votes
2 answers
489 views

Convert bytes20 to address in assembly

Can you convert a bytes20 to address in assembly (not solidity-typecasting)? If so, how?
dNyrM's user avatar
  • 948
1 vote
0 answers
98 views

How to values in mapping type struct with solidity assembly?

I have a special needs, store the mapping type struct with assembly code. thank you very for everyone who can response this question. Need your help how to write something in assembly Here is how I am ...
Umer Aqeel's user avatar
1 vote
1 answer
285 views

Grab last 12 bytes of a bytes32

How do I grab the last 12 bytes of a bytes32 in assembly? For example, the last 12 bytes of bytes32 num = 0xdeb02111e4e5fa8c7c05e983a3446893a36d12ad6d79206163636f756e740000 Thanks!
dNyrM's user avatar
  • 948
0 votes
1 answer
67 views

how to return tightly packed storage values in assembly

I have a contract with 2 tightly packed values in storage slot1, how do I return the second address value with assembly? Contract MyContract{ bool a; address b; function getAddress() public ...
Panda Power's user avatar
1 vote
1 answer
96 views

Grab the last 32 bytes of 64-bytes input

In assembly, how do I grab the last 32 bytes in a 64-bytes input? I know that this code is for grabbing the first 32: bytes32 half; assembly { half := mload(add(accData2, 32)) }
dNyrM's user avatar
  • 948
0 votes
1 answer
178 views

How to understand the difference between transfer and function call using assembly call(g,a,v,in,insize,out,outsize)

I understand that if there is an external function call, it will use all 7 parameters of the call(g,a,v,in,insize,out,outsize). However, I got a question I know low-level transfers like .transfer() ...
Yu.Pan's user avatar
  • 15
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
314 views

How to get internal calls Calldata in solidity?

How to get signature of setA() when user is calling setB() for below code snippet ? contract Sig { function setA() public { // How to get function signature of `setA()` at this location while ...
Namit Jain's user avatar

1
2 3 4 5
7