From 882b0d013f6800a3f44d50f9b05562e4f958b3b4 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 14 Aug 2018 12:47:53 +0300 Subject: [PATCH 1/3] eip160 change byte cost for exp op --- README.md | 6 +- .../scripts/generate_blockchain_tests.ex | 9 +- .../scripts/generate_state_tests.ex | 13 +- .../blockchain/test/blockchain/state_test.exs | 187 ++++++++++++++++ apps/blockchain/test/blockchain_test.exs | 211 +++++++++++++++++- apps/evm/lib/evm/configuration.ex | 4 + apps/evm/lib/evm/configuration/eip150.ex | 25 ++- apps/evm/lib/evm/configuration/frontier.ex | 28 ++- apps/evm/lib/evm/configuration/homestead.ex | 25 ++- apps/evm/lib/evm/gas.ex | 6 +- 10 files changed, 472 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 2773194c8..58b78b678 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,10 @@ Ethereum common tests are created for all clients to test against. We plan to pr - [GeneralStateTests](https://github.com/ethereum/tests/tree/develop/GeneralStateTests) 2024/2062 = 98.2% passing - [x] EIP150 - [BlockchainTests](https://github.com/ethereum/tests/tree/develop/BlockchainTests) (Includes GeneralStateTests) 1274/1275 = 99.9% passing - - [GeneralStateTests](https://github.com/ethereum/tests/tree/develop/GeneralStateTests) 1088/1114= 97.7% passing -- [ ] EIP158 + - [GeneralStateTests](https://github.com/ethereum/tests/tree/develop/GeneralStateTests) 1088/1114 = 97.7% passing +- [x] EIP158 + - [BlockchainTests](https://github.com/ethereum/tests/tree/develop/BlockchainTests) (Includes GeneralStateTests) 1031/1233 = 83.6% + - [GeneralStateTests](https://github.com/ethereum/tests/tree/develop/GeneralStateTests) 859/1181 = 72.7% passing - [ ] Byzantium - [ ] Constantinople: View the community [Constantinople Project Tracker](https://github.com/ethereum/pm/issues/53). diff --git a/apps/blockchain/scripts/generate_blockchain_tests.ex b/apps/blockchain/scripts/generate_blockchain_tests.ex index d99a200b6..280090d2b 100644 --- a/apps/blockchain/scripts/generate_blockchain_tests.ex +++ b/apps/blockchain/scripts/generate_blockchain_tests.ex @@ -11,7 +11,8 @@ defmodule GenerateBlockchainTests do def run(args) do hardfork = List.first(args) - if !Enum.member?(["Frontier", "Homestead", "EIP150"], hardfork), do: raise(RuntimeError) + if !Enum.member?(["Frontier", "Homestead", "EIP150", "EIP158"], hardfork), + do: raise(RuntimeError) {passing_count, failing_count} = Enum.reduce( @@ -105,6 +106,9 @@ defmodule GenerateBlockchainTests do "EIP150" -> Chain.load_chain(:eip150_test, config) + "EIP158" -> + Chain.load_chain(:eip150_test, config) + _ -> nil end @@ -121,6 +125,9 @@ defmodule GenerateBlockchainTests do "EIP150" -> EVM.Configuration.EIP150.new() + "EIP158" -> + EVM.Configuration.EIP158.new() + _ -> nil end diff --git a/apps/blockchain/scripts/generate_state_tests.ex b/apps/blockchain/scripts/generate_state_tests.ex index 7b2247e16..5dc6dd1bf 100644 --- a/apps/blockchain/scripts/generate_state_tests.ex +++ b/apps/blockchain/scripts/generate_state_tests.ex @@ -7,17 +7,21 @@ defmodule GenerateStateTests do use EthCommonTest.Harness + @hardforks ["EIP158", "EIP150", "Homestead", "Frontier"] + def run(_args) do initial_state = %{ passing: %{ "Homestead" => [], "Frontier" => [], - "EIP150" => [] + "EIP150" => [], + "EIP158" => [] }, failing: %{ "Homestead" => [], "Frontier" => [], - "EIP150" => [] + "EIP150" => [], + "EIP158" => [] } } @@ -46,7 +50,7 @@ defmodule GenerateStateTests do IO.puts("Failing tests") IO.puts(inspect(failing_tests, limit: :infinity)) - for hardfork <- ["EIP150", "Homestead", "Frontier"] do + for hardfork <- @hardforks do passing_tests = length(completed_tests[:passing][hardfork]) failing_tests = length(completed_tests[:failing][hardfork]) total_tests = passing_tests + failing_tests @@ -172,6 +176,9 @@ defmodule GenerateStateTests do "EIP150" -> EVM.Configuration.EIP150.new() + "EIP158" -> + EVM.Configuration.EIP158.new() + _ -> nil end diff --git a/apps/blockchain/test/blockchain/state_test.exs b/apps/blockchain/test/blockchain/state_test.exs index 06147a5a1..6262a0bfc 100644 --- a/apps/blockchain/test/blockchain/state_test.exs +++ b/apps/blockchain/test/blockchain/state_test.exs @@ -31,6 +31,190 @@ defmodule Blockchain.StateTest do "stInitCodeTest/OutOfGasContractCreation", "stInitCodeTest/NotEnoughCashContractCreation" ], + "EIP158" => [ + "stZeroCallsTest/ZeroValue_TransactionCALLwithData_ToOneStorageKey", + "stZeroCallsTest/ZeroValue_TransactionCALLwithData_ToEmpty", + "stZeroCallsTest/ZeroValue_TransactionCALLwithData", + "stZeroCallsTest/ZeroValue_TransactionCALL_ToOneStorageKey", + "stZeroCallsTest/ZeroValue_TransactionCALL_ToEmpty", + "stZeroCallsTest/ZeroValue_TransactionCALL", + "stZeroCallsTest/ZeroValue_SUICIDE_ToOneStorageKey", + "stZeroCallsTest/ZeroValue_SUICIDE_ToNonZeroBalance", + "stZeroCallsTest/ZeroValue_SUICIDE_ToEmpty", + "stZeroCallsTest/ZeroValue_SUICIDE", + "stZeroCallsTest/ZeroValue_CALL_ToOneStorageKey", + "stZeroCallsTest/ZeroValue_CALL_ToEmpty", + "stZeroCallsTest/ZeroValue_CALL", + "stWalletTest/walletConstructionPartial", + "stWalletTest/walletConstructionOOG", + "stWalletTest/walletConstruction", + "stWalletTest/multiOwnedConstructionCorrect", + "stWalletTest/dayLimitConstructionPartial", + "stWalletTest/dayLimitConstruction", + "stTransitionTest/createNameRegistratorPerTxsBefore", + "stTransitionTest/createNameRegistratorPerTxsAt", + "stTransitionTest/createNameRegistratorPerTxsAfter", + "stTransactionTest/UserTransactionZeroCostWithData", + "stTransactionTest/UserTransactionZeroCost", + "stTransactionTest/TransactionSendingToEmpty", + "stTransactionTest/TransactionDataCosts652", + "stTransactionTest/SuicidesStopAfterSuicide", + "stTransactionTest/SuicidesMixingCoinbase", + "stTransactionTest/SuicidesAndSendMoneyToItselfEtherDestroyed", + "stTransactionTest/SuicidesAndInternlCallSuicidesSuccess", + "stTransactionTest/SuicidesAndInternlCallSuicidesOOG", + "stTransactionTest/SuicidesAndInternlCallSuicidesBonusGasAtCallFailed", + "stTransactionTest/SuicidesAndInternlCallSuicidesBonusGasAtCall", + "stTransactionTest/StoreGasOnCreate", + "stTransactionTest/OverflowGasRequire2", + "stTransactionTest/Opcodes_TransactionInit", + "stTransactionTest/EmptyTransaction3", + "stTransactionTest/EmptyTransaction2", + "stTransactionTest/CreateTransactionSuccess", + "stTransactionTest/CreateMessageSuccess", + "stSystemOperationsTest/testRandomTest", + "stSystemOperationsTest/suicideSendEtherToMe", + "stSystemOperationsTest/suicideSendEtherPostDeath", + "stSystemOperationsTest/suicideOrigin", + "stSystemOperationsTest/suicideNotExistingAccount", + "stSystemOperationsTest/suicideCoinbase", + "stSystemOperationsTest/suicideCallerAddresTooBigRight", + "stSystemOperationsTest/suicideCallerAddresTooBigLeft", + "stSystemOperationsTest/suicideCaller", + "stSystemOperationsTest/suicideAddress", + "stSystemOperationsTest/extcodecopy", + "stSystemOperationsTest/doubleSelfdestructTest2", + "stSystemOperationsTest/doubleSelfdestructTest", + "stSystemOperationsTest/createNameRegistratorZeroMemExpansion", + "stSystemOperationsTest/createNameRegistratorZeroMem2", + "stSystemOperationsTest/createNameRegistratorZeroMem", + "stSystemOperationsTest/createNameRegistrator", + "stSystemOperationsTest/CreateHashCollision", + "stSystemOperationsTest/ABAcallsSuicide1", + "stSystemOperationsTest/ABAcallsSuicide0", + "stSpecialTest/tx_e1c174e2", + "stSpecialTest/failed_tx_xcf416c53", + "stSpecialTest/deploymentError", + "stSpecialTest/StackDepthLimitSEC", + "stSolidityTest/RecursiveCreateContractsCreate4Contracts", + "stSolidityTest/RecursiveCreateContracts", + "stSolidityTest/CreateContractFromMethod", + "stRevertTest/TouchToEmptyAccountRevert3", + "stRevertTest/RevertRemoteSubCallStorageOOG2", + "stRevertTest/RevertRemoteSubCallStorageOOG", + "stRevertTest/RevertPrefoundEmptyCall", + "stRevertTest/RevertPrefoundEmpty", + "stRevertTest/RevertPrefound", + "stRevertTest/RevertOpcodeMultipleSubCalls", + "stRevertTest/RevertDepthCreateOOG", + "stRevertTest/NashatyrevSuicideRevert", + "stRevertTest/LoopCallsDepthThenRevert3", + "stRevertTest/LoopCallsDepthThenRevert2", + "stRefundTest/refund_singleSuicide", + "stRefundTest/refund_multimpleSuicide", + "stRefundTest/refund_TxToSuicide", + "stRefundTest/refund_CallToSuicideTwice", + "stRefundTest/refund_CallToSuicideStorage", + "stRefundTest/refund_CallToSuicideNoStorage", + "stRefundTest/refundSuicide50procentCap", + "stRecursiveCreate/recursiveCreateReturnValue", + "stRecursiveCreate/recursiveCreate", + "stQuadraticComplexityTest/Create1000Byzantium", + "stQuadraticComplexityTest/Create1000", + "stPreCompiledContracts2/CallSha256_5", + "stPreCompiledContracts2/CallSha256_4_gas99", + "stPreCompiledContracts2/CallSha256_4", + "stPreCompiledContracts2/CallSha256_3_prefix0", + "stPreCompiledContracts2/CallSha256_3_postfix0", + "stPreCompiledContracts2/CallSha256_3", + "stPreCompiledContracts2/CallSha256_2", + "stPreCompiledContracts2/CallSha256_1", + "stPreCompiledContracts2/CallSha256_0", + "stPreCompiledContracts2/CallRipemd160_5", + "stPreCompiledContracts2/CallRipemd160_4_gas719", + "stPreCompiledContracts2/CallRipemd160_4", + "stPreCompiledContracts2/CallRipemd160_3_prefixed0", + "stPreCompiledContracts2/CallRipemd160_3_postfixed0", + "stPreCompiledContracts2/CallRipemd160_3", + "stPreCompiledContracts2/CallRipemd160_2", + "stPreCompiledContracts2/CallRipemd160_1", + "stPreCompiledContracts2/CallRipemd160_0", + "stPreCompiledContracts2/CallIdentity_5", + "stPreCompiledContracts2/CallIdentity_4_gas18", + "stPreCompiledContracts2/CallIdentity_4_gas17", + "stPreCompiledContracts2/CallIdentity_4", + "stPreCompiledContracts2/CallIdentity_3", + "stPreCompiledContracts2/CallIdentity_2", + "stPreCompiledContracts2/CallIdentitiy_1", + "stPreCompiledContracts2/CallIdentitiy_0", + "stPreCompiledContracts2/CallEcrecoverV_prefixed0", + "stPreCompiledContracts2/CallEcrecoverS_prefixed0", + "stPreCompiledContracts2/CallEcrecoverR_prefixed0", + "stPreCompiledContracts2/CallEcrecoverH_prefixed0", + "stPreCompiledContracts2/CallEcrecoverCheckLengthWrongV", + "stPreCompiledContracts2/CallEcrecoverCheckLength", + "stPreCompiledContracts2/CallEcrecover80", + "stPreCompiledContracts2/CallEcrecover3", + "stPreCompiledContracts2/CallEcrecover2", + "stPreCompiledContracts2/CallEcrecover1", + "stPreCompiledContracts2/CallEcrecover0_overlappingInputOutput", + "stPreCompiledContracts2/CallEcrecover0_gas3000", + "stPreCompiledContracts2/CallEcrecover0_completeReturnValue", + "stPreCompiledContracts2/CallEcrecover0_Gas2999", + "stPreCompiledContracts2/CallEcrecover0_0input", + "stPreCompiledContracts2/CallEcrecover0", + "stNonZeroCallsTest/NonZeroValue_SUICIDE_ToOneStorageKey", + "stNonZeroCallsTest/NonZeroValue_SUICIDE_ToNonNonZeroBalance", + "stNonZeroCallsTest/NonZeroValue_SUICIDE_ToEmpty", + "stNonZeroCallsTest/NonZeroValue_SUICIDE", + "stNonZeroCallsTest/NonZeroValue_CALL_ToOneStorageKey", + "stNonZeroCallsTest/NonZeroValue_CALL_ToEmpty", + "stMemExpandingEIP150Calls/NewGasPriceForCodesWithMemExpandingCalls", + "stMemExpandingEIP150Calls/CreateAndGasInsideCreateWithMemExpandingCalls", + "stInitCodeTest/TransactionCreateStopInInitcode", + "stInitCodeTest/TransactionCreateAutoSuicideContract", + "stInitCodeTest/OutOfGasContractCreation", + "stInitCodeTest/CallTheContractToCreateEmptyContract", + "stInitCodeTest/CallRecursiveContract", + "stInitCodeTest/CallContractToCreateContractWhichWouldCreateContractInInitCode", + "stInitCodeTest/CallContractToCreateContractWhichWouldCreateContractIfCalled", + "stInitCodeTest/CallContractToCreateContractOOGBonusGas", + "stInitCodeTest/CallContractToCreateContractOOG", + "stInitCodeTest/CallContractToCreateContractAndCallItOOG", + "stEIP158Specific/vitalikTransactionTest", + "stEIP158Specific/CALL_ZeroVCallSuicide", + "stEIP158Specific/CALL_OneVCallSuicide", + "stDelegatecallTestHomestead/delegatecodeDynamicCode", + "stCreateTest/TransactionCollisionToEmpty", + "stCreateTest/CreateCollisionToEmpty", + "stCreateTest/CREATE_empty000CreateinInitCode_Transaction", + "stCreateTest/CREATE_EmptyContractWithStorageAndCallIt_1wei", + "stCreateTest/CREATE_EmptyContractWithStorageAndCallIt_0wei", + "stCreateTest/CREATE_EmptyContractWithStorage", + "stCreateTest/CREATE_EmptyContractWithBalance", + "stCreateTest/CREATE_EmptyContractAndCallIt_1wei", + "stCreateTest/CREATE_EmptyContractAndCallIt_0wei", + "stCreateTest/CREATE_EmptyContract", + "stCreateTest/CREATE_EContract_ThenCALLToNonExistentAcc", + "stCreateTest/CREATE_EContractCreateNEContractInInit_Tr", + "stCreateTest/CREATE_EContractCreateNEContractInInitOOG_Tr", + "stCreateTest/CREATE_EContractCreateEContractInInit_Tr", + "stCreateTest/CREATE_ContractSuicideDuringInit_WithValueToItself", + "stCreateTest/CREATE_ContractSuicideDuringInit_WithValue", + "stCreateTest/CREATE_ContractSuicideDuringInit_ThenStoreThenReturn", + "stCreateTest/CREATE_ContractSuicideDuringInit", + "stCreateTest/CREATE_ContractSSTOREDuringInit", + "stCreateTest/CREATE_AcreateB_BSuicide_BStore", + "stCodeSizeLimit/codesizeValid", + "stCodeSizeLimit/codesizeOOGInvalidSize", + "stCodeSizeLimit/codesizeInit", + "stCallCreateCallCodeTest/createNameRegistratorPerTxs", + "stCallCodes/callcodeDynamicCode", + "stCallCodes/call_OOG_additionalGasCosts1", + "stBadOpcode/badOpcodes", + "stAttackTest/CrashingTransaction", + "stAttackTest/ContractCreationSpam" + ], "Frontier" => [ "stTransactionTest/UserTransactionGasLimitIsTooLowWhenZeroCost", "stTransactionTest/TransactionToItselfNotEnoughFounds", @@ -184,6 +368,9 @@ defmodule Blockchain.StateTest do "EIP150" -> EVM.Configuration.EIP150.new() + "EIP158" -> + EVM.Configuration.EIP158.new() + _ -> nil end diff --git a/apps/blockchain/test/blockchain_test.exs b/apps/blockchain/test/blockchain_test.exs index fa0415546..b3e413a95 100644 --- a/apps/blockchain/test/blockchain_test.exs +++ b/apps/blockchain/test/blockchain_test.exs @@ -17,9 +17,212 @@ defmodule BlockchainTest do "EIP150" => [ "GeneralStateTests/stSystemOperationsTest/CreateHashCollision_d0g0v0.json" ], + "EIP158" => [ + "GeneralStateTests/stAttackTest/ContractCreationSpam_d0g0v0.json", + "GeneralStateTests/stAttackTest/CrashingTransaction_d0g0v0.json", + "GeneralStateTests/stBadOpcode/badOpcodes_d0g0v0.json", + "GeneralStateTests/stCallCodes/call_OOG_additionalGasCosts1_d0g0v0.json", + "GeneralStateTests/stCallCodes/callcodeDynamicCode_d0g0v0.json", + "GeneralStateTests/stCallCreateCallCodeTest/createNameRegistratorPerTxs_d0g0v0.json", + "GeneralStateTests/stCodeSizeLimit/codesizeOOGInvalidSize_d0g0v0.json", + "GeneralStateTests/stCodeSizeLimit/codesizeValid_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_AcreateB_BSuicide_BStore_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_ContractSSTOREDuringInit_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_ContractSuicideDuringInit_ThenStoreThenReturn_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_ContractSuicideDuringInit_WithValueToItself_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_ContractSuicideDuringInit_WithValue_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_ContractSuicideDuringInit_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EContractCreateEContractInInit_Tr_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EContractCreateNEContractInInitOOG_Tr_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EContractCreateNEContractInInit_Tr_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EContract_ThenCALLToNonExistentAcc_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractAndCallIt_0wei_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractAndCallIt_1wei_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractWithBalance_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractWithStorageAndCallIt_0wei_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractWithStorageAndCallIt_1wei_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContractWithStorage_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_EmptyContract_d0g0v0.json", + "GeneralStateTests/stCreateTest/CREATE_empty000CreateinInitCode_Transaction_d0g0v0.json", + "GeneralStateTests/stCreateTest/CreateCollisionToEmpty_d0g0v0.json", + "GeneralStateTests/stCreateTest/CreateCollisionToEmpty_d0g0v1.json", + "GeneralStateTests/stCreateTest/TransactionCollisionToEmpty_d0g0v0.json", + "GeneralStateTests/stCreateTest/TransactionCollisionToEmpty_d0g0v1.json", + "GeneralStateTests/stDelegatecallTestHomestead/delegatecodeDynamicCode_d0g0v0.json", + "GeneralStateTests/stEIP158Specific/CALL_OneVCallSuicide_d0g0v0.json", + "GeneralStateTests/stEIP158Specific/CALL_ZeroVCallSuicide_d0g0v0.json", + "GeneralStateTests/stEIP158Specific/vitalikTransactionTest_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallContractToCreateContractAndCallItOOG_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallContractToCreateContractOOGBonusGas_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallContractToCreateContractOOG_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallContractToCreateContractWhichWouldCreateContractIfCalled_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallContractToCreateContractWhichWouldCreateContractInInitCode_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallRecursiveContract_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/CallTheContractToCreateEmptyContract_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/TransactionCreateAutoSuicideContract_d0g0v0.json", + "GeneralStateTests/stInitCodeTest/TransactionCreateStopInInitcode_d0g0v0.json", + "GeneralStateTests/stMemExpandingEIP150Calls/CreateAndGasInsideCreateWithMemExpandingCalls_d0g0v0.json", + "GeneralStateTests/stMemExpandingEIP150Calls/NewGasPriceForCodesWithMemExpandingCalls_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_CALL_ToEmpty_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_CALL_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_SUICIDE_ToEmpty_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_SUICIDE_ToNonNonZeroBalance_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_SUICIDE_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stNonZeroCallsTest/NonZeroValue_SUICIDE_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_0input_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_Gas2999_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_completeReturnValue_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_gas3000_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover0_overlappingInputOutput_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover1_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover2_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover3_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecover80_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverCheckLengthWrongV_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverCheckLength_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverH_prefixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverR_prefixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverS_prefixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallEcrecoverV_prefixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentitiy_0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentitiy_1_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_2_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_3_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_4_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_4_gas17_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_4_gas18_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallIdentity_5_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_1_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_2_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_3_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_3_postfixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_3_prefixed0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_4_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_4_gas719_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallRipemd160_5_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_1_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_2_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_3_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_3_postfix0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_3_prefix0_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_4_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_4_gas99_d0g0v0.json", + "GeneralStateTests/stPreCompiledContracts2/CallSha256_5_d0g0v0.json", + "GeneralStateTests/stQuadraticComplexityTest/Create1000Byzantium_d0g1v0.json", + "GeneralStateTests/stQuadraticComplexityTest/Create1000_d0g1v0.json", + "GeneralStateTests/stRecursiveCreate/recursiveCreateReturnValue_d0g0v0.json", + "GeneralStateTests/stRecursiveCreate/recursiveCreate_d0g0v0.json", + "GeneralStateTests/stRefundTest/refundSuicide50procentCap_d1g0v0.json", + "GeneralStateTests/stRefundTest/refund_CallToSuicideNoStorage_d1g0v0.json", + "GeneralStateTests/stRefundTest/refund_CallToSuicideStorage_d1g0v0.json", + "GeneralStateTests/stRefundTest/refund_CallToSuicideTwice_d1g0v0.json", + "GeneralStateTests/stRefundTest/refund_TxToSuicide_d0g1v0.json", + "GeneralStateTests/stRefundTest/refund_multimpleSuicide_d0g0v0.json", + "GeneralStateTests/stRefundTest/refund_singleSuicide_d0g0v0.json", + "GeneralStateTests/stRevertTest/LoopCallsDepthThenRevert2_d0g0v0.json", + "GeneralStateTests/stRevertTest/LoopCallsDepthThenRevert3_d0g0v0.json", + "GeneralStateTests/stRevertTest/NashatyrevSuicideRevert_d0g0v0.json", + "GeneralStateTests/stRevertTest/RevertDepthCreateOOG_d1g1v0.json", + "GeneralStateTests/stRevertTest/RevertDepthCreateOOG_d1g1v1.json", + "GeneralStateTests/stRevertTest/RevertPrefoundEmptyCall_d0g0v0.json", + "GeneralStateTests/stRevertTest/RevertPrefoundEmpty_d0g0v0.json", + "GeneralStateTests/stRevertTest/RevertPrefound_d0g0v0.json", + "GeneralStateTests/stRevertTest/RevertRemoteSubCallStorageOOG2_d0g1v0.json", + "GeneralStateTests/stRevertTest/RevertRemoteSubCallStorageOOG_d0g1v0.json", + "GeneralStateTests/stRevertTest/TouchToEmptyAccountRevert3_d0g0v0.json", + "GeneralStateTests/stSolidityTest/CreateContractFromMethod_d0g0v0.json", + "GeneralStateTests/stSolidityTest/RecursiveCreateContractsCreate4Contracts_d0g0v0.json", + "GeneralStateTests/stSolidityTest/RecursiveCreateContracts_d0g0v0.json", + "GeneralStateTests/stSpecialTest/StackDepthLimitSEC_d0g0v0.json", + "GeneralStateTests/stSpecialTest/deploymentError_d0g0v0.json", + "GeneralStateTests/stSpecialTest/failed_tx_xcf416c53_d0g0v0.json", + "GeneralStateTests/stSpecialTest/tx_e1c174e2_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/ABAcallsSuicide0_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/ABAcallsSuicide1_d1g0v0.json", + "GeneralStateTests/stSystemOperationsTest/CreateHashCollision_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/createNameRegistratorZeroMem2_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/createNameRegistratorZeroMemExpansion_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/createNameRegistratorZeroMem_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/createNameRegistrator_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/doubleSelfdestructTest2_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/doubleSelfdestructTest_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/extcodecopy_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideAddress_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideCallerAddresTooBigLeft_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideCallerAddresTooBigRight_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideCaller_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideCoinbase_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideNotExistingAccount_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideOrigin_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideSendEtherPostDeath_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/suicideSendEtherToMe_d0g0v0.json", + "GeneralStateTests/stSystemOperationsTest/testRandomTest_d0g0v0.json", + "GeneralStateTests/stTransactionTest/CreateMessageSuccess_d0g0v0.json", + "GeneralStateTests/stTransactionTest/CreateTransactionSuccess_d0g0v0.json", + "GeneralStateTests/stTransactionTest/EmptyTransaction2_d0g0v0.json", + "GeneralStateTests/stTransactionTest/EmptyTransaction3_d0g0v0.json", + "GeneralStateTests/stTransactionTest/Opcodes_TransactionInit_d120g0v0.json", + "GeneralStateTests/stTransactionTest/Opcodes_TransactionInit_d124g0v0.json", + "GeneralStateTests/stTransactionTest/Opcodes_TransactionInit_d127g0v0.json", + "GeneralStateTests/stTransactionTest/OverflowGasRequire2_d0g0v0.json", + "GeneralStateTests/stTransactionTest/StoreGasOnCreate_d0g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesAndInternlCallSuicidesBonusGasAtCallFailed_d0g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesAndInternlCallSuicidesBonusGasAtCall_d0g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesAndInternlCallSuicidesOOG_d0g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesAndInternlCallSuicidesSuccess_d1g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesAndSendMoneyToItselfEtherDestroyed_d0g0v0.json", + "GeneralStateTests/stTransactionTest/SuicidesMixingCoinbase_d0g1v0.json", + "GeneralStateTests/stTransactionTest/SuicidesStopAfterSuicide_d0g0v0.json", + "GeneralStateTests/stTransactionTest/TransactionDataCosts652_d0g0v0.json", + "GeneralStateTests/stTransactionTest/TransactionSendingToEmpty_d0g0v0.json", + "GeneralStateTests/stTransitionTest/createNameRegistratorPerTxsAfter_d0g0v0.json", + "GeneralStateTests/stTransitionTest/createNameRegistratorPerTxsAt_d0g0v0.json", + "GeneralStateTests/stTransitionTest/createNameRegistratorPerTxsBefore_d0g0v0.json", + "GeneralStateTests/stWalletTest/dayLimitConstructionPartial_d0g0v0.json", + "GeneralStateTests/stWalletTest/dayLimitConstruction_d0g0v0.json", + "GeneralStateTests/stWalletTest/dayLimitConstruction_d0g1v0.json", + "GeneralStateTests/stWalletTest/multiOwnedConstructionCorrect_d0g0v0.json", + "GeneralStateTests/stWalletTest/walletConstructionOOG_d0g1v0.json", + "GeneralStateTests/stWalletTest/walletConstructionPartial_d0g0v0.json", + "GeneralStateTests/stWalletTest/walletConstruction_d0g0v0.json", + "GeneralStateTests/stWalletTest/walletConstruction_d0g1v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_CALL_ToEmpty_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_CALL_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_CALL_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_SUICIDE_ToEmpty_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_SUICIDE_ToNonZeroBalance_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_SUICIDE_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_SUICIDE_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALL_ToEmpty_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALL_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALL_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALLwithData_ToEmpty_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALLwithData_ToOneStorageKey_d0g0v0.json", + "GeneralStateTests/stZeroCallsTest/ZeroValue_TransactionCALLwithData_d0g0v0.json", + "bcBlockGasLimitTest/GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst.json", + "bcBlockGasLimitTest/SuicideTransaction.json", + "bcExploitTest/StrangeContractCreation.json", + "bcExploitTest/SuicideIssue.json", + "bcGasPricerTest/RPC_API_Test.json", + "bcMultiChainTest/CallContractFromNotBestBlock.json", + "bcRandomBlockhashTest/randomStatetest193BC.json", + "bcRandomBlockhashTest/randomStatetest344BC.json", + "bcStateTests/OOGStateCopyContainingDeletedContract.json", + "bcStateTests/simpleSuicide.json", + "bcStateTests/suicideCoinbase.json", + "bcTotalDifficultyTest/lotsOfLeafs.json", + "bcValidBlockTest/RecallSuicidedContract.json", + "bcValidBlockTest/RecallSuicidedContractInOneBlock.json", + "bcWalletTest/wallet2outOf3txs2.json", + "bcWalletTest/wallet2outOf3txsRevoke.json", + "bcWalletTest/wallet2outOf3txsRevokeAndConfirmAgain.json", + "bcWalletTest/walletReorganizeOwners.json" + ], # the rest are not implemented yet "Byzantium" => [], - "EIP158" => [], "Constantinople" => [], "EIP158ToByzantiumAt5" => [], "FrontierToHomesteadAt5" => [], @@ -88,6 +291,9 @@ defmodule BlockchainTest do "EIP150" -> Chain.load_chain(:eip150_test, config) + "EIP158" -> + Chain.load_chain(:eip150_test, config) + _ -> nil end @@ -104,6 +310,9 @@ defmodule BlockchainTest do "EIP150" -> EVM.Configuration.EIP150.new() + "EIP158" -> + EVM.Configuration.EIP158.new() + _ -> nil end diff --git a/apps/evm/lib/evm/configuration.ex b/apps/evm/lib/evm/configuration.ex index 9b92e6e5e..44a423823 100644 --- a/apps/evm/lib/evm/configuration.ex +++ b/apps/evm/lib/evm/configuration.ex @@ -44,4 +44,8 @@ defprotocol EVM.Configuration do # EIP150 @spec fail_nested_operation_lack_of_gas?(t) :: boolean() def fail_nested_operation_lack_of_gas?(t) + + # EIP160 + @spec exp_byte_cost(t) :: integer() + def exp_byte_cost(t) end diff --git a/apps/evm/lib/evm/configuration/eip150.ex b/apps/evm/lib/evm/configuration/eip150.ex index 50f9fe7a6..56e73a4e5 100644 --- a/apps/evm/lib/evm/configuration/eip150.ex +++ b/apps/evm/lib/evm/configuration/eip150.ex @@ -15,38 +15,43 @@ defmodule EVM.Configuration.EIP150 do end defimpl EVM.Configuration, for: EVM.Configuration.EIP150 do - @spec contract_creation_cost(EVM.Configuration.t()) :: integer() + alias EVM.Configuration + + @spec contract_creation_cost(Configuration.t()) :: integer() def contract_creation_cost(config), do: config.fallback_config.contract_creation_cost - @spec has_delegate_call?(EVM.Configuration.t()) :: boolean() + @spec has_delegate_call?(Configuration.t()) :: boolean() def has_delegate_call?(config), do: config.fallback_config.has_delegate_call - @spec fail_contract_creation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_contract_creation_lack_of_gas?(Configuration.t()) :: boolean() def fail_contract_creation_lack_of_gas?(config), do: config.fallback_config.fail_contract_creation - @spec extcodesize_cost(EVM.Configuration.t()) :: integer() + @spec extcodesize_cost(Configuration.t()) :: integer() def extcodesize_cost(config), do: config.extcodesize_cost - @spec extcodecopy_cost(EVM.Configuration.t()) :: integer() + @spec extcodecopy_cost(Configuration.t()) :: integer() def extcodecopy_cost(config), do: config.extcodecopy_cost - @spec balance_cost(EVM.Configuration.t()) :: integer() + @spec balance_cost(Configuration.t()) :: integer() def balance_cost(config), do: config.balance_cost - @spec sload_cost(EVM.Configuration.t()) :: integer() + @spec sload_cost(Configuration.t()) :: integer() def sload_cost(config), do: config.sload_cost - @spec call_cost(EVM.Configuration.t()) :: integer() + @spec call_cost(Configuration.t()) :: integer() def call_cost(config), do: config.call_cost - @spec selfdestruct_cost(EVM.Configuration.t(), keyword()) :: integer() + @spec selfdestruct_cost(Configuration.t(), keyword()) :: integer() def selfdestruct_cost(config, new_account: false), do: config.selfdestruct_cost def selfdestruct_cost(config, new_account: true) do config.selfdestruct_cost + config.new_account_destruction_cost end - @spec fail_nested_operation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_nested_operation_lack_of_gas?(Configuration.t()) :: boolean() def fail_nested_operation_lack_of_gas?(config), do: config.fail_nested_operation + + @spec exp_byte_cost(Configuration.t()) :: integer() + def exp_byte_cost(config), do: Configuration.exp_byte_cost(config.fallback_config) end diff --git a/apps/evm/lib/evm/configuration/frontier.ex b/apps/evm/lib/evm/configuration/frontier.ex index bbfc6e253..aaf82ad59 100644 --- a/apps/evm/lib/evm/configuration/frontier.ex +++ b/apps/evm/lib/evm/configuration/frontier.ex @@ -8,7 +8,8 @@ defmodule EVM.Configuration.Frontier do sload_cost: 50, call_cost: 40, selfdestruct_cost: 0, - fail_nested_operation: true + fail_nested_operation: true, + exp_byte_cost: 10 def new do %__MODULE__{} @@ -16,33 +17,38 @@ defmodule EVM.Configuration.Frontier do end defimpl EVM.Configuration, for: EVM.Configuration.Frontier do - @spec contract_creation_cost(EVM.Configuration.t()) :: integer() + alias EVM.Configuration + + @spec contract_creation_cost(Configuration.t()) :: integer() def contract_creation_cost(config), do: config.contract_creation_cost - @spec has_delegate_call?(EVM.Configuration.t()) :: boolean() + @spec has_delegate_call?(Configuration.t()) :: boolean() def has_delegate_call?(config), do: config.has_delegate_call - @spec fail_contract_creation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_contract_creation_lack_of_gas?(Configuration.t()) :: boolean() def fail_contract_creation_lack_of_gas?(config), do: config.fail_contract_creation - @spec extcodesize_cost(EVM.Configuration.t()) :: integer() + @spec extcodesize_cost(Configuration.t()) :: integer() def extcodesize_cost(config), do: config.extcodesize_cost - @spec extcodecopy_cost(EVM.Configuration.t()) :: integer() + @spec extcodecopy_cost(Configuration.t()) :: integer() def extcodecopy_cost(config), do: config.extcodecopy_cost - @spec balance_cost(EVM.Configuration.t()) :: integer() + @spec balance_cost(Configuration.t()) :: integer() def balance_cost(config), do: config.balance_cost - @spec sload_cost(EVM.Configuration.t()) :: integer() + @spec sload_cost(Configuration.t()) :: integer() def sload_cost(config), do: config.sload_cost - @spec call_cost(EVM.Configuration.t()) :: integer() + @spec call_cost(Configuration.t()) :: integer() def call_cost(config), do: config.call_cost - @spec selfdestruct_cost(EVM.Configuration.t(), keyword()) :: integer() + @spec selfdestruct_cost(Configuration.t(), keyword()) :: integer() def selfdestruct_cost(config, _params), do: config.selfdestruct_cost - @spec fail_nested_operation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_nested_operation_lack_of_gas?(Configuration.t()) :: boolean() def fail_nested_operation_lack_of_gas?(config), do: config.fail_nested_operation + + @spec exp_byte_cost(Configuration.t()) :: integer() + def exp_byte_cost(config), do: config.exp_byte_cost end diff --git a/apps/evm/lib/evm/configuration/homestead.ex b/apps/evm/lib/evm/configuration/homestead.ex index e3a47cf08..13ff82fc6 100644 --- a/apps/evm/lib/evm/configuration/homestead.ex +++ b/apps/evm/lib/evm/configuration/homestead.ex @@ -10,33 +10,38 @@ defmodule EVM.Configuration.Homestead do end defimpl EVM.Configuration, for: EVM.Configuration.Homestead do - @spec contract_creation_cost(EVM.Configuration.t()) :: integer() + alias EVM.Configuration + + @spec contract_creation_cost(Configuration.t()) :: integer() def contract_creation_cost(config), do: config.contract_creation_cost - @spec has_delegate_call?(EVM.Configuration.t()) :: boolean() + @spec has_delegate_call?(Configuration.t()) :: boolean() def has_delegate_call?(config), do: config.has_delegate_call - @spec fail_contract_creation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_contract_creation_lack_of_gas?(Configuration.t()) :: boolean() def fail_contract_creation_lack_of_gas?(config), do: config.fail_contract_creation - @spec extcodesize_cost(EVM.Configuration.t()) :: integer() + @spec extcodesize_cost(Configuration.t()) :: integer() def extcodesize_cost(config), do: config.fallback_config.extcodesize_cost - @spec extcodecopy_cost(EVM.Configuration.t()) :: integer() + @spec extcodecopy_cost(Configuration.t()) :: integer() def extcodecopy_cost(config), do: config.fallback_config.extcodecopy_cost - @spec balance_cost(EVM.Configuration.t()) :: integer() + @spec balance_cost(Configuration.t()) :: integer() def balance_cost(config), do: config.fallback_config.balance_cost - @spec sload_cost(EVM.Configuration.t()) :: integer() + @spec sload_cost(Configuration.t()) :: integer() def sload_cost(config), do: config.fallback_config.sload_cost - @spec call_cost(EVM.Configuration.t()) :: integer() + @spec call_cost(Configuration.t()) :: integer() def call_cost(config), do: config.fallback_config.call_cost - @spec selfdestruct_cost(EVM.Configuration.t(), keyword()) :: integer() + @spec selfdestruct_cost(Configuration.t(), keyword()) :: integer() def selfdestruct_cost(config, _params), do: config.fallback_config.selfdestruct_cost - @spec fail_nested_operation_lack_of_gas?(EVM.Configuration.t()) :: boolean() + @spec fail_nested_operation_lack_of_gas?(Configuration.t()) :: boolean() def fail_nested_operation_lack_of_gas?(config), do: config.fallback_config.fail_nested_operation + + @spec exp_byte_cost(Configuration.t()) :: integer() + def exp_byte_cost(config), do: config.fallback_config.exp_byte_cost end diff --git a/apps/evm/lib/evm/gas.ex b/apps/evm/lib/evm/gas.ex index f33edd62f..b1da97f36 100644 --- a/apps/evm/lib/evm/gas.ex +++ b/apps/evm/lib/evm/gas.ex @@ -46,8 +46,6 @@ defmodule EVM.Gas do @g_newaccount 25_000 # Partial payment for an EXP operation. @g_exp 10 - # Partial payment when multiplied by dlog256(exponent)e for the EXP operation. - @g_expbyte 10 # Paid for every additional word when expanding memory. @g_memory 3 # The divsor of quadratic costs @@ -298,8 +296,8 @@ defmodule EVM.Gas do @spec operation_cost(atom(), list(EVM.val()), list(EVM.val()), MachineState.t()) :: t | nil def operation_cost(operation \\ nil, inputs \\ nil, machine_state \\ nil, exec_env \\ nil) - def operation_cost(:exp, [_base, exponent], _machine_state, _exec_env) do - @g_exp + @g_expbyte * MathHelper.integer_byte_size(exponent) + def operation_cost(:exp, [_base, exponent], _machine_state, exec_env) do + @g_exp + Configuration.exp_byte_cost(exec_env.config) * MathHelper.integer_byte_size(exponent) end def operation_cost(:codecopy, [_memory_offset, _code_offset, length], _machine_state, _exec_env) do From 0e5107ebc7aeb8605b54c11dc1166942342a6386 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 14 Aug 2018 12:58:15 +0300 Subject: [PATCH 2/3] add eip158 config --- apps/evm/lib/evm/configuration/eip158.ex | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 apps/evm/lib/evm/configuration/eip158.ex diff --git a/apps/evm/lib/evm/configuration/eip158.ex b/apps/evm/lib/evm/configuration/eip158.ex new file mode 100644 index 000000000..b6c1f244a --- /dev/null +++ b/apps/evm/lib/evm/configuration/eip158.ex @@ -0,0 +1,49 @@ +defmodule EVM.Configuration.EIP158 do + defstruct fallback_config: EVM.Configuration.EIP150.new(), + exp_byte_cost: 50 + + def new do + %__MODULE__{} + end +end + +defimpl EVM.Configuration, for: EVM.Configuration.EIP158 do + alias EVM.Configuration + + @spec contract_creation_cost(Configuration.t()) :: integer() + def contract_creation_cost(config), + do: Configuration.contract_creation_cost(config.fallback_config) + + @spec has_delegate_call?(Configuration.t()) :: boolean() + def has_delegate_call?(config), do: Configuration.has_delegate_call?(config.fallback_config) + + @spec fail_contract_creation_lack_of_gas?(Configuration.t()) :: boolean() + def fail_contract_creation_lack_of_gas?(config), + do: Configuration.fail_contract_creation_lack_of_gas?(config.fallback_config) + + @spec extcodesize_cost(Configuration.t()) :: integer() + def extcodesize_cost(config), do: Configuration.extcodesize_cost(config.fallback_config) + + @spec extcodecopy_cost(Configuration.t()) :: integer() + def extcodecopy_cost(config), do: Configuration.extcodecopy_cost(config.fallback_config) + + @spec balance_cost(Configuration.t()) :: integer() + def balance_cost(config), do: Configuration.balance_cost(config.fallback_config) + + @spec sload_cost(Configuration.t()) :: integer() + def sload_cost(config), do: Configuration.sload_cost(config.fallback_config) + + @spec call_cost(Configuration.t()) :: integer() + def call_cost(config), do: Configuration.call_cost(config.fallback_config) + + @spec selfdestruct_cost(Configuration.t(), keyword()) :: integer() + def selfdestruct_cost(config, _params), + do: Configuration.selfdestruct_cost(config.fallback_config) + + @spec fail_nested_operation_lack_of_gas?(Configuration.t()) :: boolean() + def fail_nested_operation_lack_of_gas?(config), + do: Configuration.fail_nested_operation_lack_of_gas?(config.fallback_config) + + @spec exp_byte_cost(Configuration.t()) :: integer() + def exp_byte_cost(config), do: config.exp_byte_cost +end From 17cac979951ae9f055d8ca3aecd65a0419226754 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 14 Aug 2018 15:47:01 +0300 Subject: [PATCH 3/3] fix dialyzer --- .dialyzer.ignore-warnings | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/.dialyzer.ignore-warnings b/.dialyzer.ignore-warnings index eed902196..953138203 100644 --- a/.dialyzer.ignore-warnings +++ b/.dialyzer.ignore-warnings @@ -42,21 +42,18 @@ apps/evm/lib/evm/functions.ex:154: Function 'not_enough_gas?'/2 has no local return apps/evm/lib/evm/functions.ex:166: Function 'is_invalid_jump_destination?'/3 will never be called apps/evm/lib/evm/functions.ex:180: Function 'is_invalid_jump_destination?'/3 will never be called -apps/evm/lib/evm/gas.ex:135: Function cost/2 has no local return -apps/evm/lib/evm/gas.ex:135: Function cost/3 has no local return -apps/evm/lib/evm/gas.ex:140: The call 'Elixir.EVM.Gas':operation_cost(atom(),_inputs@1::[integer()],_machine_state@1::#{'__struct__':='Elixir.EVM.MachineState', 'active_words':=integer(), 'gas':=integer(), 'last_return_data':=[integer -()], 'memory':=binary(), 'previously_active_words':=integer(), 'program_counter':=integer(), 'stack':=[integer()]},_exec_env@1::#{'__struct__':='Elixir.EVM.ExecEnv', 'account_interface':=atom(), 'address':=<<_:160>>, 'block_interface' -:=atom(), 'config':=atom(), 'data':=binary(), 'gas_price':=integer(), 'machine_code':=binary(), 'originator':=<<_:160>>, 'sender':=<<_:160>>, 'stack_depth':=integer(), 'value_in_wei':=integer()}) breaks the contract (atom(),['Elixir.E -VM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' -apps/evm/lib/evm/gas.ex:299: Function operation_cost/0 has no local return -apps/evm/lib/evm/gas.ex:299: The call 'Elixir.EVM.Gas':operation_cost('nil','nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' -apps/evm/lib/evm/gas.ex:299: Function operation_cost/1 has no local return -apps/evm/lib/evm/gas.ex:299: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),'nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' -apps/evm/lib/evm/gas.ex:299: Function operation_cost/2 has no local return -apps/evm/lib/evm/gas.ex:299: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),'nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' -apps/evm/lib/evm/gas.ex:299: Function operation_cost/3 has no local return -apps/evm/lib/evm/gas.ex:299: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),__@3::any(),'nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' -apps/evm/lib/evm/gas.ex:528: Function gas_cost_for_nested_operation/2 will never be called +apps/evm/lib/evm/gas.ex:133: Function cost/2 has no local return +apps/evm/lib/evm/gas.ex:133: Function cost/3 has no local return +apps/evm/lib/evm/gas.ex:138: The call 'Elixir.EVM.Gas':operation_cost(atom(),_inputs@1::[integer()],_machine_state@1::#{'__struct__':='Elixir.EVM.MachineState', 'active_words':=integer(), 'gas':=integer(), 'last_return_data':=[integer()], 'memory':=binary(), 'previously_active_words':=integer(), 'program_counter':=integer(), 'stack':=[integer()]},_exec_env@1::#{'__struct__':='Elixir.EVM.ExecEnv', 'account_interface':=atom(), 'address':=<<_:160>>, 'block_interface':=atom(), 'config':=atom(), 'created_accounts':=[<<_:160>>], 'data':=binary(), 'gas_price':=integer(), 'initial_account_interface':=_, 'machine_code':=binary(), 'originator':=<<_:160>>, 'sender':=<<_:160>>, 'stack_depth':=integer(), 'value_in_wei':=integer()}) breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' +apps/evm/lib/evm/gas.ex:297: Function operation_cost/0 has no local return +apps/evm/lib/evm/gas.ex:297: The call 'Elixir.EVM.Gas':operation_cost('nil','nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' +apps/evm/lib/evm/gas.ex:297: Function operation_cost/1 has no local return +apps/evm/lib/evm/gas.ex:297: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),'nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' +apps/evm/lib/evm/gas.ex:297: Function operation_cost/2 has no local return +apps/evm/lib/evm/gas.ex:297: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),'nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' +apps/evm/lib/evm/gas.ex:297: Function operation_cost/3 has no local return +apps/evm/lib/evm/gas.ex:297: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),__@3::any(),'nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil' +apps/evm/lib/evm/gas.ex:526: Function gas_cost_for_nested_operation/2 will never be called apps/evm/lib/evm/machine_state.ex:53: Function subtract_gas/2 has no local return apps/evm/lib/evm/operation/environmental_information.ex:114: Function calldataload/2 has no local return apps/evm/lib/evm/operation/environmental_information.ex:117: The call 'Elixir.EVM.Helpers':decode_signed(binary()) breaks the contract (integer() | 'nil') -> 'Elixir.EVM':val() | 'nil'