Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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?
20
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 ...
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 ...
13
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 ...
12
votes
1answer
385 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
422 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
537 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
810 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
162 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
491 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
487 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
230 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
934 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
2answers
2k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
5
votes
1answer
372 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
592 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

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
708 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
172 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
945 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
355 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
320 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 ...
3
votes
1answer
92 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
446 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
772 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
172 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
1answer
392 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 ...
3
votes
2answers
321 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
210 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
903 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
654 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) } } ...
2
votes
1answer
475 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
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 ...
2
votes
1answer
633 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
136 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
2answers
346 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. ...
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
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
139 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 ...
2
votes
1answer
255 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
806 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
295 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
2answers
393 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
75 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 (...
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
258 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
92 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
75 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 ...