Questions tagged [assembly]

298 questions
2
votes
1 answer

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 latest version. I wasn't sure how to specify the…
Zephyrus
  • 350
  • 3
  • 11
2
votes
1 answer

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, 32), word) } return…
lektion
  • 23
  • 2
2
votes
2 answers

abi.encode and abi.decode arguments, including variable-sized arrays

I'm passing some arguments to a function and abi.encode()-ing them. Then I pass this data to another function where I abi.decode() it, but Im not entirely sure how to do it: Arguments I'm encoding: uint256 quantity uint8 …
Hiperfly
  • 459
  • 4
  • 11
1
vote
1 answer

why does keccak256 in assembly require 2 arguments?

Why does keccak256() in assembly require 2 arguments? What is the second argument? assembly { let foo := keccak256(4) } returns error Function expects 2 arguments but got 1.
mArgo
  • 63
  • 5
1
vote
1 answer

get length of nested array in assembly

How to get length of foo[1] in example below in assembly? uint[][] foo; // foo.length = 2, foo[1].length = 3 function getLength() returns (uint len) { assembly { len := sload(foo) // returns 2 len := sload(........) // how to…
mArgo
  • 63
  • 5
1
vote
1 answer

Converting from Assembly to Solidity

I am trying to convert the assembly code into Solidity given at the link: What is a function Selector The code is trying to invoke the function func(...) of Contract1 given below: contract Contract1 { function func(uint256 x, uint8 y) public…
zak100
  • 1,406
  • 1
  • 13
  • 37
1
vote
2 answers

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; }
assembler
  • 11
  • 2
0
votes
2 answers

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 and adding byte by byte would be quite expensive,…
Andrey
  • 1,147
  • 1
  • 12
  • 19
0
votes
1 answer

How can assembly be used to add bytes together?

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 one single bytes array? function getData() public…
patrikB
  • 1
  • 1
0
votes
1 answer

Manipulating individual bytes in assembly

I am learning assembly and I am trying to write to individual bytes in a bytes32 array. I have the following code: contract TestAssembly {} function test( uint8 _count ) public { bytes32 bytesTest; assembly { …
silkAdmin
  • 103
  • 2