Questions tagged [assembly]

The tag has no usage guidance.

34 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
22 views

Copy and deploy a smart contract from opcodes without source code

I extracted opcodes from an already existing and deployed smart contract and I would like to know if it is possible to deploy an exact copy of this contract from its opcodes? My extracted opcodes ...
4
votes
3answers
372 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
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
64 views

Most gas efficient way to check if byte array contains zeroes?

I have a contract that I pass data packed into an array of uint256 (as it's apparently cheaper to use uint256 over bytes32) and each byte in the uint256 contains positions referencing another array of ...
2
votes
0answers
33 views

In solc 0.4.x assembly, how can I check if a non-constant function returns 'bool' or nothing?

I know how to do it for a constant function, for example: pragma solidity 0.4.25; contract Callee0 {function func() external pure returns (bool) {return false;}} contract Callee1 {function func() ...
2
votes
1answer
60 views

Modifying simple function with inline assembly

I'm trying to write a super simple contract that's gas efficient utilizing inline assembly in solidity. All this function needs to do is create a child smart contract with one function, self destruct....
2
votes
0answers
38 views

How to get a call graph for the binary code of a contract?

I need a call graph generator for the assembler level of smart contract code in order to analyse solidity compiler bugs. In that way, porosity is excatly what I need ! However there are too much bugs ...
2
votes
1answer
133 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
0answers
121 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
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
0answers
519 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
0answers
32 views

copy array from storage to memory

uint[2] testStorage; function assemblyStorage() public returns (uint a, uint b){ testStorage[0] = 5; testStorage[1] = 10; uint[2] memory testMemory = testStorage; ...
1
vote
0answers
17 views

why do i have to specify memory in arguments?

My function body looks like this: function element(uint a, uint b, uint[2] memory c) public returns(uint e, uint f, uint g, uint k) { I am wondering why do I put memory keyword before c ? I know that ...
1
vote
0answers
17 views

why mload(0) returns wrong number?

int x; // Storage slot #0 mapping (uint => uint) y; // Storage slot #1 uint [] z; // Storage slot #2 function element() public returns (uint a, uint b, uint c) { z.push(45);...
1
vote
0answers
34 views

how do storage and memory variable work?

So, in an ordinary programming language, we have stack and heap. Reference types such as array gets stored in heap. and the variable which holds the address(pointer) of this array is stored in stack.. ...
1
vote
0answers
16 views

Trying to understand the ethereum stack

I've been trying to understand the limits of the stack and how it works. It seems like the "Stack too deep" error only happens if there is an assembly block in the function. Without an ...
1
vote
0answers
25 views

Conditional in assembly

I am trying to use a conditional (like an if statement) in assembly. The only assembly reference site I have ever been able to find says the opcode JUMPI is the way to do this. Using solc 0.7.0, the ...
1
vote
0answers
79 views

Function selector computed differently for libraries?

As documented in various places, the function selector is computed as the first four bytes of the keccak256 hash of the function header, which consists of the function name followed by the list of ...
1
vote
0answers
54 views

When I call tranfer_from function, remix saids gas limit exceed

I am owner of the token contract, And when I call transfer_from() function, remix saids gas limit exceed. my gas limit is 300000. this is same contract, and call transfer_from() successfully. "https:/...
1
vote
0answers
107 views

delegatecall (assembly) didn't change state variable in Remix with Web3 Provider

I am trying to test proxy pattern in Remix, which connected to my private chain with Web3 Provider. By the way, miner is working all the time. After invoking add function of Proxy contract, the state ...
1
vote
0answers
158 views

Proxy contract DELEGATECALL to pass a DYNAMIC array to a function in the target contract

I'm trying to get a Proxy contract to correctly do a delegatecall to a function in another 'target' contract. The problem is, that I need to pass a dynamic array as the parameter to this function. Q: ...
1
vote
1answer
202 views

Concatenating byte strings in assembly for call input data

I have the following piece of code in my contract. It's supposed to take in a byte string composed of a uint flag that is followed by a variable list of uint numbers and contruct a call using those ...
1
vote
0answers
45 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 ...
1
vote
0answers
97 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)...
1
vote
0answers
106 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: It splits the sequence of instructions into basic blocks at JUMPs ...
1
vote
0answers
179 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 ...
0
votes
0answers
9 views

How to deploy a compiled stateless contract and which doesn t have creation code/transaction?

I got a deployed contract bytecode from an internal project which I d like to publish on the mainnet. The problem is it s just the bytecode without the creation code. Is there a simpler way to deploy ...
0
votes
0answers
12 views

Unable to reference local variable in-line assembly

I am unable to compile a contract that references a local variable in in-line assembly. Here is the code: pragma solidity ^0.5.0; /** * @dev Contract module that helps prevent reentrant calls to a ...
0
votes
1answer
20 views

Solidity 0.6.x - when is it mandatory to use assembly (with examples)?

Solidity's development is very active and, if compared to several other codes, stable releases are updated quite frequently. Which cases need assembly as mandatory feature for Solidity release 0.6.x? ...
0
votes
0answers
10 views

Can I put the inline assembly code as function argument string?

Assume there is an example as below: pragma solidity >=0.4.11 <0.6.0; contract C { uint b; function f(uint x) public view returns (uint r) { assembly { r := mul(x, ...
0
votes
1answer
27 views

How to call sha256 in assembly

I wanna compute sha256 in Solidity Assembly for hash of getting bytes slice.
0
votes
1answer
108 views

Factory contract to clone existing contracts

I am researching about Factory contract to clone existing contracts, First is the implementation present at https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol. I don't ...
0
votes
0answers
68 views

How to get the result from another contract's Optional method while return empty if it does not exist or throws?

For example I want to write a contract where when one passes the address of another contract to it, it will check whether this other contract has the name() function, and if the name() function ...
0
votes
1answer
197 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.