mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Changed the type of gas calculation to bigint instead of size_t
Since the gas calculation can involve multiplication by ``--optimize-runs``, it is possible that `size_t` is not enough to represent the total gas.
This commit is contained in:
@@ -37,23 +37,23 @@ using namespace solidity;
|
||||
using namespace solidity::yul;
|
||||
using namespace solidity::util;
|
||||
|
||||
size_t GasMeter::costs(Expression const& _expression) const
|
||||
bigint GasMeter::costs(Expression const& _expression) const
|
||||
{
|
||||
return combineCosts(GasMeterVisitor::costs(_expression, m_dialect, m_isCreation));
|
||||
}
|
||||
|
||||
size_t GasMeter::instructionCosts(evmasm::Instruction _instruction) const
|
||||
bigint GasMeter::instructionCosts(evmasm::Instruction _instruction) const
|
||||
{
|
||||
return combineCosts(GasMeterVisitor::instructionCosts(_instruction, m_dialect, m_isCreation));
|
||||
}
|
||||
|
||||
size_t GasMeter::combineCosts(std::pair<size_t, size_t> _costs) const
|
||||
bigint GasMeter::combineCosts(std::pair<bigint, bigint> _costs) const
|
||||
{
|
||||
return _costs.first * m_runs + _costs.second;
|
||||
}
|
||||
|
||||
|
||||
pair<size_t, size_t> GasMeterVisitor::costs(
|
||||
pair<bigint, bigint> GasMeterVisitor::costs(
|
||||
Expression const& _expression,
|
||||
EVMDialect const& _dialect,
|
||||
bool _isCreation
|
||||
@@ -64,7 +64,7 @@ pair<size_t, size_t> GasMeterVisitor::costs(
|
||||
return {gmv.m_runGas, gmv.m_dataGas};
|
||||
}
|
||||
|
||||
pair<size_t, size_t> GasMeterVisitor::instructionCosts(
|
||||
pair<bigint, bigint> GasMeterVisitor::instructionCosts(
|
||||
evmasm::Instruction _instruction,
|
||||
EVMDialect const& _dialect,
|
||||
bool _isCreation
|
||||
@@ -92,11 +92,11 @@ void GasMeterVisitor::operator()(Literal const& _lit)
|
||||
m_runGas += evmasm::GasMeter::runGas(evmasm::Instruction::PUSH1);
|
||||
m_dataGas +=
|
||||
singleByteDataGas() +
|
||||
static_cast<size_t>(evmasm::GasMeter::dataGas(
|
||||
evmasm::GasMeter::dataGas(
|
||||
toCompactBigEndian(valueOfLiteral(_lit), 1),
|
||||
m_isCreation,
|
||||
m_dialect.evmVersion()
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
void GasMeterVisitor::operator()(Identifier const&)
|
||||
@@ -105,7 +105,7 @@ void GasMeterVisitor::operator()(Identifier const&)
|
||||
m_dataGas += singleByteDataGas();
|
||||
}
|
||||
|
||||
size_t GasMeterVisitor::singleByteDataGas() const
|
||||
bigint GasMeterVisitor::singleByteDataGas() const
|
||||
{
|
||||
if (m_isCreation)
|
||||
return evmasm::GasCosts::txDataNonZeroGas(m_dialect.evmVersion());
|
||||
|
||||
Reference in New Issue
Block a user