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

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