Skip to content

Commit

Permalink
precompiles: Do not cache ripemd160
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Apr 4, 2024
1 parent f9f991f commit 5187061
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
19 changes: 12 additions & 7 deletions test/state/precompiles_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ std::optional<evmc::Result> Cache::find(PrecompileId id, bytes_view input, int64

void Cache::insert(PrecompileId id, bytes_view input, const evmc::Result& result)
{
if (id == PrecompileId::identity) // Do not cache "identity".
return;
const auto input_hash = keccak256(input);
std::optional<bytes> cached_output;
if (result.status_code == EVMC_SUCCESS)
cached_output = bytes{result.output_data, result.output_size};
m_cache.at(stdx::to_underlying(id)).insert({input_hash, std::move(cached_output)});
switch (id)
{
case PrecompileId::ripemd160:

Check warning on line 37 in test/state/precompiles_cache.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/precompiles_cache.cpp#L37

Added line #L37 was not covered by tests
case PrecompileId::identity:
return; // Do not cache.
default:
const auto input_hash = keccak256(input);
std::optional<bytes> cached_output;
if (result.status_code == EVMC_SUCCESS)
cached_output = bytes{result.output_data, result.output_size};
m_cache.at(stdx::to_underlying(id)).insert({input_hash, std::move(cached_output)});
}
}

Cache::Cache() noexcept
Expand Down
14 changes: 1 addition & 13 deletions test/state/precompiles_stub.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,7 @@
"da9978f0bc086d41a18d2b99f16c51583c2a38ee4c9346aa834dc50e66b4964d": "611ab7d0b1e0f74d9d8e9dad7daae35404c3c0c5d9e94839338562d708d8e9d0",
"fd6d486de5910c769ade60684c4e74e68a93a919b286607d7995398daf42204d": "3b745a1c00d035c334f358d007a430e4cf0ae63aa0556fb05529706de546464d"
},
{
"012893657d8eb2efad4de0a91bcd0e39ad9837745dec3ea923737ea803fc8e3d": "0000000000000000000000004300a157335cb7c9fc9423e011d7dd51090d093f",
"17bc5666b1ec85903b4657b6adaa1e0d32cce50dfa483c1c5948ebb3d8787268": "00000000000000000000000014ef238cfa4075e9ede92f18b1566c1dd0b99aaa",
"43c4b4524adb81e4e9a5c4648a98e9d320e3908ac5b6c889144b642cd08ae16d": "000000000000000000000000cd566972b5e50104011a92b59fa8e0b1234851ae",
"9ea7a819a0914e18e935cf832504011ef2ea4e0d3ee72af3c69d40e2066289af": "000000000000000000000000dbc100f916bfbc53535573d98cf0cbb3a5b36124",
"a1468185ed02fbc3b21223ec1c8c49605873fc9604653fa6ee049d60edc5ceb0": "000000000000000000000000c4053784867ac0165cbc1f7677386cae8489eae6",
"a9c584056064687e149968cbab758a3376d22aedc6a55823d1b3ecbee81b8fb9": "0000000000000000000000001cf4e77f5966e13e109703cd8a0df7ceda7f3dc3",
"ad4ac87fa8b6f7014b17f40a9d8c5ee373cf34535661d6375156c5ba3a04e3af": "000000000000000000000000316750573f9be26bc17727b47cacedbd0ab3e6ca",
"bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a": "000000000000000000000000c81b94933420221a7ac004a90242d8b1d3e5070d",
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470": "0000000000000000000000009c1185a5c5e9fc54612808977ee8f548b2258d31",
"da9978f0bc086d41a18d2b99f16c51583c2a38ee4c9346aa834dc50e66b4964d": "000000000000000000000000a2aa04ec13cbcdddd14a43575f1363ecb1cd90b7",
"fd6d486de5910c769ade60684c4e74e68a93a919b286607d7995398daf42204d": "0000000000000000000000007730b4642169b0f16752696da8da830a4b429c9d"
},
null,
null,
{
"010d1c26efabac677596f64e2e4f8894606e3636370a8665756ebc184e745aba": "000000000001",
Expand Down

0 comments on commit 5187061

Please sign in to comment.