Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
2answers
322 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])) ...
8
votes
1answer
423 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
54 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 ...
3
votes
2answers
948 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 { ...
1
vote
1answer
33 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
25 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
1answer
76 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
1answer
34 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
18 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{ ...
1
vote
1answer
23 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
65 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
59 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
53 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
68 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
100 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 ...
1
vote
1answer
138 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 ...
0
votes
2answers
47 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 ...
1
vote
0answers
57 views

delegatecall (assembly) didn't change state variable in Remix with Web3 Provider

I am trying to test proxy pattern in Remix, which connected to my private chain with Web3 Provider. By the way, miner is working all the time. After invoking add function of Proxy contract, the state ...
0
votes
1answer
172 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.
0
votes
1answer
36 views

How does this assembly function work?

From the Docs, how does this operation create a new "memory end"? mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))) Context: library GetCode { function at(address _addr) public ...
1
vote
1answer
98 views

How to get access to the storage array through the solidity assembler?

If the array is located in memory, then all the elements are in sequence, for example: uint256 arrLength = arr.length; assembly{ let offset := sload(arrLength) res:= mload(...
0
votes
1answer
57 views

How to split bytes32 into multiples of 8 in solidity

I want to split bytes32 into multiples of 8 (in assembly). I have the following code(After referring here): function testAssembly(bytes32 _msg) public pure returns (bytes8 i, bytes8 j, bytes8 k, ...
0
votes
1answer
76 views

Difference in “delegate call via assembly”

I came across a different version of delegate call via assembly and also tried all of them - no different result so far. How does it differ and which is the best version to use? OpenZepplin version: ...
1
vote
1answer
44 views

Read more than 32 bytes from memory (Assembly)

Assume I am passing a variable bytes (memory) to a function. This variable corresponds to A concatenated with B where A is of size 32 and B is 96 bytes, how can I return A (bytes32) and B (bytes). ...
1
vote
1answer
267 views

In-line assembly error

I am checking if an address is a smart contract. Similarly to many articles and example-codes out there, i do this within my function: uint32 size; assembly{ size := extcodesize(_to) } if(size &...
2
votes
1answer
16 views

What is the alternative to using **label** in solidity inline assembly code?

What is the alternative to using label in Solidity inline assembly code? Label is deprecated in new version.
2
votes
1answer
36 views

Understanding first evm word of reference types in assembly

Given the following function: function getArrayItems(bytes calldata) external returns ( bytes4 _signature, bytes32 _wutIsThis, bytes32 _length, bytes32 _firstItem ) { assembly { ...
2
votes
1answer
141 views

Solidity assembly function call parameter alignment

I am trying to call a function using assembly. The called function has address parameters. How to use address in assembly call? Called function example: function isSameAddress(address a, address b) ...
2
votes
1answer
106 views

can anyone help to explain calldataload

In the Solidity documentation, the definition of calldataload is: calldataload(p) call data starting from position p (32 bytes) But I am really confused by what is call data. Is the call data of ...
1
vote
1answer
41 views

why use up all the gasLimit when use assembly and revert together?

try to call erc20 token's transferFrom() using assembly(to save some gas), code like this: pragma solidity ^0.4.24; contract TestAssemblyAndRevert { function test(address from, address to, ...
1
vote
1answer
33 views

Is it possible to get a function's original returndata if it is wrapped in an interface that doesn't return anything?

Will a function's returndata persist through a wrapper, even if the wrapper does not support a return value? An example would be as follows: contract OriginalContract { function originalFunction()...
2
votes
1answer
2k views

How to find keys mapped to valid values in a given range (n_start, n_end) at runtime?

My question is related to finding keys mapped to valid values in a given range (n_start, n_end) at runtime using minimum gas, if possible. mapping(uint => myStruct) clusterContract; uint contains ...
1
vote
0answers
99 views

EVM Assembly tags

Studying the Solidity optimizer, I found that the assembly code is divided into tags and the optimizer doesn't work between them: It splits the sequence of instructions into basic blocks at JUMPs ...
0
votes
1answer
32 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(...
13
votes
2answers
3k views

isContract function using EVM assembly to get the address' code size

My problem is that I need to make sure my contract processes only the transactions coming from EOA (externally owned accounts). For this I need to determine the type of account I'm dealing with. In ...
1
vote
0answers
61 views

Proxy contract DELEGATECALL to pass a DYNAMIC array to a function in the target contract

I'm trying to get a Proxy contract to correctly do a delegatecall to a function in another 'target' contract. The problem is, that I need to pass a dynamic array as the parameter to this function. Q: ...
0
votes
0answers
123 views

How to use solidity assembly Opcodes (returndatacopy) to assigning into a variable

I want to write a generic getData function like this below. But I can only return string data or bytes32 data. When I return bytes32 string type data got vanished. When I return string type data ...
2
votes
2answers
351 views

how to join two bytes32 values in solidity?

Below is work example of joining two bytes arrays. I wonder how I can join two bytes32 using assembly or solidity? two bytes32 values should serve as an input and a joined bytes32 is an output. ...
0
votes
1answer
310 views

Convert bytes to uint256[]

I am writing an implementation of ERC777TokensRecipient. So that means a function function tokensReceived(address operator, address from, address to, uint256 amount, bytes data, bytes operatorData) ...
7
votes
1answer
163 views

When did the Ethereum “free memory pointer” change? (6060… -> 6080…)

I have been digging a bit deeper into the Ethereum bytecode with the specific goal to do contract verification from the source code. I noticed, while doing some tests, that the initial bytes of the ...
5
votes
3answers
938 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 ...
8
votes
2answers
811 views

How can a factory contract clone the bytecode of an existing contract?

Using new to create a contract causes the factory contract to compile with the product contract's bytecode appended to the end... contract Foo { function Foo() {} } bytecode: 60606040525b600056 ...
57
votes
2answers
20k views

What OPCODES are available for the Ethereum EVM?

The Ethereum virtual machine has a large number of operation codes and base level instruction sets. Is a complete listing available?
1
vote
1answer
219 views

How do I construct a call to contract return string using inline assembly?

pragma solidity ^0.4.21; contract Test1 { function add(int a, int b) returns(string){ //Simply add the two arguments and return return "Qmrwokdkeoiudkeooiskelpdislpeosj;sd[opek;s[pkfe,;...
0
votes
1answer
179 views

Assembly call instruction address as single integer

The following function is a function of a library (The code is written in Solidity). It has an assembly instruction that I do not understand. Specifically at line call(sub(gas, 2000), 6, 0, input, ...
1
vote
1answer
270 views

Assembly opcodes

I need some help understanding assembly functions pragma solidity ^0.4.23; contract Test { function addTest() public pure returns (uint c) { bytes memory b = new bytes(1024); assembly { c:...
1
vote
1answer
84 views

Compile standalone assembly

The solidity wiki explains that standalone assembly is also possible. However, I cannot compile it. For example: { mstore(0x40, 0x60) // store the "free memory pointer" // function dispatcher ...
12
votes
1answer
386 views

How to generate sugared assembly code from Solidity code?

In the Solidity documentation I see a sample assembly code: { mstore(0x40, 0x60) // store the "free memory pointer" // function dispatcher switch div(calldataload(0), exp(2, 226)) case ...
2
votes
1answer
297 views

Get return data from delegatecall

I'm using a low level delegatecall to forward my calls to a library. I need to (in this order) : load bytes4 sig into _message from memory load bounty (STRUCT) into _message from storage load bytes ...
2
votes
1answer
259 views

Optional Multi-Parameter Call to External Contract

I would like to half implement ERC223 for business reasons. This means being able to notify other contracts when they receive tokens, but not revert if the recipient is a contract that doesn't ...