Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
37 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
29 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
23 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
10 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
0 answers
13 views

how this function do in the stack, calldata, and memory

I am not familiar with the inline assembly. May I ask what happened in the arrLength method and how it operates in stack, memory, and calldata pragma solidity 0.4.5; contract Test { // for ...
LEVI_104's user avatar
0 votes
1 answer
53 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
89 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
68 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
  • 598
3 votes
2 answers
81 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
2 votes
3 answers
203 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
  • 598
1 vote
0 answers
31 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
517 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
23 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
56 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
1 vote
2 answers
527 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
54 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
1 vote
2 answers
249 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
  • 405
0 votes
0 answers
99 views

How to use keccak256 in assembly instead of keccack256(abi.encodePacked(address))?

I'm trying to use assembly to compare the gas usage of two implementations of the same function. The following works correctly: // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.17; import ...
Javier Villanueva's user avatar
0 votes
0 answers
24 views

Difference between TIMESTAMP and block.timestamp

I have two questions: I went to the link: https://ethervm.io/ and saw TIMESTAMP in the Mnemonic column and block.timestamp in Stack output. Please guide me what is the difference between Mnemonic ...
zak100's user avatar
  • 1,406
0 votes
0 answers
21 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 { ...
Ryan Sea's user avatar
  • 598
0 votes
2 answers
209 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
  • 675
1 vote
0 answers
48 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
0 votes
1 answer
128 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
  • 675
0 votes
1 answer
29 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
0 votes
1 answer
44 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
  • 675
0 votes
1 answer
71 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
3 votes
2 answers
779 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
203 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
0 votes
1 answer
289 views

How could you replicate foundry's vm.load cheatcode with solidity code?

I assume it would need assembly and potentially a delegatecall function, but I have been stuck trying to get anything that could work. The idea is that we would input the contract address and the ...
Yan Digilov's user avatar
0 votes
2 answers
120 views

Appending address array through assembly

I have an assembly part which creates an address which I want to append to an array in an address => address[] mapping. The code works if I use push() but I am trying to reduce gas usage and have ...
gsh192's user avatar
  • 1
2 votes
1 answer
80 views

Does the free memory pointer need padding?

This code is taken from the solidity documentation. library GetCode { function at(address addr) public view returns (bytes memory code) { assembly { // retrieve the size of the ...
yaxnaw's user avatar
  • 23
1 vote
2 answers
106 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
0 votes
1 answer
39 views

Most gas efficient way to convert uint256 into a handful of uint8s

I am working on a card game. I have a problem where I am choosing to store a representation of 32 uint8s inside one uint256 word in order to save on gas. I store the uint256 word and then want to ...
VoR0220's user avatar
  • 1,710
1 vote
0 answers
41 views

Why evm assembly push4 sometimes doesn't push the value in parameter?

I'm analyzing the fail of this tx on goerli My question is not really about the tx, but about a strange behaviour when I debug it on remix. I'm calling a proxy who called the implementation with ...
Fabien's user avatar
  • 41
1 vote
1 answer
177 views

Is there a way of getting the stateRoot of the last block in a contract?

So i was curious if you could write a contract, that retrieves the StateRoot from the last mined block. I found a Repo from Keydonix, who used the stateRoot from previous blocks to calculate a more ...
Mango's user avatar
  • 13
0 votes
0 answers
16 views

Accessing an internal function in my contract via assembly in another function

I have this block of code that compares hashes of bytes and I would like to convert directly into assembly: uint skipPointer; // prevents excess search if a match has been found uint ...
EKN's user avatar
  • 31
0 votes
0 answers
86 views

Gnosis sqrt function vs Uniswap sqrt function

The Uniswap sqrt function makes sense to me. I can input 100 and it returns 10. Gnosis on the other hand has a gnarly 368 lines of code expressing the same function (I think) but the return value is ...
alpo's user avatar
  • 144
1 vote
1 answer
176 views

How do I manipulate the elements of a memory array in assembly?

Simple example: Let's say I have a function that takes a fixed size array, finds the largest number in it, and returns another fixed size array in memory with the largest number as the last index: ...
EKN's user avatar
  • 31
0 votes
1 answer
58 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
48 views

get uint value inside a bytes32 slice

I have the following code: function test_bytes(bytes32 test) external pure returns(bytes3 idx,uint256 idx2) { //test = ...
Jhonatan's user avatar
0 votes
1 answer
19 views

Problem with expensive function

I have next code : struct Data { uint id; string name; string Surname string moreInfo; } mapping(address => Data[]) private ownerauto; address[] private owners string[] ...
Kilo Arms's user avatar
1 vote
0 answers
328 views

Solidity assembly code - calldatacopy, delegatecall

I have been trying to understand how assembly code works,spending lots of hours, but I could not. Please help me Basically, I am digging into a proxy contract, and I do not really understand ...
DHC's user avatar
  • 199
1 vote
2 answers
36 views

What is the return value of this asembly code?

Taken from this repository /// @notice Generate number function asmbl() public view returns (uint8 b) { assembly { let c := add(27, 16) mstore(0x80, c) { let d := add(...
Superluminal's user avatar
0 votes
0 answers
74 views

Solidity assembly function returns false on forked blockchain

I try to simulate submitting transaction to Multisig contract and confirming transaction by other multisig members by impersonating their account on Hardhat with forking. I managed submitting and ...
Sergen's user avatar
  • 1
1 vote
1 answer
31 views

Transalte Assembly(Solidity)

I want translate code to assembly, but i don't understand , how i can get data from string ( or bytes) Example String: 123 --> uint 123 for (uint256 i = 0; i < bytes(_str).length; i++) { ...
Kilo Arms's user avatar
0 votes
1 answer
31 views

Why is memory used by RETURN misaligned compared to how it was allocated?

I am experimenting with evmone and evmc to execute some simple assembly code snippets on EVM. I wrote a test that is supposed to return 0x42 as output data. The code goes as follows: PUSH 0x42 PUSH ...
radrow's user avatar
  • 103
1 vote
1 answer
265 views

What are the two arguments in revert opcode?

I am trying to understand the revert opcode and how it works . I understood that it will stop the execution of current context and return 0 to the calling context. It seems it also takes in 2 ...
infamousdegen's user avatar
0 votes
1 answer
97 views

Finding max of a memory array in assembly

Practicing my solidity assembly skills and I'm using foundry to test this function. For most inputs it works, but fails when There is a 0 present in the array Possibly duplicate values present in the ...
zzzzz's user avatar
  • 1
2 votes
2 answers
497 views

Solidity Assembly Code create2 function

I am new to solidity, can you please explain the create2 function? assembly { pair := create2(0, add(bytecode, 32), mload(bytecode), salt) }
Shakeel Khan's user avatar
0 votes
1 answer
159 views

What is the "solidity scratch pad"?

I'm reading up on upgradable proxies, came across this in openzeppelin. //solium-disable-next-line assembly { // Copy msg.data. We take full control of memory in this inline assembly ...
Bruce's user avatar
  • 867

1
2 3 4 5 6