From abbdee348ae9eec67f6a40fb8aae9e6da59f0e9a Mon Sep 17 00:00:00 2001 From: Asuka Date: Thu, 18 Jun 2026 10:17:42 +0800 Subject: [PATCH] fix(gasmeter): account for new-account and memory gas in TRON ops NATIVEDELEGATERESOURCE/NATIVEUNDELEGATERESOURCE may create a new account (add callNewAccountGas like NATIVEFREEZE); NATIVEVOTE reads memory but did not charge memory-expansion gas. --- libevmasm/GasMeter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp index c6bd0737142d..9194d5987251 100644 --- a/libevmasm/GasMeter.cpp +++ b/libevmasm/GasMeter.cpp @@ -223,6 +223,10 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _ break; case Instruction::NATIVEVOTE: gas = GasCosts::voteGas; + // NATIVEVOTE reads two memory ranges (see SemanticInformation::readWriteOperations). + // With args == 4, the ranges are (offset, size) = (-3, -2) and (-1, 0) on the stack. + gas += memoryGas(-3, -2); + gas += memoryGas(-1, 0); break; case Instruction::NATIVEWITHDRAWREWARD: gas = GasCosts::withdrawGas; @@ -231,9 +235,12 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _ case Instruction::NATIVEUNFREEZEBALANCEV2: case Instruction::NATIVECANCELALLUNFREEZEV2: case Instruction::NATIVEWITHDRAWEXPIREUNFREEZE: + gas = GasCosts::freezeV2Gas; + break; case Instruction::NATIVEDELEGATERESOURCE: case Instruction::NATIVEUNDELEGATERESOURCE: gas = GasCosts::freezeV2Gas; + gas += GasCosts::callNewAccountGas; // Delegating to a non-existent address may create a new account. break; case Instruction::CHAINID: gas = runGas(Instruction::CHAINID, m_evmVersion);