@@ -911,22 +911,40 @@ contract LoadTester {
911911 }
912912 }
913913
914+ // https://eips.ethereum.org/EIPS/eip-152#example-usage-in-solidity
914915 function testBlake2f (bytes memory inputData ) public returns (bytes memory result ) {
916+ bytes32 [2 ] memory h;
917+ h[0 ] = hex "48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5 " ;
918+ h[1 ] = hex "d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b " ;
919+
920+ bytes32 [4 ] memory m;
921+ m[0 ] = hex "6162630000000000000000000000000000000000000000000000000000000000 " ;
922+ m[1 ] = hex "0000000000000000000000000000000000000000000000000000000000000000 " ;
923+ m[2 ] = hex "0000000000000000000000000000000000000000000000000000000000000000 " ;
924+ m[3 ] = hex "0000000000000000000000000000000000000000000000000000000000000000 " ;
925+
926+ bytes8 [2 ] memory t;
927+ t[0 ] = hex "0300000000000000 " ;
928+ t[1 ] = hex "0000000000000000 " ;
929+
930+ bytes32 [2 ] memory result = F (12 , h, m, t, true );
931+ bytes32 [2 ] memory expected;
932+ expected[0 ] = hex "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1 " ;
933+ expected[1 ] = hex "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923 " ;
934+ require (result[0 ] == expected[0 ], "TestBlake2f - First hash doesn't match " );
935+ require (result[1 ] == expected[1 ], "TestBlake2f - Second hash doesn't match " );
936+ }
937+
938+ function F (uint32 rounds , bytes32 [2 ] memory h , bytes32 [4 ] memory m , bytes8 [2 ] memory t , bool f ) public view returns (bytes32 [2 ] memory ) {
915939 address BLAKE_2F_PRECOMPILED_CONTRACT = 0x0000000000000000000000000000000000000009 ;
916940
941+ bytes32 [2 ] memory output;
942+ bytes memory args = abi.encodePacked (rounds, h[0 ], h[1 ], m[0 ], m[1 ], m[2 ], m[3 ], t[0 ], t[1 ], f);
917943 assembly {
918- let success := call (
919- gas (),
920- BLAKE_2F_PRECOMPILED_CONTRACT,
921- 0 , // no ether transfer
922- add (inputData, 32 ), // inputData offset
923- mload (inputData), // inputData length
924- result, // output area
925- 64 // output area size (2 * 32 bytes)
926- )
927- if iszero (success) {
928- revert (0 , 0 )
944+ if iszero (staticcall (not (0 ), BLAKE_2F_PRECOMPILED_CONTRACT, add (args, 32 ), 0xd5 , output, 0x40 )) {
945+ revert (0 , 0 )
929946 }
930947 }
948+ return output;
931949 }
932950}
0 commit comments