Skip to content

Commit

Permalink
precompile: Add dummy point evaluation (EIP-4844) (#730)
Browse files Browse the repository at this point in the history
Introduce EIP-4844 point evaluation precompile with dummy implementation
and add JSON stub entries for it.
  • Loading branch information
chfast authored Nov 23, 2023
2 parents beaa0a2 + bd6c3de commit 2223e78
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 4 deletions.
10 changes: 10 additions & 0 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ PrecompileAnalysis expmod_analyze(bytes_view input, evmc_revision rev) noexcept
static_cast<size_t>(mod_len)};
}

PrecompileAnalysis point_evaluation_analyze(bytes_view, evmc_revision) noexcept
{
static constexpr auto POINT_EVALUATION_PRECOMPILE_GAS = 50000;
return {POINT_EVALUATION_PRECOMPILE_GAS, 64};
}

ExecutionResult ecrecover_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
Expand Down Expand Up @@ -263,6 +269,7 @@ inline constexpr auto traits = []() noexcept {
{ecmul_analyze, ecmul_execute},
{ecpairing_analyze, dummy_execute<PrecompileId::ecpairing>},
{blake2bf_analyze, dummy_execute<PrecompileId::blake2bf>},
{point_evaluation_analyze, dummy_execute<PrecompileId::point_evaluation>},
}};
#ifdef EVMONE_PRECOMPILES_SILKPRE
// tbl[static_cast<size_t>(PrecompileId::ecrecover)].execute = silkpre_ecrecover_execute;
Expand Down Expand Up @@ -295,6 +302,9 @@ bool is_precompile(evmc_revision rev, const evmc::address& addr) noexcept
if (rev < EVMC_ISTANBUL && id >= stdx::to_underlying(PrecompileId::since_istanbul))
return false;

if (rev < EVMC_CANCUN && id >= stdx::to_underlying(PrecompileId::since_cancun))
return false;

return true;
}

Expand Down
8 changes: 5 additions & 3 deletions test/state/precompiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ enum class PrecompileId : uint8_t
ecmul = 0x07,
ecpairing = 0x08,
blake2bf = 0x09,
point_evaluation = 0x0a,

since_byzantium = expmod, ///< The first precompile introduced in Byzantium.
since_istanbul = blake2bf, ///< The first precompile introduced in Istanbul.
latest = blake2bf ///< The latest introduced precompile (highest address).
since_byzantium = expmod, ///< The first precompile introduced in Byzantium.
since_istanbul = blake2bf, ///< The first precompile introduced in Istanbul.
since_cancun = point_evaluation, ///< The first precompile introduced in Cancun.
latest = point_evaluation ///< The latest introduced precompile (highest address).
};

/// The total number of known precompiles ids, including 0.
Expand Down
123 changes: 123 additions & 0 deletions test/state/precompiles_stub.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,5 +693,128 @@
"f352cd3242546c7cb1ee7c4dbf7c4cba948d505150b17fae38bff05efb7018fb": "a8ef8236e5f48a74af375df15681d128457891c1cc4706f30747b2d40300b2f49d19f80fbd0945fd87736e1fc1ff10a80fd85a7aa5125154f3aaa3789ddff673",
"f6f043c5d533a3310a6ccbc5ec11199f7038a750a570ff5be9e715eb3614c0b1": "6d2ce9e534d50e18ff866ae92d70cceba79bbcd14c63819fe48752c8aca87a4bb7dcc230d22a4047f0486cfcfb50a17b24b2899eb8fca370f22240adb5170189",
"fb59d1e38c2473ebc92cd9d9bded35e13a214ab589f11fb07ffc0703784eb33d": "08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b"
},
{
"00921f4c0512d38d3e47f51c61fe0462d685d7165b7a330a79e072daacf56d3b": null,
"0431ab5e28f24e5ee4c929cb3c1385d8f13c1318b58d2301854c6f326fecbcbe": null,
"0589e071793fbf75265d0b961534d0a67a1a44342488b6bcf0b60b783ff9464e": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"08f90802e4e96e0dad506e9d2837054e6e3801bdf2f59b42943a5c46cf3a79f5": null,
"096e352957e96e7d1a3508453d7bdcd0fcc4511a3cc2bf8774864a1c301d1c36": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"0a1b931e17ea2dcab5706d01edc0b63d53ad9a1f7a459e401cfdd447fd97ca15": null,
"0a3146c7b4717e03402621b785c6ea86127bddcacdf28830fa9ad63ef03404f8": null,
"133473a1c65b26ab31f0969131231efcb44bf2d1071418b61b144d8d3dc20413": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"14e9c2bc7bb33e8f6244d5c3a3ad2367d0055e551b77cdad8fe51587be70eec9": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"175f9ee40ebf01d5e3615106af6313d4d750b34f0621ed376da2ca15c54df36b": null,
"17bf00af651edc7b8652427a555692369cec68ecc47479d22bfb99b3a35cc959": null,
"1aee78f5e34e2b1ae4203596ec1bbe430576a6967920550dc04372948460741b": null,
"20f494390d78517391d2592f69fbcc38895b9334469fae5a3277df695f110a5c": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"21208cfa9546642d7cc86f6a4ad441e42a933f2a305e6f7aeb44328db3635737": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"21b0bf99a56e002e026142ba063e7f3cf042925ce6d20d605e3a296cc93e6f32": null,
"22f41d0f018e19c6e7a6fd22c4a128db5d37c3361920a9749062b83e74b41d1c": null,
"2380dc8f447b25ecdf5c9fc1430aee9dd24c71d26f440e098cf801e7fc64ef77": null,
"241e9aa964370f8df6175f1a471b6037aa1a53740d49be7fe02223fdba9ba641": null,
"28261bfa518abbdb1cda1bbdfd79d7c002e1fd9993322c85e9f4cc003517e3c6": null,
"2e8d278558d22d9c9ea4e05bbc9a9370af540998ecd653bd2dac1c9fa8657640": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"3092eec0b6242826422740d02038e89df2cfaede284b3299d127114f195bb7f5": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"34a2bc8e9654c0dd00e5a98de6cb5c0fa5416862a65a6279f21fad25e8535b67": null,
"3803e6001c21ffa8692722e0319d0b68d7d54f49ba92aa293200f6c8c29a9433": null,
"3b87a73e79a85e4cae4baac64fe4d04c343d5f31ce9b0f0ab5a65ce005864cb3": null,
"3d1be775a559cc4b178a958e9ea1aedad52f7bb8517ae28d4f0ffeff92c68750": null,
"3e0769297bfd63d780c9ad18ce1a129e50fbcf81b8b7c75336596ae4b73eb157": null,
"3e90e6663f49afd82e3f6e5aad1cd5eeb23a67c16bc6cb7b71df213e215ee1db": null,
"42e5a4efd1d18ba9998b653916006cfe0ebee3391f05dccc10d908fced23be4d": null,
"447d75d38095bef1274f83ef8218d1d8e04879d57b3c5c3531751d91396a40d9": null,
"467674870ea61dfdac5df5659a1444edbf6be7a715acc557ca939db56e06a7ce": null,
"46b26c0af0b3a60a3ae1f01f8a018b309c78faaebecf9de093868400acf04380": null,
"47b6e7ce049189c4b6ac3ee64144cd8f8016d3f339e4acc171ea54cbb05c495e": null,
"4cc073f92b031dce2200df48f6f142bcb858848d31164e7a73ed0e3dbcd45486": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"4d45b7861a1be5d811e1d331652ca529b61421fc6040db86913381dbefa5b354": null,
"4d7c764363246add0c7abb25d0fd988e530c49ea6ecbafce19aa20f519af5d98": null,
"53017b73cdd1b1400de021f3c0f9e196e52e426da5e2dc48eb292b54a995ef83": null,
"547854239f932df42a08c700194ba25de7d5041efe91f56ec67073a8a4c11ac2": null,
"557eb4bff5c34e5389c4b7fd8336cc501f28ea6f757dd7c353c7c8fabaec7bd2": null,
"569f5b59e40762c5b591b70f32d2ad4d4cfdb57349f24864130f10c54f8b0c82": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"58a1f3b1592a2742d22cc4522d1f2914618835a17efa742484d62d6f18caf881": null,
"59ad4e3ef5d781363478cfc1342d89e957f53fad15cb8ec7ecf9fe7b5bc7ef86": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"5e471e7cd42b5d4dfcebaae8b687a1a8222c4c1ef4c795cfdf34f5666fb5f3ab": null,
"60daab1a5266d7bf678c1d1908903a4c2afc06017fa17be27ad1ce80a386f06e": null,
"611544424d5e86ad11b3aa9884326bfc934a6283cc909a4b5a592a1ba89781f8": null,
"630342fff21dcb01589b2423a25daa800691714081e5e6b976d60feb9488d777": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"636f33cf778e400ed34bae7c0d006f237ffc2b6e2840711f6c7d4ffd3885f51f": null,
"63d37b6fce974fbdf45fdf1a00ded78d7d9ac6cb93221f80e2fe2afc675e2aa1": null,
"64620581a3d1bcbd77473f28260fecabdc3093cf52d4fbc76137ad84a316ee15": null,
"657e067cd88bdd8ed4cc9fbbee29a147a899dab7321a15d914a58d9613fff9df": null,
"67b61dafee7c4c478dde4ff10f797d01c960c09f0e98f1a9b11ed06c716eac55": null,
"67e154a164d1a97cd2c9ce581b92fe15ed0bae46433af2972d2349dd911deb0d": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"688df6b2060d85865bd7ef112f67d3397cef9a74e163a26f6e5a1ca4bdf0c903": null,
"6ccc94187f6ab69f0fa686a53bc19bf031adc529ffd811a8ef72789e7f54d060": null,
"6e62e84b84fc7b9d7c1557f4a1385d75086f44244bc1a9a5205e3872afdeb6ea": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"6eb49ec98693237d5e9895436f31e515811923a7efb0dbc0af1e62406119dea6": null,
"71e9e191394799257c36a05a93bef11869217c3f80383d5fd56621d068585697": null,
"73c51de374ed554b2c0229b1fe61c7933cf70c951e9dcde9a0639dc77797a4cd": null,
"760238be816f9009398d33b02078cf6b35bcdeed98776bf1573096a90d25137a": null,
"835acc3d5934a71b908d7810042a03ce88adbf4895a72289ec1439695b555991": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"85360f27ca43987398bb3573b48350f59b57e3457d0e20eebf06d47f7f4d288c": null,
"86082880cb127b2bafa346a525203de515a240a9ac2ff8f0f4f0dbd3d7c24456": null,
"88562b631edfc6d205f4ccee10a6367df054cd1e7fae7eeb5f43b8f73a9d3e08": null,
"8d6802c95290312dd19a7a74613256bc26e6591a8c13ecfd574069f4f0e840a7": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"921c1cf1ca24e768450334e9de833c8712ecdae833fff797b1535581b22f2b6b": null,
"93e3b9e8a17dad042ce4696d5a8d75bac9a0e6f15c919d0a7aa65df9c178e5ff": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"949ea0caf3571247238de2b53778e2eec1f87d02786278a4b1ecbd064ec2706c": null,
"95b64a72633e28a170f339046328392a62c619afc4462a1938628f83f927e269": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"96fb4dc882be76583f56a73d7db47b95e9dbfe5a231a8efcb8ba039a6e86508f": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"9757d94207433dd570417b4e61a6df491c790e5376dd2db5731e20a9d9fb9094": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"98429988c1d04d35ab7b862a2f9c652dab87cb72f264e27758a351881bc7049c": null,
"98ee43df38f66ae2679744c8696d1e93cb66f269a39a190131b691bb62c30b8e": null,
"9924363fd9c8f8672d7f4c79b9a0bc2e73b16d574bbc5daaf8a8ffa6a7e05331": null,
"9c917bef4c852a1ff6a802481c248a4dbf2402ac3f36f2fea558c08ccfede9cb": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"9d916df4d3d4315b556285a37e7638a20b140d7ff238aaa2986499651a0a64d8": null,
"a411c99d21cb94fc7098b8d379d6d946e901099bcd70f6c634305025d7635d40": null,
"a49e591712216483b8d2ef7af3ca8500c438a30a8ce9675326a2012bbcc5f1c6": null,
"aba44fc4c2cf662439dc1bdf5785db9db823c0cf5a7479d658a7ccc3dec5493e": null,
"ad44ff9b25d242c085317963bb123c269424176e840a5a3a9f72f255b269be4e": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"b0abb83298817666f6c21809d1777285c4c529294b630f9ccee0c115e6eab3f8": null,
"b19213210ad884b8661d40dfb4564eb839b05aa0a386364e4e7bb384c7763f06": null,
"be3d6064af8297187deba62c0f6228d3ba9883e569881dfdb37778537c631023": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"bf8163967b7aa7b46d814c29540359dbdbfe2e986ea4e09f446c3ac801951902": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"c2a919253ce5896a498cda2fa2ac88dbfbddcbb6aaa6a0c7d181b5da8ec8a46a": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470": null,
"c8ceb5dae9fc49cf15b300d7f7bac8d76e1911dd1d77285785ab80e9d4793114": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"cb7f870125114e2f8c2b60c1b3f1b89ff5ecb61acc0c876e1a44c7f41c248a12": null,
"cc0e04a98f7059ece7302d49e6fb40300c6776e964637ee52f9732f151bea811": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"cc3b81747514a655269e797a7ee50a79829963ced741f263b26d2686d6ca5aa4": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"cc4adef0e938d43a3fb0d521e70ef1f7fb30ff8ac9a1ac1267df7b0631c1f08f": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"cfa51da6f23a44d99441405a0afc1d2f2f19409006b892edc4b621364436db2d": null,
"d0c71f7a78e1659c98a60d38d934157e954a8714749e60dcddefda81ae3cc4bc": null,
"d4964e4e4acc4a09af21cc7349de943d7a00ee1b8ab97ecc3581f6480a594934": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"d4fc672243d64b627f0d0fbd2dda552cd128ff902d80accc2aee67d651c164d9": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"d943e0bf49906b2bdb4e80c185ca7c8916874aec96e907c7c6c8d96de3d0b9f1": null,
"da6805cdab98d18521d558effcbe74d2aecba6a2c833663d03f551f9069b012b": null,
"daeeebacf560d100ae3b495eb63f8ff3003b6d50bc1d0294d8853774cd6432b4": null,
"db9af7ad6f9798dc85f7c15d04ff7cac0eb0fc124f5087116ec321450d5682c1": null,
"dba6e80ddaca0e93917b64ed44642caedf4e35d37b2bf920c2e1726ebdbd404d": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"dc626a940f069de259e183aafd537151ed034aaf8490c2de51405ab0727a2685": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"e0481904bc4f04ca6bf660fa6da96d7240b52d2115cc1efacfaff1d3736b7c38": null,
"e3c1f2562cbcc523e45dd93f2e1e87f7cf592011b043dee18c06ac405e81c401": null,
"e4f857995acb714236297ba997dd6833d4859b91a7524bdbca795bf5e6d6e253": null,
"e61e626e7350bf9dec586c59c592644043c5b0b8e1b1db4a178f9dc7bd33ab6f": null,
"e6703953cf479857435a59e52fc7fb63b39da7996beefad32a52cef9692d1683": null,
"e6b44babf2ebbd40d135a338b0c0204640ab492f17de57c03d684b1596e797dc": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"e741b3b55653d470245cb4c20afd21f4c6fd63b2f3b1a54beb6029878ff0ad20": null,
"e75ba1e457ebb78e9c2762e962f19623a5f0fd7b41e08cb24b0791e3ab0b3347": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"e7dcc6f0a1d5d5a90bc5eb3691e49f02fb5b6363df02d1b3d0b3c68a01070dc5": null,
"e7fb86fd31187f2ecad624c5f6462e265cd0a482d69e1dcf22125812d980959c": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"ec9c9502f2a270e447933f85a233230ea9a96cf77436c500e6d601254ea65392": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"ed382547180c9fb43baa90081b471822c92d352359a4a38000fe249e1aa9e3cd": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"ef302fb9ea1d990905dc2a847b5acd2b85cfe16631f87b4fed195e9af050c8bc": null,
"efad391eb6b08e043e437cfbc436f4482f8a6f58d508da80e575851afe76682c": null,
"f01258050fca52deb8648afa705239893f1db7f1112a7c1f67b06c92bfeaa6e7": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"f0369dc275fcfae2954f10bcbae9093b1ba0790b440166e4119ab54591d1d1d2": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"f0b8e414e14bf9cd59cdbd0b2b8ca78b07d0a583cb83e9facc256701b90275a9": null,
"f63d4348b5ba82c8c0776059e1355079047d893d99ff6e090930e52d7cfdd928": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"f8be24c18835e0eecd7f60de1a1430b859851df6941480a2ac53094daf161626": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"f9e6fcc5ca6a4bd8848609a905a333a6ac0f7d5fe6b00fd40f2c4544be1e2543": null,
"fa22f97d699746dfed9566c4881ceb9ea3e19e5e53409b93e3bb49e025e3d8f6": "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",
"fa561744f544273acd92e7946b5ce4d6ef15cd20f2f2a99705585da7ae0523eb": null
}
]
4 changes: 3 additions & 1 deletion test/unittests/state_precompiles_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ TEST(state_precompiles, is_precompile)
// Istanbul:
EXPECT_EQ(is_precompile(rev, 0x09_address), rev >= EVMC_ISTANBUL);

// Cancun:
EXPECT_EQ(is_precompile(rev, 0x0a_address), rev >= EVMC_CANCUN);

// Future?
EXPECT_FALSE(is_precompile(rev, 0x0a_address));
EXPECT_FALSE(is_precompile(rev, 0x0b_address));
EXPECT_FALSE(is_precompile(rev, 0x0c_address));
EXPECT_FALSE(is_precompile(rev, 0x0d_address));
Expand Down

0 comments on commit 2223e78

Please sign in to comment.