jump_table.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package vm
  17. import (
  18. "errors"
  19. "math/big"
  20. "github.com/ethereum/go-ethereum/params"
  21. )
  22. type (
  23. executionFunc func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)
  24. gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64
  25. stackValidationFunc func(*Stack) error
  26. memorySizeFunc func(*Stack) *big.Int
  27. )
  28. var errGasUintOverflow = errors.New("gas uint64 overflow")
  29. type operation struct {
  30. // execute is the operation function
  31. execute executionFunc
  32. // gasCost is the gas function and returns the gas required for execution
  33. gasCost gasFunc
  34. // validateStack validates the stack (size) for the operation
  35. validateStack stackValidationFunc
  36. // memorySize returns the memory size required for the operation
  37. memorySize memorySizeFunc
  38. halts bool // indicates whether the operation should halt further execution
  39. jumps bool // indicates whether the program counter should not increment
  40. writes bool // determines whether this a state modifying operation
  41. valid bool // indication whether the retrieved operation is valid and known
  42. reverts bool // determines whether the operation reverts state (implicitly halts)
  43. returns bool // determines whether the operations sets the return data content
  44. }
  45. var (
  46. frontierInstructionSet = NewFrontierInstructionSet()
  47. homesteadInstructionSet = NewHomesteadInstructionSet()
  48. byzantiumInstructionSet = NewByzantiumInstructionSet()
  49. constantinopleInstructionSet = NewConstantinopleInstructionSet()
  50. )
  51. // NewConstantinopleInstructionSet returns the frontier, homestead
  52. // byzantium and contantinople instructions.
  53. func NewConstantinopleInstructionSet() [256]operation {
  54. // instructions that can be executed during the byzantium phase.
  55. instructionSet := NewByzantiumInstructionSet()
  56. instructionSet[SHL] = operation{
  57. execute: opSHL,
  58. gasCost: constGasFunc(GasFastestStep),
  59. validateStack: makeStackFunc(2, 1),
  60. valid: true,
  61. }
  62. instructionSet[SHR] = operation{
  63. execute: opSHR,
  64. gasCost: constGasFunc(GasFastestStep),
  65. validateStack: makeStackFunc(2, 1),
  66. valid: true,
  67. }
  68. instructionSet[SAR] = operation{
  69. execute: opSAR,
  70. gasCost: constGasFunc(GasFastestStep),
  71. validateStack: makeStackFunc(2, 1),
  72. valid: true,
  73. }
  74. return instructionSet
  75. }
  76. // NewByzantiumInstructionSet returns the frontier, homestead and
  77. // byzantium instructions.
  78. func NewByzantiumInstructionSet() [256]operation {
  79. // instructions that can be executed during the homestead phase.
  80. instructionSet := NewHomesteadInstructionSet()
  81. instructionSet[STATICCALL] = operation{
  82. execute: opStaticCall,
  83. gasCost: gasStaticCall,
  84. validateStack: makeStackFunc(6, 1),
  85. memorySize: memoryStaticCall,
  86. valid: true,
  87. returns: true,
  88. }
  89. instructionSet[RETURNDATASIZE] = operation{
  90. execute: opReturnDataSize,
  91. gasCost: constGasFunc(GasQuickStep),
  92. validateStack: makeStackFunc(0, 1),
  93. valid: true,
  94. }
  95. instructionSet[RETURNDATACOPY] = operation{
  96. execute: opReturnDataCopy,
  97. gasCost: gasReturnDataCopy,
  98. validateStack: makeStackFunc(3, 0),
  99. memorySize: memoryReturnDataCopy,
  100. valid: true,
  101. }
  102. instructionSet[REVERT] = operation{
  103. execute: opRevert,
  104. gasCost: gasRevert,
  105. validateStack: makeStackFunc(2, 0),
  106. memorySize: memoryRevert,
  107. valid: true,
  108. reverts: true,
  109. returns: true,
  110. }
  111. return instructionSet
  112. }
  113. // NewHomesteadInstructionSet returns the frontier and homestead
  114. // instructions that can be executed during the homestead phase.
  115. func NewHomesteadInstructionSet() [256]operation {
  116. instructionSet := NewFrontierInstructionSet()
  117. instructionSet[DELEGATECALL] = operation{
  118. execute: opDelegateCall,
  119. gasCost: gasDelegateCall,
  120. validateStack: makeStackFunc(6, 1),
  121. memorySize: memoryDelegateCall,
  122. valid: true,
  123. returns: true,
  124. }
  125. return instructionSet
  126. }
  127. // NewFrontierInstructionSet returns the frontier instructions
  128. // that can be executed during the frontier phase.
  129. func NewFrontierInstructionSet() [256]operation {
  130. return [256]operation{
  131. STOP: {
  132. execute: opStop,
  133. gasCost: constGasFunc(0),
  134. validateStack: makeStackFunc(0, 0),
  135. halts: true,
  136. valid: true,
  137. },
  138. ADD: {
  139. execute: opAdd,
  140. gasCost: constGasFunc(GasFastestStep),
  141. validateStack: makeStackFunc(2, 1),
  142. valid: true,
  143. },
  144. MUL: {
  145. execute: opMul,
  146. gasCost: constGasFunc(GasFastStep),
  147. validateStack: makeStackFunc(2, 1),
  148. valid: true,
  149. },
  150. SUB: {
  151. execute: opSub,
  152. gasCost: constGasFunc(GasFastestStep),
  153. validateStack: makeStackFunc(2, 1),
  154. valid: true,
  155. },
  156. DIV: {
  157. execute: opDiv,
  158. gasCost: constGasFunc(GasFastStep),
  159. validateStack: makeStackFunc(2, 1),
  160. valid: true,
  161. },
  162. SDIV: {
  163. execute: opSdiv,
  164. gasCost: constGasFunc(GasFastStep),
  165. validateStack: makeStackFunc(2, 1),
  166. valid: true,
  167. },
  168. MOD: {
  169. execute: opMod,
  170. gasCost: constGasFunc(GasFastStep),
  171. validateStack: makeStackFunc(2, 1),
  172. valid: true,
  173. },
  174. SMOD: {
  175. execute: opSmod,
  176. gasCost: constGasFunc(GasFastStep),
  177. validateStack: makeStackFunc(2, 1),
  178. valid: true,
  179. },
  180. ADDMOD: {
  181. execute: opAddmod,
  182. gasCost: constGasFunc(GasMidStep),
  183. validateStack: makeStackFunc(3, 1),
  184. valid: true,
  185. },
  186. MULMOD: {
  187. execute: opMulmod,
  188. gasCost: constGasFunc(GasMidStep),
  189. validateStack: makeStackFunc(3, 1),
  190. valid: true,
  191. },
  192. EXP: {
  193. execute: opExp,
  194. gasCost: gasExp,
  195. validateStack: makeStackFunc(2, 1),
  196. valid: true,
  197. },
  198. SIGNEXTEND: {
  199. execute: opSignExtend,
  200. gasCost: constGasFunc(GasFastStep),
  201. validateStack: makeStackFunc(2, 1),
  202. valid: true,
  203. },
  204. LT: {
  205. execute: opLt,
  206. gasCost: constGasFunc(GasFastestStep),
  207. validateStack: makeStackFunc(2, 1),
  208. valid: true,
  209. },
  210. GT: {
  211. execute: opGt,
  212. gasCost: constGasFunc(GasFastestStep),
  213. validateStack: makeStackFunc(2, 1),
  214. valid: true,
  215. },
  216. SLT: {
  217. execute: opSlt,
  218. gasCost: constGasFunc(GasFastestStep),
  219. validateStack: makeStackFunc(2, 1),
  220. valid: true,
  221. },
  222. SGT: {
  223. execute: opSgt,
  224. gasCost: constGasFunc(GasFastestStep),
  225. validateStack: makeStackFunc(2, 1),
  226. valid: true,
  227. },
  228. EQ: {
  229. execute: opEq,
  230. gasCost: constGasFunc(GasFastestStep),
  231. validateStack: makeStackFunc(2, 1),
  232. valid: true,
  233. },
  234. ISZERO: {
  235. execute: opIszero,
  236. gasCost: constGasFunc(GasFastestStep),
  237. validateStack: makeStackFunc(1, 1),
  238. valid: true,
  239. },
  240. AND: {
  241. execute: opAnd,
  242. gasCost: constGasFunc(GasFastestStep),
  243. validateStack: makeStackFunc(2, 1),
  244. valid: true,
  245. },
  246. XOR: {
  247. execute: opXor,
  248. gasCost: constGasFunc(GasFastestStep),
  249. validateStack: makeStackFunc(2, 1),
  250. valid: true,
  251. },
  252. OR: {
  253. execute: opOr,
  254. gasCost: constGasFunc(GasFastestStep),
  255. validateStack: makeStackFunc(2, 1),
  256. valid: true,
  257. },
  258. NOT: {
  259. execute: opNot,
  260. gasCost: constGasFunc(GasFastestStep),
  261. validateStack: makeStackFunc(1, 1),
  262. valid: true,
  263. },
  264. BYTE: {
  265. execute: opByte,
  266. gasCost: constGasFunc(GasFastestStep),
  267. validateStack: makeStackFunc(2, 1),
  268. valid: true,
  269. },
  270. SHA3: {
  271. execute: opSha3,
  272. gasCost: gasSha3,
  273. validateStack: makeStackFunc(2, 1),
  274. memorySize: memorySha3,
  275. valid: true,
  276. },
  277. ADDRESS: {
  278. execute: opAddress,
  279. gasCost: constGasFunc(GasQuickStep),
  280. validateStack: makeStackFunc(0, 1),
  281. valid: true,
  282. },
  283. BALANCE: {
  284. execute: opBalance,
  285. gasCost: gasBalance,
  286. validateStack: makeStackFunc(1, 1),
  287. valid: true,
  288. },
  289. ORIGIN: {
  290. execute: opOrigin,
  291. gasCost: constGasFunc(GasQuickStep),
  292. validateStack: makeStackFunc(0, 1),
  293. valid: true,
  294. },
  295. CALLER: {
  296. execute: opCaller,
  297. gasCost: constGasFunc(GasQuickStep),
  298. validateStack: makeStackFunc(0, 1),
  299. valid: true,
  300. },
  301. CALLVALUE: {
  302. execute: opCallValue,
  303. gasCost: constGasFunc(GasQuickStep),
  304. validateStack: makeStackFunc(0, 1),
  305. valid: true,
  306. },
  307. CALLDATALOAD: {
  308. execute: opCallDataLoad,
  309. gasCost: constGasFunc(GasFastestStep),
  310. validateStack: makeStackFunc(1, 1),
  311. valid: true,
  312. },
  313. CALLDATASIZE: {
  314. execute: opCallDataSize,
  315. gasCost: constGasFunc(GasQuickStep),
  316. validateStack: makeStackFunc(0, 1),
  317. valid: true,
  318. },
  319. CALLDATACOPY: {
  320. execute: opCallDataCopy,
  321. gasCost: gasCallDataCopy,
  322. validateStack: makeStackFunc(3, 0),
  323. memorySize: memoryCallDataCopy,
  324. valid: true,
  325. },
  326. CODESIZE: {
  327. execute: opCodeSize,
  328. gasCost: constGasFunc(GasQuickStep),
  329. validateStack: makeStackFunc(0, 1),
  330. valid: true,
  331. },
  332. CODECOPY: {
  333. execute: opCodeCopy,
  334. gasCost: gasCodeCopy,
  335. validateStack: makeStackFunc(3, 0),
  336. memorySize: memoryCodeCopy,
  337. valid: true,
  338. },
  339. GASPRICE: {
  340. execute: opGasprice,
  341. gasCost: constGasFunc(GasQuickStep),
  342. validateStack: makeStackFunc(0, 1),
  343. valid: true,
  344. },
  345. EXTCODESIZE: {
  346. execute: opExtCodeSize,
  347. gasCost: gasExtCodeSize,
  348. validateStack: makeStackFunc(1, 1),
  349. valid: true,
  350. },
  351. EXTCODECOPY: {
  352. execute: opExtCodeCopy,
  353. gasCost: gasExtCodeCopy,
  354. validateStack: makeStackFunc(4, 0),
  355. memorySize: memoryExtCodeCopy,
  356. valid: true,
  357. },
  358. BLOCKHASH: {
  359. execute: opBlockhash,
  360. gasCost: constGasFunc(GasExtStep),
  361. validateStack: makeStackFunc(1, 1),
  362. valid: true,
  363. },
  364. COINBASE: {
  365. execute: opCoinbase,
  366. gasCost: constGasFunc(GasQuickStep),
  367. validateStack: makeStackFunc(0, 1),
  368. valid: true,
  369. },
  370. TIMESTAMP: {
  371. execute: opTimestamp,
  372. gasCost: constGasFunc(GasQuickStep),
  373. validateStack: makeStackFunc(0, 1),
  374. valid: true,
  375. },
  376. NUMBER: {
  377. execute: opNumber,
  378. gasCost: constGasFunc(GasQuickStep),
  379. validateStack: makeStackFunc(0, 1),
  380. valid: true,
  381. },
  382. DIFFICULTY: {
  383. execute: opDifficulty,
  384. gasCost: constGasFunc(GasQuickStep),
  385. validateStack: makeStackFunc(0, 1),
  386. valid: true,
  387. },
  388. GASLIMIT: {
  389. execute: opGasLimit,
  390. gasCost: constGasFunc(GasQuickStep),
  391. validateStack: makeStackFunc(0, 1),
  392. valid: true,
  393. },
  394. POP: {
  395. execute: opPop,
  396. gasCost: constGasFunc(GasQuickStep),
  397. validateStack: makeStackFunc(1, 0),
  398. valid: true,
  399. },
  400. MLOAD: {
  401. execute: opMload,
  402. gasCost: gasMLoad,
  403. validateStack: makeStackFunc(1, 1),
  404. memorySize: memoryMLoad,
  405. valid: true,
  406. },
  407. MSTORE: {
  408. execute: opMstore,
  409. gasCost: gasMStore,
  410. validateStack: makeStackFunc(2, 0),
  411. memorySize: memoryMStore,
  412. valid: true,
  413. },
  414. MSTORE8: {
  415. execute: opMstore8,
  416. gasCost: gasMStore8,
  417. memorySize: memoryMStore8,
  418. validateStack: makeStackFunc(2, 0),
  419. valid: true,
  420. },
  421. SLOAD: {
  422. execute: opSload,
  423. gasCost: gasSLoad,
  424. validateStack: makeStackFunc(1, 1),
  425. valid: true,
  426. },
  427. SSTORE: {
  428. execute: opSstore,
  429. gasCost: gasSStore,
  430. validateStack: makeStackFunc(2, 0),
  431. valid: true,
  432. writes: true,
  433. },
  434. JUMP: {
  435. execute: opJump,
  436. gasCost: constGasFunc(GasMidStep),
  437. validateStack: makeStackFunc(1, 0),
  438. jumps: true,
  439. valid: true,
  440. },
  441. JUMPI: {
  442. execute: opJumpi,
  443. gasCost: constGasFunc(GasSlowStep),
  444. validateStack: makeStackFunc(2, 0),
  445. jumps: true,
  446. valid: true,
  447. },
  448. PC: {
  449. execute: opPc,
  450. gasCost: constGasFunc(GasQuickStep),
  451. validateStack: makeStackFunc(0, 1),
  452. valid: true,
  453. },
  454. MSIZE: {
  455. execute: opMsize,
  456. gasCost: constGasFunc(GasQuickStep),
  457. validateStack: makeStackFunc(0, 1),
  458. valid: true,
  459. },
  460. GAS: {
  461. execute: opGas,
  462. gasCost: constGasFunc(GasQuickStep),
  463. validateStack: makeStackFunc(0, 1),
  464. valid: true,
  465. },
  466. JUMPDEST: {
  467. execute: opJumpdest,
  468. gasCost: constGasFunc(params.JumpdestGas),
  469. validateStack: makeStackFunc(0, 0),
  470. valid: true,
  471. },
  472. PUSH1: {
  473. execute: makePush(1, 1),
  474. gasCost: gasPush,
  475. validateStack: makeStackFunc(0, 1),
  476. valid: true,
  477. },
  478. PUSH2: {
  479. execute: makePush(2, 2),
  480. gasCost: gasPush,
  481. validateStack: makeStackFunc(0, 1),
  482. valid: true,
  483. },
  484. PUSH3: {
  485. execute: makePush(3, 3),
  486. gasCost: gasPush,
  487. validateStack: makeStackFunc(0, 1),
  488. valid: true,
  489. },
  490. PUSH4: {
  491. execute: makePush(4, 4),
  492. gasCost: gasPush,
  493. validateStack: makeStackFunc(0, 1),
  494. valid: true,
  495. },
  496. PUSH5: {
  497. execute: makePush(5, 5),
  498. gasCost: gasPush,
  499. validateStack: makeStackFunc(0, 1),
  500. valid: true,
  501. },
  502. PUSH6: {
  503. execute: makePush(6, 6),
  504. gasCost: gasPush,
  505. validateStack: makeStackFunc(0, 1),
  506. valid: true,
  507. },
  508. PUSH7: {
  509. execute: makePush(7, 7),
  510. gasCost: gasPush,
  511. validateStack: makeStackFunc(0, 1),
  512. valid: true,
  513. },
  514. PUSH8: {
  515. execute: makePush(8, 8),
  516. gasCost: gasPush,
  517. validateStack: makeStackFunc(0, 1),
  518. valid: true,
  519. },
  520. PUSH9: {
  521. execute: makePush(9, 9),
  522. gasCost: gasPush,
  523. validateStack: makeStackFunc(0, 1),
  524. valid: true,
  525. },
  526. PUSH10: {
  527. execute: makePush(10, 10),
  528. gasCost: gasPush,
  529. validateStack: makeStackFunc(0, 1),
  530. valid: true,
  531. },
  532. PUSH11: {
  533. execute: makePush(11, 11),
  534. gasCost: gasPush,
  535. validateStack: makeStackFunc(0, 1),
  536. valid: true,
  537. },
  538. PUSH12: {
  539. execute: makePush(12, 12),
  540. gasCost: gasPush,
  541. validateStack: makeStackFunc(0, 1),
  542. valid: true,
  543. },
  544. PUSH13: {
  545. execute: makePush(13, 13),
  546. gasCost: gasPush,
  547. validateStack: makeStackFunc(0, 1),
  548. valid: true,
  549. },
  550. PUSH14: {
  551. execute: makePush(14, 14),
  552. gasCost: gasPush,
  553. validateStack: makeStackFunc(0, 1),
  554. valid: true,
  555. },
  556. PUSH15: {
  557. execute: makePush(15, 15),
  558. gasCost: gasPush,
  559. validateStack: makeStackFunc(0, 1),
  560. valid: true,
  561. },
  562. PUSH16: {
  563. execute: makePush(16, 16),
  564. gasCost: gasPush,
  565. validateStack: makeStackFunc(0, 1),
  566. valid: true,
  567. },
  568. PUSH17: {
  569. execute: makePush(17, 17),
  570. gasCost: gasPush,
  571. validateStack: makeStackFunc(0, 1),
  572. valid: true,
  573. },
  574. PUSH18: {
  575. execute: makePush(18, 18),
  576. gasCost: gasPush,
  577. validateStack: makeStackFunc(0, 1),
  578. valid: true,
  579. },
  580. PUSH19: {
  581. execute: makePush(19, 19),
  582. gasCost: gasPush,
  583. validateStack: makeStackFunc(0, 1),
  584. valid: true,
  585. },
  586. PUSH20: {
  587. execute: makePush(20, 20),
  588. gasCost: gasPush,
  589. validateStack: makeStackFunc(0, 1),
  590. valid: true,
  591. },
  592. PUSH21: {
  593. execute: makePush(21, 21),
  594. gasCost: gasPush,
  595. validateStack: makeStackFunc(0, 1),
  596. valid: true,
  597. },
  598. PUSH22: {
  599. execute: makePush(22, 22),
  600. gasCost: gasPush,
  601. validateStack: makeStackFunc(0, 1),
  602. valid: true,
  603. },
  604. PUSH23: {
  605. execute: makePush(23, 23),
  606. gasCost: gasPush,
  607. validateStack: makeStackFunc(0, 1),
  608. valid: true,
  609. },
  610. PUSH24: {
  611. execute: makePush(24, 24),
  612. gasCost: gasPush,
  613. validateStack: makeStackFunc(0, 1),
  614. valid: true,
  615. },
  616. PUSH25: {
  617. execute: makePush(25, 25),
  618. gasCost: gasPush,
  619. validateStack: makeStackFunc(0, 1),
  620. valid: true,
  621. },
  622. PUSH26: {
  623. execute: makePush(26, 26),
  624. gasCost: gasPush,
  625. validateStack: makeStackFunc(0, 1),
  626. valid: true,
  627. },
  628. PUSH27: {
  629. execute: makePush(27, 27),
  630. gasCost: gasPush,
  631. validateStack: makeStackFunc(0, 1),
  632. valid: true,
  633. },
  634. PUSH28: {
  635. execute: makePush(28, 28),
  636. gasCost: gasPush,
  637. validateStack: makeStackFunc(0, 1),
  638. valid: true,
  639. },
  640. PUSH29: {
  641. execute: makePush(29, 29),
  642. gasCost: gasPush,
  643. validateStack: makeStackFunc(0, 1),
  644. valid: true,
  645. },
  646. PUSH30: {
  647. execute: makePush(30, 30),
  648. gasCost: gasPush,
  649. validateStack: makeStackFunc(0, 1),
  650. valid: true,
  651. },
  652. PUSH31: {
  653. execute: makePush(31, 31),
  654. gasCost: gasPush,
  655. validateStack: makeStackFunc(0, 1),
  656. valid: true,
  657. },
  658. PUSH32: {
  659. execute: makePush(32, 32),
  660. gasCost: gasPush,
  661. validateStack: makeStackFunc(0, 1),
  662. valid: true,
  663. },
  664. DUP1: {
  665. execute: makeDup(1),
  666. gasCost: gasDup,
  667. validateStack: makeDupStackFunc(1),
  668. valid: true,
  669. },
  670. DUP2: {
  671. execute: makeDup(2),
  672. gasCost: gasDup,
  673. validateStack: makeDupStackFunc(2),
  674. valid: true,
  675. },
  676. DUP3: {
  677. execute: makeDup(3),
  678. gasCost: gasDup,
  679. validateStack: makeDupStackFunc(3),
  680. valid: true,
  681. },
  682. DUP4: {
  683. execute: makeDup(4),
  684. gasCost: gasDup,
  685. validateStack: makeDupStackFunc(4),
  686. valid: true,
  687. },
  688. DUP5: {
  689. execute: makeDup(5),
  690. gasCost: gasDup,
  691. validateStack: makeDupStackFunc(5),
  692. valid: true,
  693. },
  694. DUP6: {
  695. execute: makeDup(6),
  696. gasCost: gasDup,
  697. validateStack: makeDupStackFunc(6),
  698. valid: true,
  699. },
  700. DUP7: {
  701. execute: makeDup(7),
  702. gasCost: gasDup,
  703. validateStack: makeDupStackFunc(7),
  704. valid: true,
  705. },
  706. DUP8: {
  707. execute: makeDup(8),
  708. gasCost: gasDup,
  709. validateStack: makeDupStackFunc(8),
  710. valid: true,
  711. },
  712. DUP9: {
  713. execute: makeDup(9),
  714. gasCost: gasDup,
  715. validateStack: makeDupStackFunc(9),
  716. valid: true,
  717. },
  718. DUP10: {
  719. execute: makeDup(10),
  720. gasCost: gasDup,
  721. validateStack: makeDupStackFunc(10),
  722. valid: true,
  723. },
  724. DUP11: {
  725. execute: makeDup(11),
  726. gasCost: gasDup,
  727. validateStack: makeDupStackFunc(11),
  728. valid: true,
  729. },
  730. DUP12: {
  731. execute: makeDup(12),
  732. gasCost: gasDup,
  733. validateStack: makeDupStackFunc(12),
  734. valid: true,
  735. },
  736. DUP13: {
  737. execute: makeDup(13),
  738. gasCost: gasDup,
  739. validateStack: makeDupStackFunc(13),
  740. valid: true,
  741. },
  742. DUP14: {
  743. execute: makeDup(14),
  744. gasCost: gasDup,
  745. validateStack: makeDupStackFunc(14),
  746. valid: true,
  747. },
  748. DUP15: {
  749. execute: makeDup(15),
  750. gasCost: gasDup,
  751. validateStack: makeDupStackFunc(15),
  752. valid: true,
  753. },
  754. DUP16: {
  755. execute: makeDup(16),
  756. gasCost: gasDup,
  757. validateStack: makeDupStackFunc(16),
  758. valid: true,
  759. },
  760. SWAP1: {
  761. execute: makeSwap(1),
  762. gasCost: gasSwap,
  763. validateStack: makeSwapStackFunc(2),
  764. valid: true,
  765. },
  766. SWAP2: {
  767. execute: makeSwap(2),
  768. gasCost: gasSwap,
  769. validateStack: makeSwapStackFunc(3),
  770. valid: true,
  771. },
  772. SWAP3: {
  773. execute: makeSwap(3),
  774. gasCost: gasSwap,
  775. validateStack: makeSwapStackFunc(4),
  776. valid: true,
  777. },
  778. SWAP4: {
  779. execute: makeSwap(4),
  780. gasCost: gasSwap,
  781. validateStack: makeSwapStackFunc(5),
  782. valid: true,
  783. },
  784. SWAP5: {
  785. execute: makeSwap(5),
  786. gasCost: gasSwap,
  787. validateStack: makeSwapStackFunc(6),
  788. valid: true,
  789. },
  790. SWAP6: {
  791. execute: makeSwap(6),
  792. gasCost: gasSwap,
  793. validateStack: makeSwapStackFunc(7),
  794. valid: true,
  795. },
  796. SWAP7: {
  797. execute: makeSwap(7),
  798. gasCost: gasSwap,
  799. validateStack: makeSwapStackFunc(8),
  800. valid: true,
  801. },
  802. SWAP8: {
  803. execute: makeSwap(8),
  804. gasCost: gasSwap,
  805. validateStack: makeSwapStackFunc(9),
  806. valid: true,
  807. },
  808. SWAP9: {
  809. execute: makeSwap(9),
  810. gasCost: gasSwap,
  811. validateStack: makeSwapStackFunc(10),
  812. valid: true,
  813. },
  814. SWAP10: {
  815. execute: makeSwap(10),
  816. gasCost: gasSwap,
  817. validateStack: makeSwapStackFunc(11),
  818. valid: true,
  819. },
  820. SWAP11: {
  821. execute: makeSwap(11),
  822. gasCost: gasSwap,
  823. validateStack: makeSwapStackFunc(12),
  824. valid: true,
  825. },
  826. SWAP12: {
  827. execute: makeSwap(12),
  828. gasCost: gasSwap,
  829. validateStack: makeSwapStackFunc(13),
  830. valid: true,
  831. },
  832. SWAP13: {
  833. execute: makeSwap(13),
  834. gasCost: gasSwap,
  835. validateStack: makeSwapStackFunc(14),
  836. valid: true,
  837. },
  838. SWAP14: {
  839. execute: makeSwap(14),
  840. gasCost: gasSwap,
  841. validateStack: makeSwapStackFunc(15),
  842. valid: true,
  843. },
  844. SWAP15: {
  845. execute: makeSwap(15),
  846. gasCost: gasSwap,
  847. validateStack: makeSwapStackFunc(16),
  848. valid: true,
  849. },
  850. SWAP16: {
  851. execute: makeSwap(16),
  852. gasCost: gasSwap,
  853. validateStack: makeSwapStackFunc(17),
  854. valid: true,
  855. },
  856. LOG0: {
  857. execute: makeLog(0),
  858. gasCost: makeGasLog(0),
  859. validateStack: makeStackFunc(2, 0),
  860. memorySize: memoryLog,
  861. valid: true,
  862. writes: true,
  863. },
  864. LOG1: {
  865. execute: makeLog(1),
  866. gasCost: makeGasLog(1),
  867. validateStack: makeStackFunc(3, 0),
  868. memorySize: memoryLog,
  869. valid: true,
  870. writes: true,
  871. },
  872. LOG2: {
  873. execute: makeLog(2),
  874. gasCost: makeGasLog(2),
  875. validateStack: makeStackFunc(4, 0),
  876. memorySize: memoryLog,
  877. valid: true,
  878. writes: true,
  879. },
  880. LOG3: {
  881. execute: makeLog(3),
  882. gasCost: makeGasLog(3),
  883. validateStack: makeStackFunc(5, 0),
  884. memorySize: memoryLog,
  885. valid: true,
  886. writes: true,
  887. },
  888. LOG4: {
  889. execute: makeLog(4),
  890. gasCost: makeGasLog(4),
  891. validateStack: makeStackFunc(6, 0),
  892. memorySize: memoryLog,
  893. valid: true,
  894. writes: true,
  895. },
  896. CREATE: {
  897. execute: opCreate,
  898. gasCost: gasCreate,
  899. validateStack: makeStackFunc(3, 1),
  900. memorySize: memoryCreate,
  901. valid: true,
  902. writes: true,
  903. returns: true,
  904. },
  905. CALL: {
  906. execute: opCall,
  907. gasCost: gasCall,
  908. validateStack: makeStackFunc(7, 1),
  909. memorySize: memoryCall,
  910. valid: true,
  911. returns: true,
  912. },
  913. CALLCODE: {
  914. execute: opCallCode,
  915. gasCost: gasCallCode,
  916. validateStack: makeStackFunc(7, 1),
  917. memorySize: memoryCall,
  918. valid: true,
  919. returns: true,
  920. },
  921. RETURN: {
  922. execute: opReturn,
  923. gasCost: gasReturn,
  924. validateStack: makeStackFunc(2, 0),
  925. memorySize: memoryReturn,
  926. halts: true,
  927. valid: true,
  928. },
  929. SELFDESTRUCT: {
  930. execute: opSuicide,
  931. gasCost: gasSuicide,
  932. validateStack: makeStackFunc(1, 0),
  933. halts: true,
  934. valid: true,
  935. writes: true,
  936. },
  937. }
  938. }