mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add new gas price for deployed bytecode (EIP2028)
This commit is contained in:
+11
-10
@@ -64,7 +64,8 @@ evmc::VM* EVMHost::getVM(string const& _path)
|
||||
}
|
||||
|
||||
EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm):
|
||||
m_vm(_vm)
|
||||
m_vm(_vm),
|
||||
m_evmVersion(_evmVersion)
|
||||
{
|
||||
if (!m_vm)
|
||||
{
|
||||
@@ -73,21 +74,21 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm):
|
||||
}
|
||||
|
||||
if (_evmVersion == langutil::EVMVersion::homestead())
|
||||
m_evmVersion = EVMC_HOMESTEAD;
|
||||
m_evmRevision = EVMC_HOMESTEAD;
|
||||
else if (_evmVersion == langutil::EVMVersion::tangerineWhistle())
|
||||
m_evmVersion = EVMC_TANGERINE_WHISTLE;
|
||||
m_evmRevision = EVMC_TANGERINE_WHISTLE;
|
||||
else if (_evmVersion == langutil::EVMVersion::spuriousDragon())
|
||||
m_evmVersion = EVMC_SPURIOUS_DRAGON;
|
||||
m_evmRevision = EVMC_SPURIOUS_DRAGON;
|
||||
else if (_evmVersion == langutil::EVMVersion::byzantium())
|
||||
m_evmVersion = EVMC_BYZANTIUM;
|
||||
m_evmRevision = EVMC_BYZANTIUM;
|
||||
else if (_evmVersion == langutil::EVMVersion::constantinople())
|
||||
m_evmVersion = EVMC_CONSTANTINOPLE;
|
||||
m_evmRevision = EVMC_CONSTANTINOPLE;
|
||||
else if (_evmVersion == langutil::EVMVersion::istanbul())
|
||||
m_evmVersion = EVMC_ISTANBUL;
|
||||
m_evmRevision = EVMC_ISTANBUL;
|
||||
else if (_evmVersion == langutil::EVMVersion::berlin())
|
||||
assertThrow(false, Exception, "Berlin is not supported yet.");
|
||||
else //if (_evmVersion == langutil::EVMVersion::petersburg())
|
||||
m_evmVersion = EVMC_PETERSBURG;
|
||||
m_evmRevision = EVMC_PETERSBURG;
|
||||
}
|
||||
|
||||
evmc_storage_status EVMHost::set_storage(const evmc::address& _addr, const evmc::bytes32& _key, const evmc::bytes32& _value) noexcept
|
||||
@@ -146,7 +147,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
|
||||
{
|
||||
message.gas -= message.kind == EVMC_CREATE ? eth::GasCosts::txCreateGas : eth::GasCosts::txGas;
|
||||
for (size_t i = 0; i < message.input_size; ++i)
|
||||
message.gas -= message.input_data[i] == 0 ? eth::GasCosts::txDataZeroGas : eth::GasCosts::txDataNonZeroGas;
|
||||
message.gas -= message.input_data[i] == 0 ? eth::GasCosts::txDataZeroGas : eth::GasCosts::txDataNonZeroGas(m_evmVersion);
|
||||
if (message.gas < 0)
|
||||
{
|
||||
evmc::result result({});
|
||||
@@ -191,7 +192,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
|
||||
|
||||
evmc::address currentAddress = m_currentAddress;
|
||||
m_currentAddress = message.destination;
|
||||
evmc::result result = m_vm->execute(*this, m_evmVersion, message, code.data(), code.size());
|
||||
evmc::result result = m_vm->execute(*this, m_evmRevision, message, code.data(), code.size());
|
||||
m_currentAddress = currentAddress;
|
||||
|
||||
if (message.kind == EVMC_CREATE)
|
||||
|
||||
+4
-1
@@ -180,7 +180,10 @@ private:
|
||||
static evmc::result resultWithGas(evmc_message const& _message, bytes const& _data) noexcept;
|
||||
|
||||
evmc::VM* m_vm = nullptr;
|
||||
evmc_revision m_evmVersion;
|
||||
// EVM version requested by the testing tool
|
||||
langutil::EVMVersion m_evmVersion;
|
||||
// EVM version requested from EVMC (matches the above)
|
||||
evmc_revision m_evmRevision;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <test/libsolidity/SolidityExecutionFramework.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
#include <libdevcore/SwarmHash.h>
|
||||
#include <libevmasm/GasMeter.h>
|
||||
|
||||
@@ -37,10 +38,10 @@ namespace solidity
|
||||
namespace test
|
||||
{
|
||||
|
||||
#define CHECK_DEPLOY_GAS(_gasNoOpt, _gasOpt) \
|
||||
#define CHECK_DEPLOY_GAS(_gasNoOpt, _gasOpt, _evmVersion) \
|
||||
do \
|
||||
{ \
|
||||
u256 bzzr1Cost = GasMeter::dataGas(dev::bzzr1Hash(m_compiler.metadata(m_compiler.lastContractName())).asBytes(), true); \
|
||||
u256 bzzr1Cost = GasMeter::dataGas(dev::bzzr1Hash(m_compiler.metadata(m_compiler.lastContractName())).asBytes(), true, _evmVersion); \
|
||||
u256 gasOpt{_gasOpt}; \
|
||||
u256 gasNoOpt{_gasNoOpt}; \
|
||||
u256 gas = m_optimiserSettings == OptimiserSettings::minimal() ? gasNoOpt : gasOpt; \
|
||||
@@ -95,22 +96,25 @@ BOOST_AUTO_TEST_CASE(string_storage)
|
||||
m_compiler.overwriteReleaseFlag(true);
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
if (Options::get().evmVersion() <= EVMVersion::byzantium())
|
||||
CHECK_DEPLOY_GAS(134071, 130763);
|
||||
auto evmVersion = dev::test::Options::get().evmVersion();
|
||||
|
||||
if (evmVersion <= EVMVersion::byzantium())
|
||||
CHECK_DEPLOY_GAS(134071, 130763, evmVersion);
|
||||
// This is only correct on >=Constantinople.
|
||||
else if (Options::get().useABIEncoderV2)
|
||||
{
|
||||
if (Options::get().optimizeYul)
|
||||
CHECK_DEPLOY_GAS(151455, 127653);
|
||||
CHECK_DEPLOY_GAS(151455, 127653, evmVersion);
|
||||
else
|
||||
CHECK_DEPLOY_GAS(151455, 135371);
|
||||
CHECK_DEPLOY_GAS(151455, 135371, evmVersion);
|
||||
}
|
||||
else
|
||||
CHECK_DEPLOY_GAS(126861, 119591);
|
||||
if (Options::get().evmVersion() >= EVMVersion::byzantium())
|
||||
CHECK_DEPLOY_GAS(126861, 119591, evmVersion);
|
||||
|
||||
if (evmVersion >= EVMVersion::byzantium())
|
||||
{
|
||||
callContractFunction("f()");
|
||||
if (Options::get().evmVersion() == EVMVersion::byzantium())
|
||||
if (evmVersion == EVMVersion::byzantium())
|
||||
CHECK_GAS(21551, 21526, 20);
|
||||
// This is only correct on >=Constantinople.
|
||||
else if (Options::get().useABIEncoderV2)
|
||||
|
||||
@@ -114,9 +114,10 @@ public:
|
||||
|
||||
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)
|
||||
{
|
||||
auto evmVersion = dev::test::Options::get().evmVersion();
|
||||
GasMeter::GasConsumption gas = _isCreation ? GasCosts::txCreateGas : GasCosts::txGas;
|
||||
for (auto i: _data)
|
||||
gas += i != 0 ? GasCosts::txDataNonZeroGas : GasCosts::txDataZeroGas;
|
||||
gas += i != 0 ? GasCosts::txDataNonZeroGas(evmVersion) : GasCosts::txDataZeroGas;
|
||||
return gas;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user