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.

56
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?
16
votes
2answers
4k views

understanding mload assembly function

I am learning the inline assembly in solidity, i ve found the function mload(0x40) i am confused whith what this function does? did it reserve 4 Slot/word in memory or did it load the data stored in ...
12
votes
2answers
2k 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 ...
12
votes
3answers
2k views

What are some examples of how inline assembly benefits smart contract development?

A lot of people have expressed excitement at the potential of using inline assembly in smart contracts. After seeing this comment on reddit I'm curious to see some basic (and more advanced, if you ...
11
votes
1answer
336 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 ...
8
votes
1answer
374 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 ...
8
votes
1answer
501 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 ...
8
votes
2answers
770 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 ...
7
votes
1answer
134 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 ...
7
votes
1answer
470 views

Difference between the assembly code generated for uint and uint32?

I wrote a simple contract with a single state variable with type uint and the generated assembly code is quite straight forward. But when I changed the type to uint32 the generated assembly becomes ...
7
votes
0answers
485 views

How can a proxy contract create another contract? [duplicate]

A simple proxy contract looks like: contract Proxy { function forward(address to, uint value, bytes data) { if (!to.call.value(value)(data)) { throw; } } } Using ...
6
votes
1answer
219 views

Could more than one mapping's key point to the same memory space?

Since memory is already allocated on (array[0] = value;), I just want to change its pointing key value. Such as array[1] will allow me to access value now. Is it possible to change the key of ...
5
votes
3answers
811 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 ...
5
votes
1answer
364 views

Can a contract fetch the global block gas limit?

The OPCODE GASLIMIT gets the block's gas limit. Could in-line assembly, uint gasLimit; assembly { gasLimit := gaslimit } fetch the gas limit ? contract B { function ...
5
votes
1answer
550 views

How do you balance inline assembly blocks?

Since Solidity 0.4.3, the compiler now shows warnings when a block is not balanced. For example: Error: Inline assembly block is not balanced. It leaves 1 item(s) on the stack. I've tried finding ...
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
2k views

Concat two bytes arrays with Assembly

Does anyone know how to efficiently concat two bytes arrays with assembly language to save gas costs? Currently I have function mergeBytes(bytes param1, bytes param2) returns (bytes) { bytes ...
4
votes
1answer
676 views

How to return dynamic sized array's original address on the memory of Solidity?

On the following source code, memOffset returns local values such as 96, 128 as the address value. How could I make it return the original address that is located on the memory, is it possible? After ...
4
votes
1answer
170 views

Can you write a contract which bytecode can be proven that can only send ether to a given address?

I'm thinking maybe looking through the OP codes, you can realize that the contract can only send money to a given address. Would this kind of formal verification be hard to write?
3
votes
2answers
885 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 { ...
3
votes
2answers
313 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 { ...
3
votes
1answer
88 views

assembly in solidity: wrong result for and operator

Could somebody explain why the value of c variable is not 0x0c in code below: function test() { byte b = 0x2c; byte c; assembly { c := and(b, 0xf) } Check(c); } The Check ...
3
votes
2answers
427 views

Can the CALL opcode be used to create a contract?

The Yellow Paper Appendix H defines the CREATE and CALL opcodes. For CALL: the operand order is: gas, to, value, in offset, in size, out offset, out size. By setting the second operand (the "to"...
3
votes
1answer
730 views

How do I use delegatecall assembly with a storage pointer to a struct

I am trying to call a library function using assembly and the delegatecall opcode. The library function accepts two parameters, the state object storage pointer and an address, it returns a single ...
3
votes
1answer
171 views

Contract assembly algorithm in .data part of the object file

Hope you are doing well. We were running a simple contract and trying to analyse the assembly code generated by the browser compiler. In the .data part we found a section where the compiler executes a ...
3
votes
2answers
300 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])) ...
3
votes
0answers
204 views

Checking if an address is encoded on the end of a bytes array

I have a bytes array. Within the last 20 bytes, there is an address stored. I am trying to compare the address at the end of this array to the address of a msg.sender, and am wondering if there is a ...
2
votes
1answer
880 views

Can I use delegatecall in a transaction?

I'm interested in techniques to perform multiple sends/contract calls inside of a single transaction but with the EOA that originates the transaction still being the sender for all operations (not a ...
2
votes
1answer
430 views

Help to understand assembly method

I have find this assembly code function toBytes(address a) constant returns (bytes b){ assembly { let m := mload(0x40) mstore(add(m, 20), xor(...
2
votes
1answer
131 views

Difference between sending a transaction with no to field and create() opcode?

What is the difference between sending a transaction with no to field and create() opcode ?
2
votes
1answer
26 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
68 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
60 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 ...
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 ...
2
votes
1answer
310 views

How to pass parameters to Contract constructor using when using assembly?

Here I have a function which deploys a Contract straight from bytecode, but let say my contract needs some arguments in the constructor, is it possible to pass them through create opcode? function ...
2
votes
1answer
574 views

Problem using created array from assembly

I've used the code from the solidity assembly tutorial here to create a single dimensional array in assembly. The code is as follows: contract C { function f(uint a, uint b) constant returns (uint[]) ...
2
votes
1answer
713 views

How can you split calldata bytes to an arbitrary number of different log events?

The following code is incomplete. What I want to do is split the bytes data (calldata) into two or more separate log functions for indexing reasons. The problem is I can't figure out how to do it in ...
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 ...
2
votes
1answer
243 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
366 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 ...
2
votes
2answers
344 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 ...
2
votes
1answer
14 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
189 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 ...
2
votes
0answers
79 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 = ...
2
votes
0answers
70 views

Assembly operations throw warnings during compiling

Leveraging the following common string utility has been quite helpful, but would like to get rid of a warning: function stringToBytes32(string memory source) returns (bytes32 result) { assembly ...
2
votes
0answers
474 views

Call vs Delegate Call call data format

I'm using both call and delegatecall within an assembly block and i've noticed that when issuing a call I need to provide 4 bytes (sig) + any arguments, whereas for delegatecall I need to provide 4 ...
1
vote
1answer
464 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
1answer
27 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
2answers
439 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 () ...
1
vote
1answer
32 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(...