Stack Exchange Network

Stack Exchange network consists of 174 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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

The tag has no usage guidance.

2
votes
1answer
36 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
22 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, ...
0
votes
0answers
15 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
23 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
40 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
22 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 - ...
0
votes
0answers
15 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
32 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
38 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 ...
2
votes
2answers
202 views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
3
votes
2answers
144 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
31 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
73 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
38 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
80 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
87 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
111 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
154 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
19 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
100 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
269 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
32 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
165 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
52 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
0answers
103 views

Delegatecall trouble

I'm trying to build a simple example using proxy contract and delegatecall but I'm having trouble making it work . What I'm trying to achieve is : Having a contract Dummy extending Proxy that will ...
0
votes
1answer
60 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 ...
1
vote
1answer
120 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
286 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
191 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
2answers
392 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 ...
0
votes
1answer
34 views

Under what circumstance does CALL return nonzero?

Reading the yellow paper http://yellowpaper.io/ documentation for CALL. µ'_s[0] ≡ x where x = 0 if the code execution for this operation failed due to an exceptional halting, Z(σ, µ, I) = > or if ...
0
votes
1answer
35 views

How to store x amount of uint8s inside a byte32?

I'm trying to store an array of uint8 but its not very gas efficient. This is my current solution of storing things: uint8[5] public VALUES = [10, 11, 12, 13, 14]; The problem is that I will have ...
2
votes
1answer
627 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
0answers
79 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 From Solidity docs Optimizer Internals: It splits the sequence of ...
0
votes
1answer
122 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.
1
vote
1answer
36 views

Standalone assembly contract: control flow error

I'm trying to understand why the following toy contract does not work. I can deploy it successfully, and transactions with fewer than 36 bytes of data are successful, but those containing 36 bytes or ...
3
votes
2answers
567 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 ...
0
votes
0answers
181 views

Solidity to Assembly

I'm trying to follow the following pattern from the documentation to convert between solidity and assembly: // This function is less efficient because the optimizer currently fails to // remove the ...
1
vote
1answer
236 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
354 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[]) ...
1
vote
1answer
142 views

Assembly for array with bytes64, to bypass nested array error

Since it is not possible to pass call code with an array of bytes64, as an array with types bigger than bytes32 becomes a nested array, Why is bytes[] a nested array? How would assembly be used to ...
3
votes
0answers
144 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 ...
1
vote
1answer
94 views

Can't understand hashing mechanism for mappings

I have a contract with function function addToBalance () payable { userBalances[msg.sender] += msg.value ; } Debugged assembly and stumbled on the code that calculates key for store: ...
0
votes
1answer
135 views

EVM assembly level debugger

I want to examine behavior of some EVM instructions in live mode, but can't find any tools like debuggers/emulators which give nice look of stack and memory and ability to execute contract by steps.
2
votes
1answer
287 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(...
1
vote
1answer
398 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 ...
3
votes
1answer
58 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 ...
1
vote
0answers
121 views

out of gas error by assembly delegatecall

I want to get a return value from current contract call other contract by delegatecall, but got a error of out-of-gas. I try to add gas limit to 3000000000, but it doesn't work. please help me. And i ...
1
vote
1answer
284 views

Is it possible to change the gas price during contract method execution?

Is there any way in Solidity to change the gas price during contract method execution? For example using Assembly?
1
vote
1answer
206 views

What is the proper use of inline assembly revert, and how do I retrieve returndata passed to it?

I stumbled on this EIP which describes the revert opcode that looks like it allows you to "throw" more specific errors by passing a memory pointer with the opcode (also described briefly in the docs). ...