Questions tagged [assembly]
The assembly tag has no usage guidance.
158
questions
0
votes
0answers
20 views
test return value of transaction
contractA
function test() internal {
stateVariable = 20;
uint num = 20;
assembly {
mstore(0x00, num)
return(0x00, 0x20)
}
}
How do I test the return ? I am using hardhat , but i don'...
3
votes
1answer
28 views
Can abi.encodeWithSignature be optimized by pre-compute?
I have a proxy implementation with method exchange and delegator with method exchange2 with the following code:
function exchange2(int128 i, int128 j, uint256 dx, uint256 min_dy) public {
(...
1
vote
1answer
54 views
What programming languages was Uniswap's open-source code written in?
Uniswap is a decentralized exchange that is actually a decentralized app where people can trade ERC-20 tokens without a middleman.
Uniswap's code is open-source:
https://github.com/Uniswap
Was the ...
0
votes
0answers
10 views
how to access the element of struct in array and mapping using assembly?
how to access the element of struct in array and mapping using assembly?
my code case:
contract Test {
struct User {
address addr;
uint256 tokenAmount;
}
mapping (uint256 =...
0
votes
0answers
14 views
staticcall - what does this code do?
I'm lost, does anyone understand this code?
assembly {
success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60)
// Use "invalid" to make gas ...
1
vote
1answer
55 views
How much C++ is needed to write smart contracts?
Solidity seems to be written in C++ so does that mean that smart contracts require some level of C++ programming skills to get by? How much background knowledge is required for writing a simple one or ...
1
vote
1answer
81 views
Instantiating a smart contract in Uniswap using assembly and create2
I am studying Uniswap source code and there is something I do not understand in this file:
https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2Factory.sol:
This factory can ...
0
votes
1answer
26 views
Why chainid is done in assembly in UniswapV2ERC20
I am studying uniswap solidity source code and there is something i do not understand in UniswapV2ERC20 constructor:
uint chainId;
assembly {
chainId := chainid
}
(pasted from https://github.com/...
1
vote
0answers
9 views
How do I get solcjs to compile yul
I want to write a smart contract using pure Yul but I have no idea how I'm meant to configure / run solcjs to compile my yul code down to bytecode. Any pointers would be much appreciated.
0
votes
1answer
67 views
Encode data into a single bytes variable using assembly
I'm currently testing a few things using the Solidity assembly. Basically, what I want to do is
Pack several variables of different type together into one bytes array i.e. similar to what abi....
0
votes
0answers
29 views
How to pass a non-deployed Smart Contract to a deployed contract and call a function on it?
I'm currently trying to pass a Smart Contract (which is NOT deployed) in byte code format as an argument to another Smart Contract (which is deployed).
From within the deployed contract I want to run ...
0
votes
1answer
53 views
Is it possible to access struct field from in-line assembly (Yul) when using ABIEncoderV2?
Is it possible to access struct field from Yul? Ideally it could look like this:
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
contract Sample {
struct S {
uint256 n;
...
0
votes
2answers
75 views
Parameters for delegatecall in inline assembly
I am trying to perform a delegate call from inline-assembly and I am unable to wrap my head around how to access the memory variables assigned outside the assembly block.
function() external payable {
...
0
votes
0answers
10 views
How to deploy a compiled stateless contract and which doesn t have creation code/transaction?
I got a deployed contract bytecode from an internal project which I d like to publish on the mainnet.
The problem is it s just the bytecode without the creation code.
Is there a simpler way to deploy ...
4
votes
1answer
35 views
Copy and deploy a smart contract from opcodes without source code
I extracted opcodes from an already existing and deployed smart contract and I would like to know if it is possible to deploy an exact copy of this contract from its opcodes?
My extracted opcodes ...
0
votes
0answers
24 views
Unable to reference local variable in-line assembly
I am unable to compile a contract that references a local variable in in-line assembly.
Here is the code:
pragma solidity ^0.5.0;
/**
* @dev Contract module that helps prevent reentrant calls to a ...
2
votes
1answer
72 views
Most gas efficient way to check if byte array contains zeroes?
I have a contract that I pass data packed into an array of uint256 (as it's apparently cheaper to use uint256 over bytes32) and each byte in the uint256 contains positions referencing another array of ...
0
votes
1answer
54 views
how do i pass by reference?
I have a couple of questions.
First:
So, In a function, i created memory array. I want to pass this memory by reference to another function..
function test2() public returns(uint a) {
uint[2] ...
1
vote
0answers
41 views
copy array from storage to memory
uint[2] testStorage;
function assemblyStorage() public returns (uint a, uint b){
testStorage[0] = 5;
testStorage[1] = 10;
uint[2] memory testMemory = testStorage;
...
0
votes
1answer
40 views
why does this contract ask to increase gas limit?
string test;
function assemblyStorage() public payable returns (string memory a){
test = "good";
assembly {
a:=sload(0)
}
}
I am trying to return the string ...
1
vote
0answers
20 views
why do i have to specify memory in arguments?
My function body looks like this:
function element(uint a, uint b, uint[2] memory c) public returns(uint e, uint f, uint g, uint k) {
I am wondering why do I put memory keyword before c ? I know that ...
1
vote
0answers
21 views
why mload(0) returns wrong number?
int x; // Storage slot #0
mapping (uint => uint) y; // Storage slot #1
uint [] z; // Storage slot #2
function element() public returns (uint a, uint b, uint c) {
z.push(45);...
1
vote
0answers
55 views
how do storage and memory variable work?
So, in an ordinary programming language, we have stack and heap.
Reference types such as array gets stored in heap. and the variable which holds the address(pointer) of this array is stored in stack..
...
2
votes
1answer
31 views
where does function variables get created?
function element() public returns (uint) {
uint test = 20;
return test;
}
Where would test variable be created ? in memory or stack ?
The funny thing is from testing assembly, I can see that it'...
1
vote
1answer
58 views
sload. assembly with struct - not working in solidity
struct S {
uint128 a;
uint128 b;
}
S test1;
function assemblyStorage() public returns (uint a, uint b, uint c, uint d, uint f, uint g){
test1 = S(5,10);
assembly {
a:=sload(0)
}
}
...
1
vote
0answers
18 views
Trying to understand the ethereum stack
I've been trying to understand the limits of the stack and how it works. It seems like the "Stack too deep" error only happens if there is an assembly block in the function. Without an ...
0
votes
1answer
26 views
Solidity 0.6.x - when is it mandatory to use assembly (with examples)?
Solidity's development is very active and, if compared to several other codes, stable releases are updated quite frequently. Which cases need assembly as mandatory feature for Solidity release 0.6.x? ...
0
votes
0answers
13 views
Can I put the inline assembly code as function argument string?
Assume there is an example as below:
pragma solidity >=0.4.11 <0.6.0;
contract C {
uint b;
function f(uint x) public view returns (uint r) {
assembly {
r := mul(x, ...
1
vote
0answers
26 views
Conditional in assembly
I am trying to use a conditional (like an if statement) in assembly. The only assembly reference site I have ever been able to find says the opcode JUMPI is the way to do this.
Using solc 0.7.0, the ...
0
votes
1answer
94 views
How to get data location for string > 31 length
The documentation says:
bytes and string are encoded identically. For byte arrays that store
data which is 32 or more bytes long, the main slot stores length * 2 +
1 and the data is stored as usual ...
1
vote
2answers
138 views
In assembly… can't get delegatecall to work
Delegatecall can be used in either solidity or assembly.
In solidity, I can get it working with the following code:
bytes memory payload = abi.encodeWithSignature ("get_value(uint16,uint16)",...
0
votes
2answers
53 views
How do i retrieve Eth from a contact that i created?
New to blockchain.. havent a clue.. I managed to create a new contract with Eth. I moved money from MyEtherum Wallet to Metamask and into a contract, somehow? I have no coding experience but need ...
2
votes
1answer
74 views
Parameters on evm opcode create
Why the usual way to create a contract with evm opcodes use add and mload, for example:
bytes memory bytecode = hex"600580600c6000396000b800602a600052b8";
...
assembly {
_address := ...
2
votes
1answer
55 views
Get return value of a low level call
I'd like to get the return value of a low level call.
(bool success, ) = address(0x1234...7890).call{value:0}(callData);
This post discusses a solution that sounds like it should work, but it doesn'...
1
vote
1answer
47 views
How to call sha256 in assembly
I wanna compute sha256 in Solidity Assembly for hash of getting bytes slice.
3
votes
1answer
164 views
Why does Gnosis' MultiSig passes less gas than available in external_call?
Gnosis' MultiSig Wallet substract a fixed amount of gas (34710) when calling an external address.
function external_call(address destination, uint value, uint dataLength, bytes data) internal returns ...
0
votes
1answer
53 views
Calling another contract's state-changing function as view function
In Web3 we can do TestContract.methods.myMethod(myParam).call() to call a state changing function without executing it. But I am wondering if this is possible in Solidity or inline-assembly? So in ...
0
votes
1answer
44 views
Write uints as bytes to create one larger bytes
I would like to take three uints and essentially concatenate them together as one bytes variable. What's the simplest way I can do that? I've seen many posts about people writing full-blown code to ...
0
votes
1answer
226 views
Factory contract to clone existing contracts
I am researching about Factory contract to clone existing contracts, First is the implementation present at https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol. I don't ...
3
votes
1answer
218 views
How to get access to the storage mapping through the solidity assembler?
referencing the question How to get access to the storage array through the solidity assembler? I have been trying to figure out how to access the mapping (or variable y from the question). The ...
2
votes
1answer
56 views
is there any advantage of using inline assembly call over address.call?
Is there any advantage of using inline assembly call over address.call?
For example
// address addr
// uint value
// bytes memory data
// using inline assembly
assembly {
call(gas, addr, value,...
1
vote
1answer
165 views
Using assembly to create a fallback function with a return value?
Is it possible to use Solidity assembly to create a fallback function that makes a DELEGATECALL to another contract, and then uses assembly to correctly store the return value of the DELEGATECALL in ...
0
votes
1answer
41 views
why does keccak256 in assembly require 2 arguments?
Why does keccak256() in assembly require 2 arguments? What is the second argument?
assembly {
let foo := keccak256(4)
}
returns error
Function expects 2 arguments but got 1.
1
vote
1answer
25 views
get length of nested array in assembly
How to get length of foo[1] in example below in assembly?
uint[][] foo; // foo.length = 2, foo[1].length = 3
function getLength() returns (uint len) {
assembly {
len := sload(foo) // ...
0
votes
1answer
62 views
Listen to a solidity event from a smart contract function [duplicate]
I have the following event:
event WaitingPlayer2(address indexed player2);
Which I call through:
function partecipateAsPlayer2(address player2) public{
emit WaitingPlayer2(player2);
}
Is ...
1
vote
1answer
188 views
Clone factory and constructor arguments
In my project I'm using a Clone Factory:
https://github.com/optionality/clone-factory/tree/master/contracts
function createClone(address target) external returns (address result) {
bytes20 ...
2
votes
3answers
490 views
Passing constructor arguments to the CREATE assembly instruction in solidity
I have a contract which deploys other contracts by bytecode:
contract DeployContract {
function deploy(bytes calldata _bytecode) external returns(address addr) {
bytes memory bytecode = ...
2
votes
0answers
33 views
In solc 0.4.x assembly, how can I check if a non-constant function returns 'bool' or nothing?
I know how to do it for a constant function, for example:
pragma solidity 0.4.25;
contract Callee0 {function func() external pure returns (bool) {return false;}}
contract Callee1 {function func() ...
2
votes
1answer
83 views
Modifying simple function with inline assembly
I'm trying to write a super simple contract that's gas efficient utilizing inline assembly in solidity. All this function needs to do is create a child smart contract with one function, self destruct....
1
vote
1answer
157 views
Accessing struct fields from assembly block
Say we have the following structure:
struct MyStruct {
uint256 x;
uint256 y;
}
and that it is passed as an argument to some function. Inside that function, we have assembly block from where we ...