@@ -912,202 +912,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
912
912
)
913
913
}
914
914
915
- BOOST_AUTO_TEST_CASE (keccak256)
916
- {
917
- char const * sourceCode = R"(
918
- contract test {
919
- function a(bytes32 input) public returns (bytes32 hash) {
920
- return keccak256(abi.encodePacked(input));
921
- }
922
- }
923
- )" ;
924
- ALSO_VIA_YUL (
925
- DISABLE_EWASM_TESTRUN ()
926
- compileAndRun (sourceCode);
927
- auto f = [&](u256 const & _x) -> u256
928
- {
929
- return util::keccak256 (toBigEndian (_x));
930
- };
931
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
932
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
933
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
934
- );
935
- }
936
-
937
- BOOST_AUTO_TEST_CASE (sha256)
938
- {
939
- char const * sourceCode = R"(
940
- contract test {
941
- function a(bytes32 input) public returns (bytes32 sha256hash) {
942
- return sha256(abi.encodePacked(input));
943
- }
944
- }
945
- )" ;
946
- auto f = [&](u256 const & _x) -> bytes
947
- {
948
- if (_x == u256 (4 ))
949
- return fromHex (" e38990d0c7fc009880a9c07c23842e886c6bbdc964ce6bdd5817ad357335ee6f" );
950
- if (_x == u256 (5 ))
951
- return fromHex (" 96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47" );
952
- if (_x == u256 (-1 ))
953
- return fromHex (" af9613760f72635fbdb44a5a0a63c39f12af30f950a6ee5c971be188e89c4051" );
954
- return fromHex (" " );
955
- };
956
- ALSO_VIA_YUL (
957
- DISABLE_EWASM_TESTRUN ()
958
- compileAndRun (sourceCode);
959
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
960
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
961
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
962
- )
963
- }
964
-
965
- BOOST_AUTO_TEST_CASE (ripemd)
966
- {
967
- char const * sourceCode = R"(
968
- contract test {
969
- function a(bytes32 input) public returns (bytes32 sha256hash) {
970
- return ripemd160(abi.encodePacked(input));
971
- }
972
- }
973
- )" ;
974
- auto f = [&](u256 const & _x) -> bytes
975
- {
976
- if (_x == u256 (4 ))
977
- return fromHex (" 1b0f3c404d12075c68c938f9f60ebea4f74941a0000000000000000000000000" );
978
- if (_x == u256 (5 ))
979
- return fromHex (" ee54aa84fc32d8fed5a5fe160442ae84626829d9000000000000000000000000" );
980
- if (_x == u256 (-1 ))
981
- return fromHex (" 1cf4e77f5966e13e109703cd8a0df7ceda7f3dc3000000000000000000000000" );
982
- return fromHex (" " );
983
- };
984
- ALSO_VIA_YUL (
985
- DISABLE_EWASM_TESTRUN ()
986
- compileAndRun (sourceCode);
987
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
988
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
989
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
990
- )
991
- }
992
-
993
- BOOST_AUTO_TEST_CASE (packed_keccak256)
994
- {
995
- char const * sourceCode = R"(
996
- contract test {
997
- function a(bytes32 input) public returns (bytes32 hash) {
998
- uint24 b = 65536;
999
- uint c = 256;
1000
- return keccak256(abi.encodePacked(uint8(8), input, b, input, c));
1001
- }
1002
- }
1003
- )" ;
1004
- auto f = [&](u256 const & _x) -> u256
1005
- {
1006
- return util::keccak256 (
1007
- toCompactBigEndian (unsigned (8 )) +
1008
- toBigEndian (_x) +
1009
- toCompactBigEndian (unsigned (65536 )) +
1010
- toBigEndian (_x) +
1011
- toBigEndian (u256 (256 ))
1012
- );
1013
- };
1014
- ALSO_VIA_YUL (
1015
- DISABLE_EWASM_TESTRUN ()
1016
- compileAndRun (sourceCode);
1017
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
1018
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
1019
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
1020
- )
1021
- }
1022
-
1023
- BOOST_AUTO_TEST_CASE (packed_keccak256_complex_types)
1024
- {
1025
- char const * sourceCode = R"(
1026
- contract test {
1027
- uint120[3] x;
1028
- function f() public returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
1029
- uint120[] memory y = new uint120[](3);
1030
- x[0] = y[0] = uint120(type(uint).max - 1);
1031
- x[1] = y[1] = uint120(type(uint).max - 2);
1032
- x[2] = y[2] = uint120(type(uint).max - 3);
1033
- hash1 = keccak256(abi.encodePacked(x));
1034
- hash2 = keccak256(abi.encodePacked(y));
1035
- hash3 = keccak256(abi.encodePacked(this.f));
1036
- }
1037
- }
1038
- )" ;
1039
- ALSO_VIA_YUL (
1040
- DISABLE_EWASM_TESTRUN ()
1041
- compileAndRun (sourceCode);
1042
- // Strangely, arrays are encoded with intra-element padding.
1043
- ABI_CHECK (callContractFunction (" f()" ), encodeArgs (
1044
- util::keccak256 (encodeArgs (u256 (" 0xfffffffffffffffffffffffffffffe" ), u256 (" 0xfffffffffffffffffffffffffffffd" ), u256 (" 0xfffffffffffffffffffffffffffffc" ))),
1045
- util::keccak256 (encodeArgs (u256 (" 0xfffffffffffffffffffffffffffffe" ), u256 (" 0xfffffffffffffffffffffffffffffd" ), u256 (" 0xfffffffffffffffffffffffffffffc" ))),
1046
- util::keccak256 (fromHex (m_contractAddress.hex () + " 26121ff0" ))
1047
- ));
1048
- )
1049
- }
1050
-
1051
- BOOST_AUTO_TEST_CASE (packed_sha256)
1052
- {
1053
- char const * sourceCode = R"(
1054
- contract test {
1055
- function a(bytes32 input) public returns (bytes32 hash) {
1056
- uint24 b = 65536;
1057
- uint c = 256;
1058
- return sha256(abi.encodePacked(uint8(8), input, b, input, c));
1059
- }
1060
- }
1061
- )" ;
1062
- auto f = [&](u256 const & _x) -> bytes
1063
- {
1064
- if (_x == u256 (4 ))
1065
- return fromHex (" 804e0d7003cfd70fc925dc103174d9f898ebb142ecc2a286da1abd22ac2ce3ac" );
1066
- if (_x == u256 (5 ))
1067
- return fromHex (" e94921945f9068726c529a290a954f412bcac53184bb41224208a31edbf63cf0" );
1068
- if (_x == u256 (-1 ))
1069
- return fromHex (" f14def4d07cd185ddd8b10a81b2238326196a38867e6e6adbcc956dc913488c7" );
1070
- return fromHex (" " );
1071
- };
1072
- ALSO_VIA_YUL (
1073
- DISABLE_EWASM_TESTRUN ()
1074
- compileAndRun (sourceCode);
1075
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
1076
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
1077
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
1078
- )
1079
- }
1080
-
1081
- BOOST_AUTO_TEST_CASE (packed_ripemd160)
1082
- {
1083
- char const * sourceCode = R"(
1084
- contract test {
1085
- function a(bytes32 input) public returns (bytes32 hash) {
1086
- uint24 b = 65536;
1087
- uint c = 256;
1088
- return ripemd160(abi.encodePacked(uint8(8), input, b, input, c));
1089
- }
1090
- }
1091
- )" ;
1092
- auto f = [&](u256 const & _x) -> bytes
1093
- {
1094
- if (_x == u256 (4 ))
1095
- return fromHex (" f93175303eba2a7b372174fc9330237f5ad202fc000000000000000000000000" );
1096
- if (_x == u256 (5 ))
1097
- return fromHex (" 04f4fc112e2bfbe0d38f896a46629e08e2fcfad5000000000000000000000000" );
1098
- if (_x == u256 (-1 ))
1099
- return fromHex (" c0a2e4b1f3ff766a9a0089e7a410391730872495000000000000000000000000" );
1100
- return fromHex (" " );
1101
- };
1102
- ALSO_VIA_YUL (
1103
- DISABLE_EWASM_TESTRUN ()
1104
- compileAndRun (sourceCode);
1105
- testContractAgainstCpp (" a(bytes32)" , f, u256 (4 ));
1106
- testContractAgainstCpp (" a(bytes32)" , f, u256 (5 ));
1107
- testContractAgainstCpp (" a(bytes32)" , f, u256 (-1 ));
1108
- )
1109
- }
1110
-
1111
915
BOOST_AUTO_TEST_CASE (inter_contract_calls)
1112
916
{
1113
917
char const * sourceCode = R"(
0 commit comments