CRYPTO NEWS

How to write struct with solidity assembly ( understand assembly )

In the first example, I tried to change the second slot of the structure but failed

 mapping(uint256 => MyStruct) public myStruct;     struct MyStruct {         uint128 slot1;         uint128 slot2; //fixed 32-bytes, 256bit     }     function writeTest(uint256 key) external {         assembly {             mstore(0x0, key)             mstore(0x20, myStruct.slot)             let hash := keccak256(0, 0x40)             let s:= sload(hash)             sstore(                 hash,                 or(                     and(s, not(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)),                     and(12, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)                 )             ) // clear first 128 bit and write new 128 bit (12)             let slot2 := div(                 and(                     s,                     0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000                 ),                 0x100000000000000000000000000000000             )              // or             slot2 := shr(128, s)             // how i can clean and rewrite bit in slot 2         }     } 

In the second example, I tried to create a 32-byte struct in memory and then save it in storage, in this case only the first slot of the string changes.

  function writeTest2(uint256 key) external {         MyStruct memory test2 = MyStruct(10, 20); // 32 bytes         assembly {             mstore(0x0, key)             mstore(0x20, myStruct.slot)             let hash := keccak256(0, 0x40)             sstore(hash, mload(test2))             // check map and get me wrong value, just slot 1 changed         }     } 

how I can write, read or shift a,b,c in mstore for one 32-byte pack

  function testPackingMemory(uint64 a,uint64 b,uint128 c) external {         assembly {             mstore(0x40,some_value) // how i can write or read a,b,c in mstore for one 32byte         }     } 

Parax Aelor

#Parax Aelor #TheSupremeTeam Artist Name: Parax Aelor Who are you? I describe myself as a versatile and diverse artist. I like to be creative and use different flows and beats to get my audience to feel what I want them to feel. Where are you from? Atlanta Georgia. The music scene is very realistic, storytelling,::Listen

#Parax Aelor #TheSupremeTeam
Artist Name: Parax Aelor

Who are you?

I describe myself as a versatile and diverse artist. I like to be creative and use different flows and beats to get my audience to feel what I want them to feel.

Where are you from?

Atlanta Georgia. The music scene is very realistic, storytelling, and creative.

How can we follow you?

https://soundcloud.com/parax01?utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing

https://youtube.com/channel/UCTvn_390ZdIcPDXZsscEUwA

https://www.instagram.com/paraxaelorofcl/

Song Title: Motion

Listen to Parax Aelor:

Source: https://supremepr.us/

How to write struct with solidity assembly ( understand assembly )

Shopping cart
There are no products in the cart!
Continue shopping
0