Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
60
votes
2answers
21k 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?
22
votes
2answers
6k 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 ...
14
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 ...
14
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
439 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 ...
9
votes
1answer
677 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
1answer
603 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
2answers
966 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 ...
8
votes
1answer
580 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
1answer
281 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
0answers
491 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
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 ...
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?
6
votes
1answer
243 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
1answer
400 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
643 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
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 { ...
4
votes
1answer
347 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 ...
4
votes
1answer
335 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 ...
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
813 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
187 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?
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])) ...
3
votes
1answer
951 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) } } ...
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 ...
3
votes
2answers
530 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
109 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
485 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
847 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
180 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
483 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
498 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 ...
3
votes
0answers
225 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
1k 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
279 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: ...
2
votes
1answer
523 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
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 ...
2
votes
1answer
774 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
144 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
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 ...
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
853 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
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'...
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,...
2
votes
1answer
755 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
60 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
320 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
342 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,;...
2
votes
1answer
318 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
1k 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 ...