github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-london/sha3.sol (about)

     1  // SPDX-License-Identifier: GPL-3.0
     2  
     3  pragma solidity ^0.8.14;
     4  
     5  contract Sha3 {
     6      function hashArray() public pure returns (bytes32) {
     7          bytes8[] memory tickers = new bytes8[](4);
     8          tickers[0] = bytes8("BTC");
     9          tickers[1] = bytes8("ETH");
    10          tickers[2] = bytes8("LTC");
    11          tickers[3] = bytes8("DOGE");
    12          return keccak256(abi.encodePacked(tickers));
    13          // 0x374c0504f79c1d5e6e4ded17d488802b5656bd1d96b16a568d6c324e1c04c37b
    14      }
    15  
    16      function hashPackedArray() public pure returns (bytes32) {
    17          bytes8 btc = bytes8("BTC");
    18          bytes8 eth = bytes8("ETH");
    19          bytes8 ltc = bytes8("LTC");
    20          bytes8 doge = bytes8("DOGE");
    21          return keccak256(abi.encodePacked(btc, eth, ltc, doge));
    22          // 0xe79a6745d2205095147fd735f329de58377b2f0b9f4b81ae23e010062127f2bc
    23      }
    24  
    25      function hashAddress() public pure returns (bytes32) {
    26          address account = 0x6779913e982688474F710B47E1c0506c5Dca4634;
    27          return keccak256(abi.encodePacked(account));
    28          // 0x229327de236bd04ccac2efc445f1a2b63afddf438b35874b9f6fd1e6c38b0198
    29      }
    30  
    31      function testPackedArgs() public pure returns (bool) {
    32          return keccak256("ab") == keccak256(abi.encodePacked("a", "b"));
    33      }
    34  
    35      function hashHex() public pure returns (bytes32) {
    36          bytes1 i = 0x0a;
    37          return keccak256(abi.encodePacked(i));
    38          // 0x0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8
    39      }
    40  
    41      function hashInt() public pure returns (bytes32) {
    42          return keccak256(abi.encodePacked(int256(1)));
    43      }
    44  
    45      function hashNegative() public pure returns (bytes32) {
    46          return keccak256(abi.encodePacked(int256(-1)));
    47      }
    48  
    49      function hash8() public pure returns (bytes32) {
    50          return keccak256(abi.encodePacked(uint8(1)));
    51      }
    52  
    53      function hash32() public pure returns (bytes32) {
    54          return keccak256(abi.encodePacked(uint32(1)));
    55      }
    56  
    57      function hash256() public pure returns (bytes32) {
    58          return keccak256(abi.encodePacked(uint256(1)));
    59      }
    60  
    61      function hashEth() public pure returns (bytes32) {
    62          return keccak256(abi.encodePacked(uint256(100 ether)));
    63      }
    64  
    65      function hashWei() public pure returns (bytes32) {
    66          return keccak256(abi.encodePacked(uint256(100)));
    67      }
    68  
    69      function hashMultipleArgs() public pure returns (bytes32) {
    70          return keccak256(abi.encodePacked("a", uint256(1)));
    71      }
    72  
    73      function hashString() public pure returns (bytes32) {
    74          return keccak256("a");
    75      }
    76  }