Skip to content

Commit

Permalink
EIP - 152 Blake2 compression function F (#618)
Browse files Browse the repository at this point in the history
* Add web3 rpc tests for blake2compression

* evm.md: Implement EIP-152

* formatting

* tests/failing.llvm: remove now passing tests

Co-authored-by: ehildenb <[email protected]>
Co-authored-by: rv-jenkins <[email protected]>
  • Loading branch information
3 people committed Jan 8, 2020
1 parent 692d237 commit 8167a3f
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 7 deletions.
28 changes: 24 additions & 4 deletions evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ Self destructing to yourself, unlike a regular transfer, destroys the balance in
Precompiled Contracts
---------------------

- `#precompiled` is a placeholder for the 8 pre-compiled contracts at addresses 1 through 8.
- `#precompiled` is a placeholder for the 9 pre-compiled contracts at addresses 1 through 9.

```k
syntax NullStackOp ::= PrecompiledOp
Expand All @@ -1706,6 +1706,7 @@ Precompiled Contracts
rule #precompiled(6) => ECADD
rule #precompiled(7) => ECMUL
rule #precompiled(8) => ECPAIRING
rule #precompiled(9) => BLAKE2F
syntax Set ::= #precompiledAccounts ( Schedule ) [function]
// -----------------------------------------------------------
Expand All @@ -1717,7 +1718,7 @@ Precompiled Contracts
rule #precompiledAccounts(BYZANTIUM) => #precompiledAccounts(SPURIOUS_DRAGON) SetItem(5) SetItem(6) SetItem(7) SetItem(8)
rule #precompiledAccounts(CONSTANTINOPLE) => #precompiledAccounts(BYZANTIUM)
rule #precompiledAccounts(PETERSBURG) => #precompiledAccounts(CONSTANTINOPLE)
rule #precompiledAccounts(ISTANBUL) => #precompiledAccounts(PETERSBURG)
rule #precompiledAccounts(ISTANBUL) => #precompiledAccounts(PETERSBURG) SetItem(9)
```

- `ECREC` performs ECDSA public key recovery.
Expand Down Expand Up @@ -1822,6 +1823,23 @@ Precompiled Contracts
requires isValidPoint(AK) andBool isValidPoint(BK)
rule <k> #checkPoint ~> #ecpairing(ListItem(AK::G1Point) _, ListItem(BK::G2Point) _, _, _, _) => #end EVMC_PRECOMPILE_FAILURE ... </k>
requires notBool isValidPoint(AK) orBool notBool isValidPoint(BK)
syntax PrecompiledOp ::= "BLAKE2F"
// ----------------------------------
rule <k> BLAKE2F => #end EVMC_SUCCESS ... </k>
<output> _ => #parseByteStack( Blake2Compress( #asString( DATA ) ) ) </output>
<callData> DATA </callData>
requires #sizeByteArray( DATA ) ==Int 213
andBool DATA[212] <=Int 1
rule <k> BLAKE2F => #end EVMC_PRECOMPILE_FAILURE ... </k>
<callData> DATA </callData>
requires #sizeByteArray( DATA ) ==Int 213
andBool DATA[212] >Int 1
rule <k> BLAKE2F => #end EVMC_PRECOMPILE_FAILURE ... </k>
<callData> DATA </callData>
requires #sizeByteArray( DATA ) =/=Int 213
```


Expand Down Expand Up @@ -2099,6 +2117,7 @@ The intrinsic gas calculation mirrors the style of the YellowPaper (appendix H).
rule <k> #gasExec(SCHED, ECADD) => Gecadd < SCHED> ... </k>
rule <k> #gasExec(SCHED, ECMUL) => Gecmul < SCHED > ... </k>
rule <k> #gasExec(SCHED, ECPAIRING) => Gecpairconst < SCHED > +Int (#sizeByteArray(DATA) /Int 192) *Int Gecpaircoeff < SCHED > ... </k> <callData> DATA </callData>
rule <k> #gasExec(SCHED, BLAKE2F) => Gfround < SCHED > *Int #asWord( DATA[0 .. 4] ) ... </k> <callData> DATA </callData>
syntax InternalOp ::= "#allocateCallGas"
// ----------------------------------------
Expand Down Expand Up @@ -2298,8 +2317,8 @@ A `ScheduleConst` is a constant determined by the fee schedule.
| "Gcallvalue" | "Gcallstipend" | "Gnewaccount" | "Gexp" | "Gexpbyte" | "Gmemory" | "Gtxcreate"
| "Gtxdatazero" | "Gtxdatanonzero" | "Gtransaction" | "Glog" | "Glogdata" | "Glogtopic" | "Gsha3"
| "Gsha3word" | "Gcopy" | "Gblockhash" | "Gquadcoeff" | "maxCodeSize" | "Rb" | "Gquaddivisor"
| "Gecadd" | "Gecmul" | "Gecpairconst" | "Gecpaircoeff"
// ---------------------------------------------------------------------------------------------
| "Gecadd" | "Gecmul" | "Gecpairconst" | "Gecpaircoeff" | "Gfround"
// ----------------------------------------------------------------------------------------------------------
```

### Default Schedule
Expand Down Expand Up @@ -2358,6 +2377,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
rule Gecmul < DEFAULT > => 40000
rule Gecpairconst < DEFAULT > => 100000
rule Gecpaircoeff < DEFAULT > => 80000
rule Gfround < DEFAULT > => 1
rule maxCodeSize < DEFAULT > => 2 ^Int 32 -Int 1
rule Rb < DEFAULT > => 5 *Int (10 ^Int 18)
Expand Down
3 changes: 0 additions & 3 deletions tests/failing.llvm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ tests/ethereum-tests/BlockchainTests/GeneralStateTests/stBadOpcode/badOpcodes.js
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stChainId/chainIdGasCost.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stChainId/chainId.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stCreate2/Create2Recursive.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stPreCompiledContracts2/CALLBlake2f.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stPreCompiledContracts2/CALLCODEBlake2f.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Create1000Byzantium.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Create1000.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stRecursiveCreate/recursiveCreateReturnValue.json
tests/ethereum-tests/BlockchainTests/GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json
tests/ethereum-tests/LegacyTests/Constantinople/BlockchainTests/GeneralStateTests/stCreate2/Create2Recursive_d0g0v0.json
tests/ethereum-tests/LegacyTests/Constantinople/BlockchainTests/GeneralStateTests/stCreate2/Create2Recursive_d0g1v0.json
tests/ethereum-tests/LegacyTests/Constantinople/BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/Create1000Byzantium_d0g1v0.json
Expand Down
107 changes: 107 additions & 0 deletions tests/web3/blake2.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[
{
"jsonrpc": "2.0",
"id": 0,
"result": ""
},
{
"jsonrpc": "2.0",
"id": 1,
"result": ""
},
{
"jsonrpc": "2.0",
"id": 2,
"result": ""
},
{
"jsonrpc": "2.0",
"id": 3,
"result": ""
},
{
"jsonrpc": "2.0",
"id": 4,
"result": "08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b"
},
{
"jsonrpc": "2.0",
"id": 5,
"result": "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"
},
{
"jsonrpc": "2.0",
"id": 6,
"result": "75ab69d3190a562c51aef8d88f1c2775876944407270c42c9844252c26d2875298743e7f6d5ea2f2d3e8d226039cd31b4e426ac4f2d3d666a610c2116fde4735"
},
{
"jsonrpc": "2.0",
"id": 7,
"result": "b63a380cb2897d521994a85234ee2c181b5f844d2c624c002677e9703449d2fba551b3a8333bcdf5f2f7e08993d53923de3d64fcc68c034e717b9293fed7a421"
},
{
"jsonrpc":"2.0",
"id": 8,
"result": "5e6563daea76f0766a4c70cd34bf3edf59ce91ee7e2eb668feb2b60f1c687d7438e1c2c29a5a5dcd3da4ca87a92209e4708731396fcc440a5a1e62787f7c8b9a"
},
{
"jsonrpc":"2.0",
"id": 9,
"result": "193a3b81c1b1ba0c2817d12434cf008c56f7c39c2786165931e88b7efee7a9ad02bc3612125e7512623df4ec1d1166d916e1013c5f64157e7585db4141a25e55"
},
{
"jsonrpc":"2.0",
"id": 10,
"result": "2b03e158fcf5806f5759d1523d9239dc2d9bd24a7213dc5f608db56790c90cc14aeb4e6cad3d314679455cbb6f13e700d390537b3bbead4d19444129493103be"
},
{
"jsonrpc":"2.0",
"id": 11,
"result": "a8ef8236e5f48a74af375df15681d128457891c1cc4706f30747b2d40300b2f49d19f80fbd0945fd87736e1fc1ff10a80fd85a7aa5125154f3aaa3789ddff673"
},
{
"jsonrpc":"2.0",
"id": 12,
"result": "46729c2367d9b0f1940e3a13319c4bd4398d74640eb09f023481dbb1952aca6e55c5a22da0c7502b725d714cda68bb321192f43ca2f4eeb3fb7a2c0e022b86ef"
},
{
"jsonrpc":"2.0",
"id": 13,
"result": "1c0f6f0785d41d7c22c6c40e3e4a7f2d787ccf26204ee45f1adcab4b3b7615df9bb97b4e903563a52f97b7b3e5bb83762ed9fd140dbb9d855c2a1f107ec416c7"
},
{
"jsonrpc":"2.0",
"id": 14,
"result": "3ff8604873d56006c144fb1d4c84316fdb42b466a09c4416022573f7b3cd078bd0a658efb659c6cd1f73c1e3b3d1f0d4eef93183dd5438cf81b343e4f684a1a1"
},
{
"jsonrpc":"2.0",
"id": 15,
"result": "0c1b96fc9c06898bb49af24ef91a669143df8e847807765da43f8ad6c0ec5180e6ab033a21428e52c5d933345f81d8300a02158704935b7a020d990572ad9be0"
},
{
"jsonrpc":"2.0",
"id": 16,
"result": "3bec7c26dbf9fb0ccefb0c3cfc38f65118f29c1538f6cd9969857d6cd9802ca7da729afd9688fcd82c85ad1913fe48c0db42a951a72e4aed80db00571923afbe"
},
{
"jsonrpc":"2.0",
"id": 17,
"result": "458d06011153650319111fef15479ee1e97a322280534b8ba6b583743938671f56ee546c97802f033ac25863221a3843cbc09f78b435ada8098c3f9933e43245"
},
{
"jsonrpc":"2.0",
"id": 18,
"result": "307f79b2083b29ec66926bc36e1457f571f90b7cc0572faca1d9229ca35d704f73efee65f960489017168f67d9c9b3643752de57c6b70a7d6ebdda82282f5150"
},
{
"jsonrpc":"2.0",
"id": 19,
"result": "ecaa9f694717ab09e7cdb902cf15919f75eac3f3e29e6350d302e8088f20dcd24e2e789d1134432456c6a9591b977cc2c464ed51d333fe68c30767e930d9f63a"
},
{
"jsonrpc":"2.0",
"id": 20,
"result": "fc59093aafa9ab43daae0e914c57635c5402d8e3d2130eb9b3cc181de7f0ecf9b22bf99a7815ce16419e200e01846e6b5df8cc7703041bbceb571de6631d2615"
}
]
126 changes: 126 additions & 0 deletions tests/web3/blake2.in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[{
"jsonrpc": "2.0",
"id": 0,
"method": "firefly_blake2compress",
"params": [ "" ]
},
{
"jsonrpc": "2.0",
"id": 1,
"method": "firefly_blake2compress",
"params": [ "0x00000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc": "2.0",
"id": 2,
"method": "firefly_blake2compress",
"params": [ "0x000000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc": "2.0",
"id": 3,
"method": "firefly_blake2compress",
"params": [ "0x0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000002" ]
},
{
"jsonrpc": "2.0",
"id": 4,
"method": "firefly_blake2compress",
"params": [ "0x0000000048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc": "2.0",
"id": 5,
"method": "firefly_blake2compress",
"params": [ "0x0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc": "2.0",
"id": 6,
"method": "firefly_blake2compress",
"params": [ "0x0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000" ]
},
{
"jsonrpc": "2.0",
"id": 7,
"method": "firefly_blake2compress",
"params": [ "0x0000000148c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 8,
"method": "firefly_blake2compress",
"params": [ "0000000d48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 9,
"method": "firefly_blake2compress",
"params": [ "0000000e48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 10,
"method": "firefly_blake2compress",
"params": [ "0000000f48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 11,
"method": "firefly_blake2compress",
"params": [ "0000001048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 12,
"method": "firefly_blake2compress",
"params": [ "0000001148c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 13,
"method": "firefly_blake2compress",
"params": [ "0000001248c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 14,
"method": "firefly_blake2compress",
"params": [ "0000001348c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 15,
"method": "firefly_blake2compress",
"params": [ "0000001448c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 16,
"method": "firefly_blake2compress",
"params": [ "0000001548c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 17,
"method": "firefly_blake2compress",
"params": [ "0000001648c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 18,
"method": "firefly_blake2compress",
"params": [ "0000001748c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 19,
"method": "firefly_blake2compress",
"params": [ "0000001848c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
},
{
"jsonrpc":"2.0",
"id": 20,
"method": "firefly_blake2compress",
"params": [ "ffffffff48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001" ]
}]
Loading

0 comments on commit 8167a3f

Please sign in to comment.