mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
correct calculation of LOG cost
This commit is contained in:
parent
fdd5275a83
commit
94e41d815b
3 changed files with 24 additions and 0 deletions
|
|
@ -805,6 +805,9 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
auto numBytes = stack.pop();
|
auto numBytes = stack.pop();
|
||||||
_memory.require(beginIdx, numBytes);
|
_memory.require(beginIdx, numBytes);
|
||||||
|
|
||||||
|
// This will commit the current cost block
|
||||||
|
_gasMeter.countLogData(numBytes);
|
||||||
|
|
||||||
std::array<llvm::Value*,4> topics;
|
std::array<llvm::Value*,4> topics;
|
||||||
auto numTopics = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::LOG0);
|
auto numTopics = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::LOG0);
|
||||||
for (size_t i = 0; i < numTopics; ++i)
|
for (size_t i = 0; i < numTopics; ++i)
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,16 @@ uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure
|
||||||
case Instruction::CREATE:
|
case Instruction::CREATE:
|
||||||
return static_cast<uint64_t>(c_createGas);
|
return static_cast<uint64_t>(c_createGas);
|
||||||
|
|
||||||
|
case Instruction::LOG0:
|
||||||
|
case Instruction::LOG1:
|
||||||
|
case Instruction::LOG2:
|
||||||
|
case Instruction::LOG3:
|
||||||
|
case Instruction::LOG4:
|
||||||
|
{
|
||||||
|
auto numTopics = static_cast<uint64_t>(inst) - static_cast<uint64_t>(Instruction::LOG0);
|
||||||
|
return static_cast<uint64_t>(c_logGas) + numTopics * static_cast<uint64_t>(c_logTopicGas);
|
||||||
|
}
|
||||||
|
|
||||||
default: // Assumes instruction code is valid
|
default: // Assumes instruction code is valid
|
||||||
return static_cast<uint64_t>(c_stepGas);
|
return static_cast<uint64_t>(c_stepGas);
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +148,14 @@ void GasMeter::countSStore(Ext& _ext, llvm::Value* _index, llvm::Value* _newValu
|
||||||
createCall(m_gasCheckFunc, cost);
|
createCall(m_gasCheckFunc, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GasMeter::countLogData(llvm::Value* _dataLength)
|
||||||
|
{
|
||||||
|
assert(m_checkCall);
|
||||||
|
assert(m_blockCost > 0); // LOGn instruction is already counted
|
||||||
|
auto cost = m_builder.CreateMul(_dataLength, Constant::get(c_logDataGas), "logdata_cost");
|
||||||
|
commitCostBlock(cost);
|
||||||
|
}
|
||||||
|
|
||||||
void GasMeter::giveBack(llvm::Value* _gas)
|
void GasMeter::giveBack(llvm::Value* _gas)
|
||||||
{
|
{
|
||||||
m_runtimeManager.setGas(m_builder.CreateAdd(m_runtimeManager.getGas(), _gas));
|
m_runtimeManager.setGas(m_builder.CreateAdd(m_runtimeManager.getGas(), _gas));
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ public:
|
||||||
/// Calculate & count gas cost for SSTORE instruction
|
/// Calculate & count gas cost for SSTORE instruction
|
||||||
void countSStore(class Ext& _ext, llvm::Value* _index, llvm::Value* _newValue);
|
void countSStore(class Ext& _ext, llvm::Value* _index, llvm::Value* _newValue);
|
||||||
|
|
||||||
|
/// Count gas cost of LOG data
|
||||||
|
void countLogData(llvm::Value* _dataLength);
|
||||||
|
|
||||||
/// Finalize cost-block by checking gas needed for the block before the block
|
/// Finalize cost-block by checking gas needed for the block before the block
|
||||||
/// @param _additionalCost adds additional cost to cost-block before commit
|
/// @param _additionalCost adds additional cost to cost-block before commit
|
||||||
void commitCostBlock(llvm::Value* _additionalCost = nullptr);
|
void commitCostBlock(llvm::Value* _additionalCost = nullptr);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue