Skip to content

Commit

Permalink
Updating contract code
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Oct 2, 2024
1 parent b870e77 commit aa8e0e1
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@ comment
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "hardhat/console.sol";

contract TestMCopy {
constructor() {}

event OK();
event ERROR();
event LOG(bytes32 l);

function checkMCopy() external {
bytes32 expected = 0x0000000000000000000000000000000000000000000000000000000000000077;
bytes32 result = getCopiedValue();
bytes32 value = 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
bytes32 result = getCopiedValue(value);

if (result == expected) {
if (result == value) {
emit OK();
} else {
emit ERROR();
}
}

function getCopiedValue() public pure returns (bytes32 x) {
function getCopiedValue(bytes32 value) public pure returns (bytes32 x) {
assembly {
mstore(0x20, 0x77) // Store 0x77 at word 1 in memory
mcopy(0, 0x20, 0x20) // Use MCOPY to copy value at word 1 to word 0 in memory
x := mload(0) // Returns the value at word 0
mstore(32, value) // Store given value at offset 32 (word 1) in memory
mcopy(0, 32, 32) // Use MCOPY to copy the value at offset 32 (word 1) to offset 0 (word 0) in memory
x := mload(0) // Returns the value at offset 0 (word 0)
}
}

Expand All @@ -50,7 +47,7 @@ This contract contains two functions: checkMCopy, and getCopiedValue.

// CONTRACT BYTECODE

6080604052348015600e575f80fd5b506101548061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c806389448792146100385780638c2bcab914610056575b5f80fd5b610040610060565b60405161004d9190610105565b60405180910390f35b61005e610072565b005b5f60776020526020805f5e5f51905090565b5f60775f1b90505f610082610060565b90508181036100bc577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16100e9565b7f1c9c433b57013295d61f5c5738f5e2cb1de70bb5ba5b2896edfa8efae345965e60405160405180910390a15b5050565b5f819050919050565b6100ff816100ed565b82525050565b5f6020820190506101185f8301846100f6565b9291505056fea26469706673582212206199acac4caca83f6a604881008d178a60fad43ca326fb08e555757e3a0161da64736f6c634300081a0033
6080604052348015600e575f80fd5b506101df8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80638aa8ef4f146100385780638c2bcab914610068575b5f80fd5b610052600480360381019061004d9190610156565b610072565b60405161005f9190610190565b60405180910390f35b610070610085565b005b5f816020526020805f5e5f519050919050565b5f7e0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f5f1b90505f6100b482610072565b90508181036100ee577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a161011b565b7f1c9c433b57013295d61f5c5738f5e2cb1de70bb5ba5b2896edfa8efae345965e60405160405180910390a15b5050565b5f80fd5b5f819050919050565b61013581610123565b811461013f575f80fd5b50565b5f813590506101508161012c565b92915050565b5f6020828403121561016b5761016a61011f565b5b5f61017884828501610142565b91505092915050565b61018a81610123565b82525050565b5f6020820190506101a35f830184610181565b9291505056fea2646970667358221220fe7a5fd75789c53fe321a72af31afed5663b12a01fe5c41d5d4165980b55b87d64736f6c634300081a0033

// CONTRACT CALL

Expand Down

0 comments on commit aa8e0e1

Please sign in to comment.