From 50984af8751f4e62b87c08cb6b6d2e0d5ab2ff2b Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 20 Aug 2024 09:11:47 +0300 Subject: [PATCH] fixing after merge --- vmhost/vmhooks/baseOps.go | 10 ++++++++-- vmhost/vmhooks/cryptoei.go | 15 +++++++++++---- vmhost/vmhooks/managedei.go | 12 +++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/vmhost/vmhooks/baseOps.go b/vmhost/vmhooks/baseOps.go index ca37190e2..ba9efeb39 100644 --- a/vmhost/vmhooks/baseOps.go +++ b/vmhost/vmhooks/baseOps.go @@ -1161,7 +1161,10 @@ func TransferESDTNFTExecuteByUserWithTypedArgs( output := host.Output() gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue * uint64(len(transfers)) - metering.UseAndTraceGas(gasToUse) + err := metering.UseGasBounded(gasToUse) + if WithFaultAndHost(host, err, runtime.SyncExecAPIErrorShouldFailExecution()) { + return 1 + } sender := runtime.GetContextAddress() @@ -2481,7 +2484,10 @@ func (context *VMHooksImpl) IsReservedFunctionName(nameHandle int32) int32 { metering := host.Metering() gasToUse := metering.GasSchedule().BaseOpsAPICost.IsReservedFunctionName - metering.UseAndTraceGas(gasToUse) + err := metering.UseGasBounded(gasToUse) + if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + return -1 + } name, err := managedTypes.GetBytes(nameHandle) if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index ff46089cf..5415f34b7 100644 --- a/vmhost/vmhooks/cryptoei.go +++ b/vmhost/vmhooks/cryptoei.go @@ -317,7 +317,7 @@ func (context *VMHooksImpl) ManagedVerifyBLS( func useGasForCryptoVerify( metering vmhost.MeteringContext, sigVerificationType string, -) { +) error { metering.StartGasTracing(sigVerificationType) gasToUse := metering.GasSchedule().CryptoAPICost.VerifyBLS @@ -333,7 +333,8 @@ func useGasForCryptoVerify( case verifyBLSAggregatedSignature: gasToUse = metering.GasSchedule().CryptoAPICost.VerifyBLSMultiSig } - metering.UseAndTraceGas(gasToUse) + + return metering.UseGasBounded(gasToUse) } // ManagedVerifyBLSWithHost VMHooks implementation. @@ -348,7 +349,10 @@ func ManagedVerifyBLSWithHost( metering := host.Metering() managedType := host.ManagedTypes() crypto := host.Crypto() - useGasForCryptoVerify(metering, sigVerificationType) + err := useGasForCryptoVerify(metering, sigVerificationType) + if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + return 1 + } keyBytes, err := managedType.GetBytes(keyHandle) if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { @@ -611,7 +615,10 @@ func ManagedVerifyCustomSecp256k1WithHost( managedType := host.ManagedTypes() crypto := host.Crypto() - useGasForCryptoVerify(metering, verifyCryptoFunc) + err := useGasForCryptoVerify(metering, verifyCryptoFunc) + if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + return 1 + } keyBytes, err := managedType.GetBytes(keyHandle) if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { diff --git a/vmhost/vmhooks/managedei.go b/vmhost/vmhooks/managedei.go index c570c0103..5543bd876 100644 --- a/vmhost/vmhooks/managedei.go +++ b/vmhost/vmhooks/managedei.go @@ -113,7 +113,10 @@ func (context *VMHooksImpl) ManagedGetOriginalCallerAddr(destinationHandle int32 metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller - metering.UseGasAndAddTracedGas(managedCallerName, gasToUse) + err := metering.UseGasBoundedAndAddTracedGas(managedCallerName, gasToUse) + if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + return + } caller := runtime.GetVMInput().OriginalCallerAddr managedType.SetBytes(destinationHandle, caller) @@ -127,7 +130,10 @@ func (context *VMHooksImpl) ManagedGetRelayerAddr(destinationHandle int32) { metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller - metering.UseGasAndAddTracedGas(managedCallerName, gasToUse) + err := metering.UseGasBoundedAndAddTracedGas(managedCallerName, gasToUse) + if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + return + } caller := runtime.GetVMInput().RelayerAddr managedType.SetBytes(destinationHandle, caller) @@ -1086,7 +1092,7 @@ func (context *VMHooksImpl) ManagedMultiTransferESDTNFTExecuteByUser( return -1 } - transfers, err := readESDTTransfers(managedType, tokenTransfersHandle) + transfers, err := readESDTTransfers(managedType, runtime, tokenTransfersHandle) if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { return -1 }