Skip to content

Commit 2c450ef

Browse files
committed
evmmax: Apply a hack to use the newest evmome/evmc
1 parent ce7d1cf commit 2c450ef

File tree

6 files changed

+265
-10
lines changed

6 files changed

+265
-10
lines changed

test/EVMHost.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ evmc::Result EVMHost::call(evmc_message const& _message) noexcept
416416
message.input_data = nullptr;
417417
message.input_size = 0;
418418
}
419-
evmc::Result result = m_vm.execute(*this, m_evmRevision, message, code.data(), code.size());
419+
evmc::Result result = m_vm.execute(*this, static_cast<evmc_revision>(15), message, code.data(), code.size());
420420

421421
if (message.kind == EVMC_CREATE || message.kind == EVMC_CREATE2 || message.kind == EVMC_EOFCREATE)
422422
{

test/evmc/evmc.h

+15-8
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ enum evmc_call_kind
8080
EVMC_CALLCODE = 2, /**< Request CALLCODE. */
8181
EVMC_CREATE = 3, /**< Request CREATE. */
8282
EVMC_CREATE2 = 4, /**< Request CREATE2. Valid since Constantinople.*/
83-
EVMC_EOFCREATE = 5 /**< Request EOFCREATE. Valid since Prague.*/
83+
EVMC_EOFCREATE = 5 /**< Request EOFCREATE. Valid since Osaka.*/
8484
};
8585

8686
/** The flags for ::evmc_message. */
8787
enum evmc_flags
8888
{
89-
EVMC_STATIC = 1 /**< Static call mode. */
89+
EVMC_STATIC = 1, /**< Static call mode. */
90+
EVMC_DELEGATED = 2 /**< Delegated call mode (EIP-7702). Valid since Prague. */
9091
};
9192

9293
/**
@@ -101,7 +102,7 @@ struct evmc_message
101102

102103
/**
103104
* Additional flags modifying the call execution behavior.
104-
* In the current version the only valid values are ::EVMC_STATIC or 0.
105+
*
105106
*/
106107
uint32_t flags;
107108

@@ -1033,21 +1034,27 @@ enum evmc_revision
10331034
EVMC_CANCUN = 12,
10341035

10351036
/**
1036-
* The Prague revision.
1037+
* The Prague / Pectra revision.
10371038
*
1038-
* The future next revision after Cancun.
1039+
* https://eips.ethereum.org/EIPS/eip-7600
10391040
*/
10401041
EVMC_PRAGUE = 13,
10411042

10421043
/**
1043-
* The Osaka revision.
1044+
* The Osaka / Fusaka revision.
10441045
*
1045-
* The future next revision after Prague.
1046+
* https://eips.ethereum.org/EIPS/eip-7607
10461047
*/
10471048
EVMC_OSAKA = 14,
10481049

1050+
/**
1051+
* The unspecified EVM revision used for EVM implementations to expose
1052+
* experimental features.
1053+
*/
1054+
EVMC_EXPERIMENTAL = 15,
1055+
10491056
/** The maximum EVM revision supported. */
1050-
EVMC_MAX_REVISION = EVMC_OSAKA,
1057+
EVMC_MAX_REVISION = EVMC_EXPERIMENTAL,
10511058

10521059
/**
10531060
* The latest known EVM revision with finalized specification.

test/evmc/helpers.h

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ static inline const char* evmc_revision_to_string(enum evmc_revision rev)
303303
return "Prague";
304304
case EVMC_OSAKA:
305305
return "Osaka";
306+
case EVMC_EXPERIMENTAL:
307+
return "Experimental";
306308
}
307309
return "<unknown>";
308310
}

test/evmc/instructions.h

+227
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
// EVMC: Ethereum Client-VM Connector API.
2+
// Copyright 2018 The EVMC Authors.
3+
// Licensed under the Apache License, Version 2.0.
4+
5+
/**
6+
* EVM Instruction Tables
7+
*
8+
* A collection of metrics for EVM1 instruction set.
9+
*
10+
* @defgroup instructions EVM Instructions
11+
* @{
12+
*/
13+
#pragma once
14+
15+
#include <evmc/evmc.h>
16+
#include <evmc/utils.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
/**
23+
* The list of EVM 1 opcodes from every EVM revision.
24+
*/
25+
enum evmc_opcode
26+
{
27+
OP_STOP = 0x00,
28+
OP_ADD = 0x01,
29+
OP_MUL = 0x02,
30+
OP_SUB = 0x03,
31+
OP_DIV = 0x04,
32+
OP_SDIV = 0x05,
33+
OP_MOD = 0x06,
34+
OP_SMOD = 0x07,
35+
OP_ADDMOD = 0x08,
36+
OP_MULMOD = 0x09,
37+
OP_EXP = 0x0a,
38+
OP_SIGNEXTEND = 0x0b,
39+
40+
OP_LT = 0x10,
41+
OP_GT = 0x11,
42+
OP_SLT = 0x12,
43+
OP_SGT = 0x13,
44+
OP_EQ = 0x14,
45+
OP_ISZERO = 0x15,
46+
OP_AND = 0x16,
47+
OP_OR = 0x17,
48+
OP_XOR = 0x18,
49+
OP_NOT = 0x19,
50+
OP_BYTE = 0x1a,
51+
OP_SHL = 0x1b,
52+
OP_SHR = 0x1c,
53+
OP_SAR = 0x1d,
54+
55+
OP_KECCAK256 = 0x20,
56+
57+
OP_ADDRESS = 0x30,
58+
OP_BALANCE = 0x31,
59+
OP_ORIGIN = 0x32,
60+
OP_CALLER = 0x33,
61+
OP_CALLVALUE = 0x34,
62+
OP_CALLDATALOAD = 0x35,
63+
OP_CALLDATASIZE = 0x36,
64+
OP_CALLDATACOPY = 0x37,
65+
OP_CODESIZE = 0x38,
66+
OP_CODECOPY = 0x39,
67+
OP_GASPRICE = 0x3a,
68+
OP_EXTCODESIZE = 0x3b,
69+
OP_EXTCODECOPY = 0x3c,
70+
OP_RETURNDATASIZE = 0x3d,
71+
OP_RETURNDATACOPY = 0x3e,
72+
OP_EXTCODEHASH = 0x3f,
73+
74+
OP_BLOCKHASH = 0x40,
75+
OP_COINBASE = 0x41,
76+
OP_TIMESTAMP = 0x42,
77+
OP_NUMBER = 0x43,
78+
OP_PREVRANDAO = 0x44,
79+
OP_GASLIMIT = 0x45,
80+
OP_CHAINID = 0x46,
81+
OP_SELFBALANCE = 0x47,
82+
OP_BASEFEE = 0x48,
83+
84+
OP_POP = 0x50,
85+
OP_MLOAD = 0x51,
86+
OP_MSTORE = 0x52,
87+
OP_MSTORE8 = 0x53,
88+
OP_SLOAD = 0x54,
89+
OP_SSTORE = 0x55,
90+
OP_JUMP = 0x56,
91+
OP_JUMPI = 0x57,
92+
OP_PC = 0x58,
93+
OP_MSIZE = 0x59,
94+
OP_GAS = 0x5a,
95+
OP_JUMPDEST = 0x5b,
96+
97+
OP_PUSH0 = 0x5f,
98+
OP_PUSH1 = 0x60,
99+
OP_PUSH2 = 0x61,
100+
OP_PUSH3 = 0x62,
101+
OP_PUSH4 = 0x63,
102+
OP_PUSH5 = 0x64,
103+
OP_PUSH6 = 0x65,
104+
OP_PUSH7 = 0x66,
105+
OP_PUSH8 = 0x67,
106+
OP_PUSH9 = 0x68,
107+
OP_PUSH10 = 0x69,
108+
OP_PUSH11 = 0x6a,
109+
OP_PUSH12 = 0x6b,
110+
OP_PUSH13 = 0x6c,
111+
OP_PUSH14 = 0x6d,
112+
OP_PUSH15 = 0x6e,
113+
OP_PUSH16 = 0x6f,
114+
OP_PUSH17 = 0x70,
115+
OP_PUSH18 = 0x71,
116+
OP_PUSH19 = 0x72,
117+
OP_PUSH20 = 0x73,
118+
OP_PUSH21 = 0x74,
119+
OP_PUSH22 = 0x75,
120+
OP_PUSH23 = 0x76,
121+
OP_PUSH24 = 0x77,
122+
OP_PUSH25 = 0x78,
123+
OP_PUSH26 = 0x79,
124+
OP_PUSH27 = 0x7a,
125+
OP_PUSH28 = 0x7b,
126+
OP_PUSH29 = 0x7c,
127+
OP_PUSH30 = 0x7d,
128+
OP_PUSH31 = 0x7e,
129+
OP_PUSH32 = 0x7f,
130+
OP_DUP1 = 0x80,
131+
OP_DUP2 = 0x81,
132+
OP_DUP3 = 0x82,
133+
OP_DUP4 = 0x83,
134+
OP_DUP5 = 0x84,
135+
OP_DUP6 = 0x85,
136+
OP_DUP7 = 0x86,
137+
OP_DUP8 = 0x87,
138+
OP_DUP9 = 0x88,
139+
OP_DUP10 = 0x89,
140+
OP_DUP11 = 0x8a,
141+
OP_DUP12 = 0x8b,
142+
OP_DUP13 = 0x8c,
143+
OP_DUP14 = 0x8d,
144+
OP_DUP15 = 0x8e,
145+
OP_DUP16 = 0x8f,
146+
OP_SWAP1 = 0x90,
147+
OP_SWAP2 = 0x91,
148+
OP_SWAP3 = 0x92,
149+
OP_SWAP4 = 0x93,
150+
OP_SWAP5 = 0x94,
151+
OP_SWAP6 = 0x95,
152+
OP_SWAP7 = 0x96,
153+
OP_SWAP8 = 0x97,
154+
OP_SWAP9 = 0x98,
155+
OP_SWAP10 = 0x99,
156+
OP_SWAP11 = 0x9a,
157+
OP_SWAP12 = 0x9b,
158+
OP_SWAP13 = 0x9c,
159+
OP_SWAP14 = 0x9d,
160+
OP_SWAP15 = 0x9e,
161+
OP_SWAP16 = 0x9f,
162+
OP_LOG0 = 0xa0,
163+
OP_LOG1 = 0xa1,
164+
OP_LOG2 = 0xa2,
165+
OP_LOG3 = 0xa3,
166+
OP_LOG4 = 0xa4,
167+
168+
OP_CREATE = 0xf0,
169+
OP_CALL = 0xf1,
170+
OP_CALLCODE = 0xf2,
171+
OP_RETURN = 0xf3,
172+
OP_DELEGATECALL = 0xf4,
173+
OP_CREATE2 = 0xf5,
174+
175+
OP_STATICCALL = 0xfa,
176+
177+
OP_REVERT = 0xfd,
178+
OP_INVALID = 0xfe,
179+
OP_SELFDESTRUCT = 0xff
180+
};
181+
182+
/**
183+
* Metrics for an EVM 1 instruction.
184+
*
185+
* Small integer types are used here to make the tables of metrics smaller.
186+
*/
187+
struct evmc_instruction_metrics
188+
{
189+
/** The instruction gas cost. */
190+
int16_t gas_cost;
191+
192+
/** The minimum number of the EVM stack items required for the instruction. */
193+
int8_t stack_height_required;
194+
195+
/**
196+
* The EVM stack height change caused by the instruction execution,
197+
* i.e. stack height _after_ execution - stack height _before_ execution.
198+
*/
199+
int8_t stack_height_change;
200+
};
201+
202+
/**
203+
* Get the table of the EVM 1 instructions metrics.
204+
*
205+
* @param revision The EVM revision.
206+
* @return The pointer to the array of 256 instruction metrics. Null pointer in case
207+
* an invalid EVM revision provided.
208+
*/
209+
EVMC_EXPORT const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table(
210+
enum evmc_revision revision);
211+
212+
/**
213+
* Get the table of the EVM 1 instruction names.
214+
*
215+
* The entries for undefined instructions contain null pointers.
216+
*
217+
* @param revision The EVM revision.
218+
* @return The pointer to the array of 256 instruction names. Null pointer in case
219+
* an invalid EVM revision provided.
220+
*/
221+
EVMC_EXPORT const char* const* evmc_get_instruction_names_table(enum evmc_revision revision);
222+
223+
#ifdef __cplusplus
224+
}
225+
#endif
226+
227+
/** @} */

test/evmc/mocked_host.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <algorithm>
88
#include <cassert>
99
#include <string>
10-
#include <map>
1110
#include <unordered_map>
11+
#include <map>
1212
#include <vector>
1313

1414
namespace evmc

test/evmc/tooling.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// EVMC: Ethereum Client-VM Connector API.
2+
// Copyright 2020 The EVMC Authors.
3+
// Licensed under the Apache License, Version 2.0.
4+
5+
#include <evmc/evmc.hpp>
6+
#include <iosfwd>
7+
#include <string>
8+
9+
namespace evmc::tooling
10+
{
11+
int run(VM& vm,
12+
evmc_revision rev,
13+
int64_t gas,
14+
bytes_view code,
15+
bytes_view input,
16+
bool create,
17+
bool bench,
18+
std::ostream& out);
19+
} // namespace evmc::tooling

0 commit comments

Comments
 (0)