Write to a packed storage variable in Yul

Поделиться
HTML-код
  • Опубликовано: 26 сен 2024
  • Tutorial example showing updating a packed storage variable in Yul. Makes use of bit masking and bit shifting operations in Yul.
    Useful Links:
    github.com/rea...
    Feel free to donate and help me to buy a coffee or even a new MacBook pro! ;)
    BTC: bc1q3fddwnufucdkpqz6fzj03xsskaqjxv8dag90x2
    ETH: 0x67cC81389f44c0B980F93dc003300a31aD5dadA2
    Many thanks everyone and I appreciate your support in any way!

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

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

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

  • @RiteshVerma-c3t
    @RiteshVerma-c3t 11 месяцев назад +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  11 месяцев назад

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