Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
84 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 ...
2
votes
1answer
55 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....
0
votes
1answer
18 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? ...
1
vote
0answers
15 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 ...
4
votes
3answers
1k views

Understanding solidity inline assembly code

Here is a code from solidity documentation: function sumAsm(uint[] _data) public returns (uint o_sum) { for (uint i = 0; i < _data.length; ++i) { assembly { ...
0
votes
0answers
10 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, ...
2
votes
1answer
131 views

Using 'call' from a constant function

I am trying to determine the behavior of call when executed from a constant function. Of course, the compiler issues a warning on that: Warning: Function declared as view, but this expression (...
1
vote
0answers
23 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
78 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
49 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
41 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 ...
0
votes
1answer
26 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 := ...
1
vote
1answer
200 views

Concatenating byte strings in assembly for call input data

I have the following piece of code in my contract. It's supposed to take in a byte string composed of a uint flag that is followed by a variable list of uint numbers and contruct a call using those ...
2
votes
1answer
39 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
2answers
148 views

Accessing private variables using assembly

I would like program an oracle service which I would like to charge a fee for. Therefore, I would store the data of interest as a private variable in my oracle contract. This private variable should ...
4
votes
3answers
369 views

convert bytes to uint8[8] using mstore()

I know how to convert bytes to uint8[8] using mload but mstore seemed like it could be more gas efficient. Is something like this possible? function bytesToUintArray(bytes input) returns (uint8[8])) ...
0
votes
1answer
26 views

How to call sha256 in assembly

I wanna compute sha256 in Solidity Assembly for hash of getting bytes slice.
0
votes
1answer
195 views

Return subset of variable-length array

How does one return the first x elements of an array of addresses? I'm pretty sure this can be done in assembly but could not find the reference.
3
votes
1answer
108 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 ...
6
votes
4answers
1k views

Get address from public key in Solidity

The address is the last 20 bytes of sha3(publicKey) In Solidity, using assembly if needed, how could I splice the first 12 bytes from sha3(publicKey) and get the address? What I came up with runs out ...
0
votes
1answer
64 views

How to get the last n bytes of a bytes32 in assembly?

I have the following code: function getBytes5() public returns (bytes5) { uint256 x = now; bytes memory inBytes = new bytes(32); bytes5 outBytes5; assembly { mstore(...
0
votes
1answer
36 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
33 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 ...
1
vote
3answers
155 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
1answer
101 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
42 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
60 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
31 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
23 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
46 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
105 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 ...
1
vote
1answer
75 views

Upgradability Proxy ADMIN_SLOT assembly sstore does not update

I'm currently playing around with Proxy Upgradability, and noticed the use of assembly in terms of the new upgraded contract and the slot assigned. Real implementation can be seen here. I have ...
2
votes
0answers
32 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() ...
6
votes
3answers
4k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
1
vote
1answer
88 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 ...
1
vote
0answers
74 views

Function selector computed differently for libraries?

As documented in various places, the function selector is computed as the first four bytes of the keccak256 hash of the function header, which consists of the function name followed by the list of ...
0
votes
1answer
80 views

How to call ecrecover() in pure assembly?

If I do remember correctly, it’s a contract built‑in in the Ethereum Virtual machine, isn’t it? if yes, what’s the address to call for it?
2
votes
0answers
37 views

How to get a call graph for the binary code of a contract?

I need a call graph generator for the assembler level of smart contract code in order to analyse solidity compiler bugs. In that way, porosity is excatly what I need ! However there are too much bugs ...
1
vote
0answers
52 views

When I call tranfer_from function, remix saids gas limit exceed

I am owner of the token contract, And when I call transfer_from() function, remix saids gas limit exceed. my gas limit is 300000. this is same contract, and call transfer_from() successfully. "https:/...
8
votes
1answer
602 views

What is the cryptic part at the end of a solidity contract bytecode?

Given the following contract: pragma solidity ^0.4.11; contract Simple { bytes32 public v; function set(bytes32 _v) { v = _v; } } When disassembling, neither remix, solc or evm ...
0
votes
0answers
68 views

How to get the result from another contract's Optional method while return empty if it does not exist or throws?

For example I want to write a contract where when one passes the address of another contract to it, it will check whether this other contract has the name() function, and if the name() function ...
1
vote
1answer
44 views

Is the gast cost of '<=' lower than the gas cost of '<'?

I've been debating on whether I should use < or <= in a for loop. So I decided to conduct a small test and verify that their gas costs are the same. Here is my contract: pragma solidity 0.4....
1
vote
1answer
139 views

How to construct deployable bytecode from runtime bytecode?

For example I want to redeploy/clone a contract to another address but don't have the original source code, so I only have the runtime bytecode stored on the blockchain. If I try to deploy the runtime ...
0
votes
1answer
30 views

Call to other contract method return false when two parameters are passed

Caller Contract Called.call(abi.encodeWithSignature("test(address, address)"),empAddress, empContAddress) Called Contract event ad(address); function test(address e, address f)public{ ...
2
votes
1answer
94 views

Solidity: Saving arbitrary data into bytes array and later parsing it

I want to create a function that receives two addresses and saves them into a bytes array. later a matching function will receive this bytes array and parse the two addresses. function ...
1
vote
2answers
108 views

Using mstore to copy bytes32 does not work, why?

Why does mstore(c, p) not copy p to c? function test()returns (bytes32) { bytes32 c; bytes32 p = 0xFF; assembly { mstore(c, p) } return c; }
1
vote
1answer
186 views

Solidity: Raise events via Assembly using log3

I want to raise events from inside a piece of assembly code. I've extended the answer here with the function AssemblyEvent() which currently causes a runtime error. Working example: pragma ...
1
vote
1answer
123 views

Converting from Assembly to Solidity

I am trying to convert the assembly code into Solidity given at the link: What is a function Selector The code is trying to invoke the function func(...) of Contract1 given below: contract Contract1 ...
2
votes
2answers
163 views

Where is the length of an array located in terms of memory layout?

For example, given the following cases: uint[3] memory arr; uint[] memory arr = new uint[](3); Suppose I try to access arr from within an assembly block (using mload, for example). Where (...
2
votes
2answers
147 views

How can I peek into the stack using inline assembly?

I am specifically interested in calling a function whose return-type is unknown to me. More precisely: The contract which owns the function has had several versions over time My contract may call ...