Questions tagged [assembly]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
96 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
129 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
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 ...
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[]) ...
1
vote
1answer
101 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
100 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 ...
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"...
1
vote
1answer
52 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 ...
1
vote
1answer
425 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 ...
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
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 ...
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 ...
1
vote
1answer
225 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
187 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
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
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 ...
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 ...
1
vote
0answers
178 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
416 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
439 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). ...
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 ...
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 ...
2
votes
0answers
78 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
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 ...
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
0answers
517 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 ...
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 ...
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 ?
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 ...
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 ...
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 ...
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
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?

1 2
3