Write to a packed storage variable in Yul

Поделиться
HTML-код
  • Опубликовано: 20 дек 2024

Комментарии • 3

  • @sanjaysen-e6l
    @sanjaysen-e6l 6 месяцев назад

    we will multiply by 29byte to get complete 256-bit to store vale at certain postion?

  • @RiteshVerma-c3t
    @RiteshVerma-c3t Год назад +1

    Your video has helped me , Thanks
    Would be great if you could help in this task
    I am trying to solve some gas optimization quests on node guardians...
    Task : implement a simple function copying a bytes memory array in most gas efficient way using inline assembly
    here is my code, which is not working and not efficient
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.19;
    abstract contract Challenge {
    /**
    * @notice Returns a copy of the given array in a gas efficient way.
    * @dev This contract will be called internally.
    * @param array The array to copy.
    * @return copy The copied array.
    */
    function copyArray(bytes memory array)
    internal
    pure
    returns (bytes memory copy)
    {
    assembly {
    let length := mload(array)
    copy := mload(0x40)
    mstore(0x40, add(copy, add(32, mul(length, 32))))
    mstore(copy, length)
    if gt(length, 0) {
    let src := add(array, 32)
    let dst := add(copy, 32)
    let end := add(src, mul(length, 32))
    for { } lt(src, end) { } {
    mstore(dst, mload(src))
    src := add(src, 32)
    dst := add(dst, 32)
    }
    }
    }
    //return copy;
    }
    }

    • @Reanblock
      @Reanblock  Год назад

      Many thanks for your comment.. I will be producing some video tutorials on smart contract gas efficiency in the near future.