Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [assembly]

The tag has no usage guidance.

0
votes
1answer
25 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
19 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
38 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
22 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
13 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
22 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
51 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) ...
1
vote
1answer
25 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()...
1
vote
1answer
37 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, ...
2
votes
1answer
48 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 ...
0
votes
1answer
37 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
24 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
0answers
33 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
89 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 ...
0
votes
1answer
175 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) ...
1
vote
2answers
162 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. ...
8
votes
1answer
126 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 ...
0
votes
1answer
139 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
113 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 ...
1
vote
1answer
183 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:...
2
votes
1answer
232 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
171 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 ...
1
vote
1answer
33 views

Why is mstore not working here? (assembly)

function debug() returns (bytes) { bytes memory ret = new bytes(6); bytes memory word = new bytes(6); word = hex"61626f757400"; assembly { mstore(add(ret, ...
1
vote
1answer
64 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 ...
0
votes
2answers
205 views

Combining two 32 byte values (bytes32) into a 64 byte value

I am passing 64 byte public keys into my solidity function as two 32 byte parts, high 32 bytes and low 32 bytes. How do I combine them back to a 64 byte value in Solidity (cost efficiently)? Looping ...
1
vote
1answer
169 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
209 views

Is there a difference between the call stack and the “normal” stack?

I cannot find any good source on this. The "normal" stack is where all PUSH opcodes put their bytes on. The "call stack" could be some other stack where either call data or addresses are put on - ...
1
vote
1answer
47 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; }
0
votes
1answer
51 views

Convert two int128 variables to Bytes32 and back

For Bytes32 to 2x int128 I have working code. I've adapted code from this stack Exchange answer function bytes32to2xint128(bytes32 z) pure public returns (int128 x, int128 y){ bytes16[2] memory ...
0
votes
1answer
243 views

How can assembly be used to add bytes together? [duplicate]

To store data on the blockchain, a storage container bytes[6] data is used, each array stores maximum amount based on block gas limit. Can assembly be used to add those 6 arrays together, and return ...
4
votes
2answers
2k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
4
votes
2answers
309 views

Returning values from Solidity function that does not define a return?

I'm a bit confused by the code at this smart contract, which is part of the Aragon project code: function delegatedFwd( address _dst, bytes _calldata, uint256 _minReturnSize) internal { ...
0
votes
1answer
100 views

Forward call to another smart contract

I have created a smart contract using a factory method pattern as follows: contract MyContractFactory is Ownable { function create(...) onlyOwner public returns (MyContract) { return new ...
-1
votes
2answers
129 views

Plot a gaussian distribution in Solidity

are there any libraries to plot a gaussian distribution, and measure position along that curve? like https://github.com/errcw/gaussian in javascript
2
votes
0answers
75 views

Append address to bytecode and then deploy it

I'm trying to write a deployer function which would allow me do deploy arbitraty code. So far, I can deploy a contract with parameters using this snippet found here: // js truffle const tokenWeb3 = ...
1
vote
1answer
426 views

Solidity assembly question - mstore

I was searching on how to convert a uint to bytes in Solidity and found this answer. function toBytes(uint256 x) returns (bytes b) { b = new bytes(32); assembly { mstore(add(b, 32), x) } } ...
1
vote
2answers
413 views

Solidity to inline assembly

Taken a smart contract like the following: contract A { address public beneficiary; function A(address _beneficiary) public { beneficiary = _beneficiary; } function () ...
2
votes
1answer
360 views

Accessing array elements with inline assembly

Using a loop in inline assembly compared to a regular solidity for loop saves around 20% in gas cost. I'm struggling however with looping over an array through inline assembly. Is this possible and ...
1
vote
1answer
327 views

Add data to an array in assembly for solidity

Hi I'm trying to make a function in assembly inline with following purpose: Given: An array in the blockchain with names (= bytes32[] _documentHashes). Asked: Find which indexes are equal to the ...
1
vote
0answers
30 views

Solidity VM memory management

I'm trying to do an external function call in assembly. So I have to prepare a memory area that store the input args. But where's the address that I should start with mstore? I mean, there are some ...
0
votes
1answer
227 views

What does the assembly part of this function do? (in receiveApproval )

I'm trying to wrap my head around the approveAndCall() function, because I want to allow users to pay for functions of my main contract with the associated tokens. I'm trying to understand the ...
8
votes
1answer
485 views

How could msg.sender != tx.origin AND extcodesize(caller) == 0 be true?

I'm working on a puzzle where msg.sender != tx.origin, so the implication is that the caller needs to be a contract or at least something in between the calling account. But extcodesize(caller) == 0 ...
1
vote
0answers
398 views

Cast bytes to bytes32 using assembly [duplicate]

Is there any way of converting bytes into bytes32 using solidity assembly? (avoiding a loop, and knowing the size of the input bytes array)
2
votes
1answer
240 views

Out of gas exception when calculating Keccak256 inline solidity assembly

I am trying to write a simple function which should return me Keccak256 of an incoming uint using Solidity inline assembly function, however it returns me out of gas exception when trying to execute ...
1
vote
0answers
80 views

Should I not use this string-byte type casting assembly code?

My string to bytes32, bytes32 to string code is below. function _stringToBytes32(string _string) internal pure returns (bytes32 _bytes32) { require(bytes(_string).length < 33)...
0
votes
1answer
97 views

SHA3_512 library, convert the input and output to 512-bit bytes

The SHA3_512 library takes an input uint64[8] and outputs uint32[16]. To convert the input from 64 bytes and the output back to bytes, I wrote this, but it gives the wrong result. What are some ...
3
votes
2answers
292 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])) ...
1
vote
1answer
541 views

hexadecimal (bytes) to binary (uint) in a smart contract

What are some ways to convert from bytes8 hexadecimal to uint64 binary?
2
votes
2answers
332 views

Get public key from signature in a smart contract (note, public key, not address)

Are there any libraries to get a public key from a signature in a smart contract? The ecrecover method returns an address, not a public key, and to do computations that need to derive a public key ...
5
votes
3answers
773 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 ...