1

I want to copy in inline assembly from calldata the last two bytes of every 32 byte slices to the lower half of the first free memory slot(32 bytes).

free = free memory pointer + 14 (bytes)

moffset = free + (loop count * 2) so in the first run calldatacopy copy the bytes at the start of the lower half of the 32 byte slot

loffset = 4 + (loop count * 30) the first four bytes are the function signature, and i want copy from the calldata the data what follows the signature, and the data is packed by 32 bytes, and i want to read starting from the (loop number * 30th byte)

When i debug it in RemixIDE the memory location is not updated after the first loop.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract YourContract {
mapping (address=>uint128) public whitelist;

function _setwlistA(uint16[8] calldata partitions, address operator) public {
 assembly{
   let i:=1
   let free:= add(mload(64),14)
   for {} lt (i,9) {} 
     {
      let moffset := add(free,mul(i,2))
      let loffset := add(4,mul(i,30))
      calldatacopy(moffset,loffset,2)
      i := add(i,1)
      }
   mstore(0,operator)
   mstore(32, whitelist.slot)
   sstore(keccak256(0,64),mload(sub(free,14)))
  }
 }
}

1 Answer 1

1

While i was editing my question i realized:

I just need to set the offset for calldata's reading point first to 34 outside the loop, then in every loop i must add 32 to it.

outside:

let loffset:= 34

inside:

loffset := add(loffset,32)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.