Skip to content

Commit

Permalink
Remove obsolete gas cost tiers
Browse files Browse the repository at this point in the history
- They're no longer used because the cost depends on the EVM version.
  • Loading branch information
cameel committed Feb 19, 2024
1 parent 18cabee commit f518815
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
1 change: 0 additions & 1 deletion libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <libevmasm/JumpdestRemover.h>
#include <libevmasm/BlockDeduplicator.h>
#include <libevmasm/ConstantOptimiser.h>
#include <libevmasm/GasMeter.h>

#include <liblangutil/CharStream.h>
#include <liblangutil/Exceptions.h>
Expand Down
24 changes: 13 additions & 11 deletions libevmasm/GasMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,20 @@ unsigned GasMeter::runGas(Instruction _instruction, langutil::EVMVersion _evmVer

switch (instructionInfo(_instruction, _evmVersion).gasPriceTier)
{
case Tier::Zero: return GasCosts::tier0Gas;
case Tier::Base: return GasCosts::tier1Gas;
case Tier::VeryLow: return GasCosts::tier2Gas;
case Tier::Low: return GasCosts::tier3Gas;
case Tier::Mid: return GasCosts::tier4Gas;
case Tier::High: return GasCosts::tier5Gas;
case Tier::Ext: return GasCosts::tier6Gas;
case Tier::WarmAccess: return GasCosts::warmStorageReadCost;
default: break;
case Tier::Zero: return GasCosts::tier0Gas;
case Tier::Base: return GasCosts::tier1Gas;
case Tier::VeryLow: return GasCosts::tier2Gas;
case Tier::Low: return GasCosts::tier3Gas;
case Tier::Mid: return GasCosts::tier4Gas;
case Tier::High: return GasCosts::tier5Gas;
case Tier::Ext: return GasCosts::tier6Gas;
case Tier::WarmAccess: return GasCosts::warmStorageReadCost;

case Tier::Special:
case Tier::Invalid:
assertThrow(false, OptimizerException, "Invalid gas tier for instruction " + instructionInfo(_instruction, _evmVersion).name);
}
assertThrow(false, OptimizerException, "Invalid gas tier for instruction " + instructionInfo(_instruction, _evmVersion).name);
return 0;
util::unreachable();
}

u256 GasMeter::dataGas(bytes const& _data, bool _inCreation, langutil::EVMVersion _evmVersion)
Expand Down
12 changes: 6 additions & 6 deletions libevmasm/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1, false, Tier::Low } },
{ Instruction::KECCAK256, { "KECCAK256", 0, 2, 1, true, Tier::Special } },
{ Instruction::ADDRESS, { "ADDRESS", 0, 0, 1, false, Tier::Base } },
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Balance } },
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Special } },
{ Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, Tier::Base } },
{ Instruction::CALLER, { "CALLER", 0, 0, 1, false, Tier::Base } },
{ Instruction::CALLVALUE, { "CALLVALUE", 0, 0, 1, false, Tier::Base } },
Expand All @@ -221,12 +221,12 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ Instruction::CODESIZE, { "CODESIZE", 0, 0, 1, false, Tier::Base } },
{ Instruction::CODECOPY, { "CODECOPY", 0, 3, 0, true, Tier::VeryLow } },
{ Instruction::GASPRICE, { "GASPRICE", 0, 0, 1, false, Tier::Base } },
{ Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false, Tier::ExtCode } },
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true, Tier::ExtCode } },
{ Instruction::RETURNDATASIZE, {"RETURNDATASIZE", 0, 0, 1, false, Tier::Base } },
{ Instruction::RETURNDATACOPY, {"RETURNDATACOPY", 0, 3, 0, true, Tier::VeryLow } },
{ Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false, Tier::Special } },
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true, Tier::Special } },
{ Instruction::RETURNDATASIZE, {"RETURNDATASIZE", 0, 0, 1, false, Tier::Base } },
{ Instruction::RETURNDATACOPY, {"RETURNDATACOPY", 0, 3, 0, true, Tier::VeryLow } },
{ Instruction::MCOPY, { "MCOPY", 0, 3, 0, true, Tier::VeryLow } },
{ Instruction::EXTCODEHASH, { "EXTCODEHASH", 0, 1, 1, false, Tier::Balance } },
{ Instruction::EXTCODEHASH, { "EXTCODEHASH", 0, 1, 1, false, Tier::Special } },
{ Instruction::BLOCKHASH, { "BLOCKHASH", 0, 1, 1, false, Tier::Ext } },
{ Instruction::BLOBHASH, { "BLOBHASH", 0, 1, 1, false, Tier::VeryLow } },
{ Instruction::COINBASE, { "COINBASE", 0, 0, 1, false, Tier::Base } },
Expand Down
2 changes: 0 additions & 2 deletions libevmasm/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ enum class Tier
High, // 10, Slow
Ext, // 20, Ext
WarmAccess, // 100, Warm Access
ExtCode, // 700, Extcode
Balance, // 400, Balance
Special, // multiparam or otherwise special
Invalid // Invalid.
};
Expand Down
2 changes: 0 additions & 2 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@

#include <libyul/YulStack.h>

#include <libevmasm/Instruction.h>
#include <libevmasm/Disassemble.h>
#include <libevmasm/GasMeter.h>

#include <liblangutil/Exceptions.h>
#include <liblangutil/SourceReferenceFormatter.h>
Expand Down

0 comments on commit f518815

Please sign in to comment.