From af19be42d9edd89cb28b2d7b60660fa142fb4a8d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 12:52:51 +0300 Subject: [PATCH 1/7] fixing after merge --- vmhost/contexts/blockchain.go | 5 +- vmhost/contexts/runtime.go | 38 -- vmhost/hosttest/execution_test.go | 191 ++------ vmhost/hosttest/managedops_test.go | 12 +- vmhost/interface.go | 9 +- vmhost/vmhooks/baseOps.go | 712 ++++++++++++++++++----------- vmhost/vmhooks/bigFloatOps.go | 6 +- vmhost/vmhooks/bigIntOps.go | 9 +- vmhost/vmhooks/cryptoei.go | 136 +++--- vmhost/vmhooks/manBufOps.go | 29 +- vmhost/vmhooks/managedei.go | 236 ++++++---- vmhost/vmhooks/smallIntOps.go | 42 +- vmhost/vmhooks/vmHooksImpl.go | 17 +- vmhost/vmhookstest/manMaps_test.go | 16 +- 14 files changed, 767 insertions(+), 691 deletions(-) diff --git a/vmhost/contexts/blockchain.go b/vmhost/contexts/blockchain.go index fbdf520db..28609e75c 100644 --- a/vmhost/contexts/blockchain.go +++ b/vmhost/contexts/blockchain.go @@ -1,6 +1,7 @@ package contexts import ( + "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" "math/big" "github.com/multiversx/mx-chain-core-go/core/check" @@ -8,7 +9,6 @@ import ( logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" ) var logBlockchain = logger.GetOrCreate("vm/blockchainContext") @@ -317,7 +317,8 @@ func (context *blockchainContext) PopSetActiveState() { prevSnapshot := context.stateStack[stateStackLen-1] err := context.blockChainHook.RevertToSnapshot(prevSnapshot) - if vmhooks.WithFaultAndHost(context.host, err, true) { + if err != nil { + vmhooks.FailExecution(context.host, err) context.host.Runtime().AddError(err, "RevertToSnapshot") logBlockchain.Error("PopSetActiveState RevertToSnapshot", "error", err) return diff --git a/vmhost/contexts/runtime.go b/vmhost/contexts/runtime.go index 22238a5e5..4ffc46ffa 100644 --- a/vmhost/contexts/runtime.go +++ b/vmhost/contexts/runtime.go @@ -702,44 +702,6 @@ func (context *runtimeContext) checkIfContainsNewCryptoApi() error { return nil } -// BaseOpsErrorShouldFailExecution returns true -func (context *runtimeContext) BaseOpsErrorShouldFailExecution() bool { - return true -} - -// SyncExecAPIErrorShouldFailExecution specifies whether an error in the -// EEI functions for synchronous execution should abort contract execution. -func (context *runtimeContext) SyncExecAPIErrorShouldFailExecution() bool { - return true -} - -// BigIntAPIErrorShouldFailExecution specifies whether an error in the EEI -// functions for BigInt operations should abort contract execution. -func (context *runtimeContext) BigIntAPIErrorShouldFailExecution() bool { - return true -} - -// BigFloatAPIErrorShouldFailExecution returns true -func (context *runtimeContext) BigFloatAPIErrorShouldFailExecution() bool { - return true -} - -// CryptoAPIErrorShouldFailExecution specifies whether an error in the EEI -// functions for crypto operations should abort contract execution. -func (context *runtimeContext) CryptoAPIErrorShouldFailExecution() bool { - return true -} - -// ManagedBufferAPIErrorShouldFailExecution returns true -func (context *runtimeContext) ManagedBufferAPIErrorShouldFailExecution() bool { - return true -} - -// ManagedMapAPIErrorShouldFailExecution returns true -func (context *runtimeContext) ManagedMapAPIErrorShouldFailExecution() bool { - return true -} - // UseGasBoundedShouldFailExecution returns true when flag activated func (context *runtimeContext) UseGasBoundedShouldFailExecution() bool { return context.host.EnableEpochsHandler().IsFlagEnabled(vmhost.UseGasBoundedShouldFailExecutionFlag) diff --git a/vmhost/hosttest/execution_test.go b/vmhost/hosttest/execution_test.go index 79fc50f25..7b6e245fa 100644 --- a/vmhost/hosttest/execution_test.go +++ b/vmhost/hosttest/execution_test.go @@ -1322,11 +1322,6 @@ func TestExecution_ExecuteOnSameContext_Prepare(t *testing.T) { } func TestExecution_ExecuteOnSameContext_Wrong(t *testing.T) { - executionCostBeforeExecuteAPI := uint64(156) - executeAPICost := uint64(39) - gasLostOnFailure := uint64(50000) - finalCost := uint64(44) - test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). @@ -1338,34 +1333,9 @@ func TestExecution_ExecuteOnSameContext_Wrong(t *testing.T) { WithGasProvided(test.GasProvided). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if !host.Runtime().SyncExecAPIErrorShouldFailExecution() { - verify.Ok(). - GasUsed(test.ParentAddress, 3405). - Balance(test.ParentAddress, 1000). - BalanceDelta(test.ParentAddress, -test.ParentTransferValue). - BalanceDelta(test.ParentTransferReceiver, test.ParentTransferValue). - GasRemaining(test.GasProvided- - test.ParentCompilationCostSameCtx- - executionCostBeforeExecuteAPI- - executeAPICost- - gasLostOnFailure- - finalCost). - ReturnData(test.ParentFinishA, test.ParentFinishB, []byte("succ"), []byte("fail")). - Storage( - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyA).WithValue(test.ParentDataA), - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyB).WithValue(test.ParentDataB), - test.CreateStoreEntry(test.ChildAddress).WithKey(test.ChildKey).WithValue(test.ChildData), - ). - Transfers( - test.CreateTransferEntry(test.ParentAddress, test.ParentTransferReceiver, 0). - WithData(test.ParentTransferData). - WithValue(big.NewInt(test.ParentTransferValue)), - ) - } else { - verify.ExecutionFailed(). - ReturnMessage("account not found"). - GasRemaining(0) - } + verify.ExecutionFailed(). + ReturnMessage("account not found"). + GasRemaining(0) }) } @@ -1386,11 +1356,6 @@ func TestExecution_ExecuteOnSameContext_OutOfGas(t *testing.T) { // compilation and starting, but the child starts an infinite loop which will // end in OutOfGas. - executionCostBeforeExecuteAPI := uint64(90) - executeAPICost := uint64(1) - gasLostOnFailure := uint64(3500) - finalCost := uint64(54) - test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). @@ -1405,27 +1370,10 @@ func TestExecution_ExecuteOnSameContext_OutOfGas(t *testing.T) { WithGasProvided(test.GasProvided). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if !host.Runtime().SyncExecAPIErrorShouldFailExecution() { - verify.Ok(). - Balance(test.ParentAddress, 1000). - BalanceDelta(test.ParentAddress, 0). - GasRemaining(test.GasProvided- - test.ParentCompilationCostSameCtx- - executionCostBeforeExecuteAPI- - executeAPICost- - gasLostOnFailure- - finalCost). - ReturnData(test.ParentFinishA, []byte("fail")). - Storage( - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyA).WithValue(test.ParentDataA), - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyB).WithValue(test.ParentDataB), - ) - } else { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()). - HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). - GasRemaining(0) - } + verify.OutOfGas(). + ReturnMessage(vmhost.ErrNotEnoughGas.Error()). + HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). + GasRemaining(0) }) } @@ -1617,26 +1565,10 @@ func TestExecution_ExecuteOnSameContext_Recursive_Direct_ErrMaxInstances(t *test WithArguments([]byte{recursiveCalls}). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if host.Runtime().SyncExecAPIErrorShouldFailExecution() == false { - verify.Ok(). - Balance(test.ParentAddress, 1000). - BalanceDelta(test.ParentAddress, 0). - ReturnData( - []byte(fmt.Sprintf("Rfinish%03d", recursiveCalls)), - []byte("fail"), - ). - Storage( - test.CreateStoreEntry(test.ParentAddress). - WithKey([]byte(fmt.Sprintf("Rkey%03d.........................", recursiveCalls))). - WithValue([]byte(fmt.Sprintf("Rvalue%03d", recursiveCalls))), - ) - require.Equal(t, int64(1), host.ManagedTypes().GetBigIntOrCreate(16).Int64()) - } else { - verify.ExecutionFailed(). - ReturnMessage(vmhost.ErrExecutionFailed.Error()). - HasRuntimeErrors(vmhost.ErrMaxInstancesReached.Error(), vmhost.ErrExecutionFailed.Error()). - GasRemaining(0) - } + verify.ExecutionFailed(). + ReturnMessage(vmhost.ErrExecutionFailed.Error()). + HasRuntimeErrors(vmhost.ErrMaxInstancesReached.Error(), vmhost.ErrExecutionFailed.Error()). + GasRemaining(0) }) } @@ -1815,16 +1747,10 @@ func TestExecution_ExecuteOnSameContext_Recursive_Mutual_SCs_OutOfGas(t *testing WithArguments([]byte{recursiveCalls}). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if host.Runtime().SyncExecAPIErrorShouldFailExecution() == false { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()). - GasRemaining(0) - } else { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()). - HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). - GasRemaining(0) - } + verify.OutOfGas(). + ReturnMessage(vmhost.ErrNotEnoughGas.Error()). + HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). + GasRemaining(0) }) } @@ -1871,11 +1797,6 @@ func TestExecution_ExecuteOnDestContext_Wrong(t *testing.T) { // Call parentFunctionWrongCall() of the parent SC, which will try to call a // non-existing SC. - executionCostBeforeExecuteAPI := uint64(156) - executeAPICost := uint64(42) - gasLostOnFailure := uint64(10000) - finalCost := uint64(44) - test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). @@ -1887,38 +1808,9 @@ func TestExecution_ExecuteOnDestContext_Wrong(t *testing.T) { WithGasProvided(test.GasProvided). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if host.Runtime().SyncExecAPIErrorShouldFailExecution() == false { - verify.Ok(). - Balance(test.ParentAddress, 1000). - BalanceDelta(test.ParentAddress, -42). - GasUsed(test.ParentAddress, 3612). - BalanceDelta(test.ChildTransferReceiver, 96). - BalanceDelta(test.ParentTransferReceiver, test.ParentTransferValue). - GasRemaining(test.GasProvided- - test.ParentCompilationCostDestCtx- - executionCostBeforeExecuteAPI- - executeAPICost- - gasLostOnFailure- - finalCost). - ReturnData(test.ParentFinishA, test.ParentFinishB, []byte("succ"), []byte("fail")). - Storage( - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyA).WithValue(test.ParentDataA), - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyB).WithValue(test.ParentDataB), - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ChildKey).WithValue(test.ChildData), - ). - Transfers( - test.CreateTransferEntry(test.ChildAddress, test.ChildTransferReceiver, 0). - WithData([]byte("qwerty")). - WithValue(big.NewInt(96)), - test.CreateTransferEntry(test.ParentAddress, test.ParentTransferReceiver, 1). - WithData(test.ParentTransferData). - WithValue(big.NewInt(test.ParentTransferValue)), - ) - } else { - verify.ExecutionFailed(). - ReturnMessage("account not found"). - GasRemaining(0) - } + verify.ExecutionFailed(). + ReturnMessage("account not found"). + GasRemaining(0) }) } @@ -1939,11 +1831,6 @@ func TestExecution_ExecuteOnDestContext_OutOfGas(t *testing.T) { // compilation and starting, but the child starts an infinite loop which will // end in OutOfGas. - executionCostBeforeExecuteAPI := uint64(90) - executeAPICost := uint64(1) - gasLostOnFailure := uint64(3500) - finalCost := uint64(54) - test.BuildInstanceCallTest(t). WithContracts( test.CreateInstanceContract(test.ParentAddress). @@ -1959,27 +1846,10 @@ func TestExecution_ExecuteOnDestContext_OutOfGas(t *testing.T) { WithGasProvided(test.GasProvided). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if host.Runtime().SyncExecAPIErrorShouldFailExecution() == false { - verify.Ok(). - Balance(test.ParentAddress, 1000). - GasRemaining(test.GasProvided- - test.ParentCompilationCostDestCtx- - executionCostBeforeExecuteAPI- - executeAPICost- - gasLostOnFailure- - finalCost). - ReturnData(test.ParentFinishA, []byte("fail")). - Storage( - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyA).WithValue(test.ParentDataA), - test.CreateStoreEntry(test.ParentAddress).WithKey(test.ParentKeyB).WithValue(test.ParentDataB), - ) - require.Equal(t, int64(42), host.ManagedTypes().GetBigIntOrCreate(12).Int64()) - } else { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()). - HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). - GasRemaining(0) - } + verify.OutOfGas(). + ReturnMessage(vmhost.ErrNotEnoughGas.Error()). + HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). + GasRemaining(0) }) } @@ -2424,15 +2294,10 @@ func TestExecution_ExecuteOnDestContext_Recursive_Mutual_SCs_OutOfGas(t *testing WithArguments([]byte{recursiveCalls}). Build()). AndAssertResults(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) { - if host.Runtime().SyncExecAPIErrorShouldFailExecution() == false { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()) - } else { - verify.OutOfGas(). - ReturnMessage(vmhost.ErrNotEnoughGas.Error()). - HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). - GasRemaining(0) - } + verify.OutOfGas(). + ReturnMessage(vmhost.ErrNotEnoughGas.Error()). + HasRuntimeErrors(vmhost.ErrNotEnoughGas.Error()). + GasRemaining(0) }) } @@ -3242,7 +3107,7 @@ func TestExecution_Mocked_Warm_Instances_Same_Contract_Same_Address(t *testing.T host := parentInstance.Host instance := contextmock.GetMockInstance(host) - vmhooks.WithFaultAndHost(host, vmhost.ErrNotEnoughGas, true) + vmhooks.FailExecution(host, vmhost.ErrNotEnoughGas) childInput := test.DefaultTestContractCallInput() childInput.CallerAddr = test.ParentAddress @@ -3285,7 +3150,7 @@ func TestExecution_Mocked_Warm_Instances_Same_Contract_Different_Address(t *test host := parentInstance.Host instance := contextmock.GetMockInstance(host) - vmhooks.WithFaultAndHost(host, vmhost.ErrNotEnoughGas, true) + vmhooks.FailExecution(host, vmhost.ErrNotEnoughGas) childInput := test.DefaultTestContractCallInput() childInput.CallerAddr = test.ParentAddress diff --git a/vmhost/hosttest/managedops_test.go b/vmhost/hosttest/managedops_test.go index f5a50a9bb..1339f2fce 100644 --- a/vmhost/hosttest/managedops_test.go +++ b/vmhost/hosttest/managedops_test.go @@ -30,11 +30,11 @@ func TestManaged_SetByteSlice(t *testing.T) { result := vmhooks.ManagedBufferSetByteSliceWithTypedArgs( host, mBuffer, int32(len(prefix)), int32(len(slice)), []byte(data)) if result != 0 { - vmhooks.WithFaultAndHost(host, vmhost.ErrSignalError, true) + vmhooks.FailExecution(host, vmhost.ErrSignalError) } bufferBytes, err := managedType.GetBytes(mBuffer) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) } host.Output().Finish(bufferBytes) return parentInstance @@ -77,11 +77,11 @@ func TestManaged_CopyByteSlice_DifferentBuffer(t *testing.T) { result := vmhooks.ManagedBufferCopyByteSliceWithHost( host, sourceMBuffer, int32(len(prefix)), int32(len(slice)), destMBuffer) if result != 0 { - vmhooks.WithFaultAndHost(host, vmhost.ErrSignalError, true) + vmhooks.FailExecution(host, vmhost.ErrSignalError) } destBytes, err := managedType.GetBytes(destMBuffer) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) } host.Output().Finish(destBytes) return parentInstance @@ -119,11 +119,11 @@ func TestManaged_CopyByteSlice_SameBuffer(t *testing.T) { result := vmhooks.ManagedBufferCopyByteSliceWithHost( host, sourceMBuffer, int32(len(prefix))-deltaForSlice, int32(len(slice)), sourceMBuffer) if result != 0 { - vmhooks.WithFaultAndHost(host, vmhost.ErrSignalError, true) + vmhooks.FailExecution(host, vmhost.ErrSignalError) } destBytes, err := managedType.GetBytes(sourceMBuffer) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) } host.Output().Finish(destBytes) return parentInstance diff --git a/vmhost/interface.go b/vmhost/interface.go index ae122cea0..fa74ff916 100644 --- a/vmhost/interface.go +++ b/vmhost/interface.go @@ -148,13 +148,6 @@ type RuntimeContext interface { CallSCFunction(functionName string) error GetPointsUsed() uint64 SetPointsUsed(gasPoints uint64) - BaseOpsErrorShouldFailExecution() bool - SyncExecAPIErrorShouldFailExecution() bool - CryptoAPIErrorShouldFailExecution() bool - BigIntAPIErrorShouldFailExecution() bool - BigFloatAPIErrorShouldFailExecution() bool - ManagedBufferAPIErrorShouldFailExecution() bool - ManagedMapAPIErrorShouldFailExecution() bool UseGasBoundedShouldFailExecution() bool CleanInstance() @@ -162,7 +155,7 @@ type RuntimeContext interface { GetAllErrors() error ValidateCallbackName(callbackName string) error - + IsReservedFunctionName(functionName string) bool HasFunction(functionName string) bool diff --git a/vmhost/vmhooks/baseOps.go b/vmhost/vmhooks/baseOps.go index ba9efeb39..eb4c16f68 100644 --- a/vmhost/vmhooks/baseOps.go +++ b/vmhost/vmhooks/baseOps.go @@ -114,7 +114,7 @@ var logEEI = logger.GetOrCreate("vm/eei") func getESDTTransferFromInputFailIfWrongIndex(host vmhost.VMHost, index int32) *vmcommon.ESDTTransfer { esdtTransfers := host.Runtime().GetVMInput().ESDTTransfers if int32(len(esdtTransfers))-1 < index || index < 0 { - WithFaultAndHost(host, vmhost.ErrInvalidTokenIndex, host.Runtime().BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInvalidTokenIndex) return nil } return esdtTransfers[index] @@ -123,7 +123,8 @@ func getESDTTransferFromInputFailIfWrongIndex(host vmhost.VMHost, index int32) * func failIfMoreThanOneESDTTransfer(context *VMHooksImpl) bool { runtime := context.GetRuntimeContext() if len(runtime.GetVMInput().ESDTTransfers) > 1 { - return context.WithFault(vmhost.ErrTooManyESDTTransfers, true) + FailExecution(context.GetVMHost(), vmhost.ErrTooManyESDTTransfers) + return true } return false } @@ -135,7 +136,8 @@ func (context *VMHooksImpl) GetGasLeft() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetGasLeft err := metering.UseGasBoundedAndAddTracedGas(getGasLeftName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -150,13 +152,15 @@ func (context *VMHooksImpl) GetSCAddress(resultOffset executor.MemPtr) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetSCAddress err := metering.UseGasBoundedAndAddTracedGas(getSCAddressName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } owner := runtime.GetContextAddress() err = context.MemStore(resultOffset, owner) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -165,22 +169,24 @@ func (context *VMHooksImpl) GetSCAddress(resultOffset executor.MemPtr) { // @autogenerate(VMHooks) func (context *VMHooksImpl) GetOwnerAddress(resultOffset executor.MemPtr) { blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetOwnerAddress err := metering.UseGasBoundedAndAddTracedGas(getOwnerAddressName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } owner, err := blockchain.GetOwnerAddress() - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = context.MemStore(resultOffset, owner) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -189,17 +195,18 @@ func (context *VMHooksImpl) GetOwnerAddress(resultOffset executor.MemPtr) { // @autogenerate(VMHooks) func (context *VMHooksImpl) GetShardOfAddress(addressOffset executor.MemPtr) int32 { blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetShardOfAddress err := metering.UseGasBoundedAndAddTracedGas(getShardOfAddressName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } address, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -210,17 +217,18 @@ func (context *VMHooksImpl) GetShardOfAddress(addressOffset executor.MemPtr) int // @autogenerate(VMHooks) func (context *VMHooksImpl) IsSmartContract(addressOffset executor.MemPtr) int32 { blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.IsSmartContract err := metering.UseGasBoundedAndAddTracedGas(isSmartContractName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } address, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -240,14 +248,17 @@ func (context *VMHooksImpl) SignalError(messageOffset executor.MemPtr, messageLe gasToUse += metering.GasSchedule().BaseOperationCost.PersistPerByte * uint64(messageLength) err := metering.UseGasBounded(gasToUse) - if err != nil && context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } message, err := context.MemLoad(messageOffset, messageLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } + runtime.SignalUserError(string(message)) } @@ -255,24 +266,26 @@ func (context *VMHooksImpl) SignalError(messageOffset executor.MemPtr, messageLe // @autogenerate(VMHooks) func (context *VMHooksImpl) GetExternalBalance(addressOffset executor.MemPtr, resultOffset executor.MemPtr) { blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(getExternalBalanceName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } address, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } balance := blockchain.GetBalance(address) err = context.MemStore(resultOffset, balance) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -281,18 +294,19 @@ func (context *VMHooksImpl) GetExternalBalance(addressOffset executor.MemPtr, re // @autogenerate(VMHooks) func (context *VMHooksImpl) GetBlockHash(nonce int64, resultOffset executor.MemPtr) int32 { blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockHash err := metering.UseGasBoundedAndAddTracedGas(blockHashName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } hash := blockchain.BlockHash(uint64(nonce)) err = context.MemStore(resultOffset, hash) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -342,17 +356,18 @@ func (context *VMHooksImpl) GetESDTBalance( nonce int64, resultOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(getESDTBalanceName) esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = context.MemStore(resultOffset, esdtData.Value.Bytes()) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -367,17 +382,17 @@ func (context *VMHooksImpl) GetESDTNFTNameLength( tokenIDLen executor.MemLength, nonce int64, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(getESDTNFTNameLengthName) esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if esdtData == nil || esdtData.TokenMetaData == nil { - context.WithFault(vmhost.ErrNilESDTData, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(context.GetVMHost(), vmhost.ErrNilESDTData) return 0 } @@ -392,17 +407,17 @@ func (context *VMHooksImpl) GetESDTNFTAttributeLength( tokenIDLen executor.MemLength, nonce int64, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(getESDTNFTAttributeLengthName) esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if esdtData == nil || esdtData.TokenMetaData == nil { - context.WithFault(vmhost.ErrNilESDTData, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(context.GetVMHost(), vmhost.ErrNilESDTData) return 0 } @@ -417,17 +432,17 @@ func (context *VMHooksImpl) GetESDTNFTURILength( tokenIDLen executor.MemLength, nonce int64, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(getESDTNFTURILengthName) esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if esdtData == nil || esdtData.TokenMetaData == nil { - context.WithFault(vmhost.ErrNilESDTData, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(context.GetVMHost(), vmhost.ErrNilESDTData) return 0 } if len(esdtData.TokenMetaData.URIs) == 0 { @@ -454,13 +469,13 @@ func (context *VMHooksImpl) GetESDTTokenData( urisOffset executor.MemPtr, ) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(getESDTTokenDataName) esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -468,25 +483,30 @@ func (context *VMHooksImpl) GetESDTTokenData( value.Set(esdtData.Value) err = context.MemStore(propertiesOffset, esdtData.Properties) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if esdtData.TokenMetaData != nil { err = context.MemStore(hashOffset, esdtData.TokenMetaData.Hash) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = context.MemStore(nameOffset, esdtData.TokenMetaData.Name) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = context.MemStore(attributesOffset, esdtData.TokenMetaData.Attributes) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = context.MemStore(creatorOffset, esdtData.TokenMetaData.Creator) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -495,7 +515,8 @@ func (context *VMHooksImpl) GetESDTTokenData( if len(esdtData.TokenMetaData.URIs) > 0 { err = context.MemStore(urisOffset, esdtData.TokenMetaData.URIs[0]) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } } @@ -507,12 +528,12 @@ func (context *VMHooksImpl) GetESDTTokenData( // @autogenerate(VMHooks) func (context *VMHooksImpl) GetESDTLocalRoles(tokenIdHandle int32) int64 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() tokenID, err := managedType.GetBytes(tokenIdHandle) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -520,7 +541,8 @@ func (context *VMHooksImpl) GetESDTLocalRoles(tokenIdHandle int32) int64 { key := []byte(string(esdtRoleKeyPrefix) + string(tokenID)) data, trieDepth, usedCache, err := storage.GetStorage(key) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -529,7 +551,8 @@ func (context *VMHooksImpl) GetESDTLocalRoles(tokenIdHandle int32) int64 { int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.StorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -543,17 +566,18 @@ func (context *VMHooksImpl) ValidateTokenIdentifier( tokenIdHandle int32, ) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetArgument err := metering.UseGasBoundedAndAddTracedGas(validateTokenIdentifierName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } tokenID, err := managedType.GetBytes(tokenIdHandle) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -581,39 +605,45 @@ func (context *VMHooksImpl) TransferValue( gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return 1 } sender := runtime.GetContextAddress() dest, err := context.MemLoad(destOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } valueBytes, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.PersistPerByte, uint64(length)) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } if host.IsBuiltinFunctionCall(data) { - context.WithFault(vmhost.ErrTransferValueOnESDTCall, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrTransferValueOnESDTCall) return 1 } err = output.Transfer(dest, sender, 0, 0, big.NewInt(0).SetBytes(valueBytes), nil, data, vm.DirectCall) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -775,13 +805,15 @@ func (context *VMHooksImpl) TransferValueExecuteWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return 1 } callArgs, err := context.extractIndirectContractCallArgumentsWithValue( host, destOffset, valueOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -810,7 +842,9 @@ func TransferValueExecuteWithTypedArgs( gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -829,14 +863,15 @@ func TransferValueExecuteWithTypedArgs( gasToUse, false, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } } if contractCallInput != nil { if host.IsBuiltinFunctionName(contractCallInput.Function) { - WithFaultAndHost(host, vmhost.ErrNilESDTData, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNilESDTData) return 1 } } @@ -846,7 +881,7 @@ func TransferValueExecuteWithTypedArgs( vmOutput, err := executeOnDestContextFromAPI(host, contractCallInput) if err != nil { logEEI.Trace("eGLD pre-transfer execution failed", "error", err) - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return 1 } host.CompleteLogEntriesWithCallType(vmOutput, vmhost.TransferAndExecuteString) @@ -860,12 +895,14 @@ func TransferValueExecuteWithTypedArgs( } err = metering.UseGasBounded(uint64(gasLimit)) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } err = output.Transfer(dest, sender, uint64(gasLimit), 0, value, nil, []byte(data), vm.DirectCall) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -953,19 +990,21 @@ func (context *VMHooksImpl) MultiTransferESDTNFTExecute( metering.StartGasTracing(multiTransferESDTNFTExecuteName) if numTokenTransfers == 0 { - _ = WithFaultAndHost(host, vmhost.ErrFailedTransfer, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrFailedTransfer) return 1 } callArgs, err := context.extractIndirectContractCallArgumentsWithoutValue( host, destOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } gasToUse := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(callArgs.actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -976,13 +1015,15 @@ func (context *VMHooksImpl) MultiTransferESDTNFTExecute( tokenTransferDataOffset, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -1030,19 +1071,22 @@ func (context *VMHooksImpl) TransferESDTNFTExecuteWithHost( metering := host.Metering() tokenIdentifier, executeErr := context.MemLoad(tokenIDOffset, tokenIDLen) - if WithFaultAndHost(host, executeErr, runtime.BaseOpsErrorShouldFailExecution()) { + if executeErr != nil { + FailExecution(host, executeErr) return 1 } callArgs, err := context.extractIndirectContractCallArgumentsWithValue( host, destOffset, valueOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } gasToUse := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(callArgs.actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -1083,7 +1127,8 @@ func TransferESDTNFTExecuteWithTypedArgs( gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue * uint64(len(transfers)) err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -1102,7 +1147,8 @@ func TransferESDTNFTExecuteWithTypedArgs( gasToUse, false, ) - if WithFaultAndHost(host, executeErr, runtime.SyncExecAPIErrorShouldFailExecution()) { + if executeErr != nil { + FailExecution(host, executeErr) return 1 } @@ -1120,7 +1166,8 @@ func TransferESDTNFTExecuteWithTypedArgs( SenderForExec: sender, } gasLimitForExec, executeErr := output.TransferESDT(transfersArgs, contractCallInput) - if WithFaultAndHost(host, executeErr, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, executeErr) return 1 } @@ -1132,7 +1179,7 @@ func TransferESDTNFTExecuteWithTypedArgs( if executeErr != nil { logEEI.Trace("ESDT post-transfer execution failed", "error", executeErr) host.Blockchain().RevertToSnapshot(snapshotBeforeTransfer) - WithFaultAndHost(host, executeErr, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, executeErr) return 1 } @@ -1162,7 +1209,8 @@ func TransferESDTNFTExecuteByUserWithTypedArgs( gasToUse := metering.GasSchedule().BaseOpsAPICost.TransferValue * uint64(len(transfers)) err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.SyncExecAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -1181,7 +1229,8 @@ func TransferESDTNFTExecuteByUserWithTypedArgs( gasToUse, false, ) - if WithFaultAndHost(host, executeErr, runtime.SyncExecAPIErrorShouldFailExecution()) { + if executeErr != nil { + FailExecution(host, executeErr) return 1 } @@ -1197,7 +1246,8 @@ func TransferESDTNFTExecuteByUserWithTypedArgs( SenderForExec: callerForExecution, } gasLimitForExec, executeErr := output.TransferESDT(transfersArgs, contractCallInput) - if WithFaultAndHost(host, executeErr, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, executeErr) return 1 } @@ -1219,7 +1269,8 @@ func TransferESDTNFTExecuteByUserWithTypedArgs( ReturnAfterError: true, } _, executeErr = output.TransferESDT(returnTransferArgs, nil) - if WithFaultAndHost(host, executeErr, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, executeErr) return 1 } @@ -1274,30 +1325,34 @@ func (context *VMHooksImpl) CreateAsyncCallWithHost(host vmhost.VMHost, gas int64, extraGasForCallback int64, ) int32 { - runtime := host.Runtime() calledSCAddress, err := context.MemLoad(destOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } data, err := context.MemLoad(dataOffset, dataLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } successFunc, err := context.MemLoad(successOffset, successLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } errorFunc, err := context.MemLoad(errorOffset, errorLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -1331,7 +1386,8 @@ func CreateAsyncCallWithTypedArgs(host vmhost.VMHost, gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateAsyncCall err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -1350,13 +1406,15 @@ func CreateAsyncCallWithTypedArgs(host vmhost.VMHost, if asyncCall.HasDefinedAnyCallback() { gasToUse = metering.GasSchedule().BaseOpsAPICost.SetAsyncCallback err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } } err = async.RegisterAsyncCall("", asyncCall) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -1380,17 +1438,20 @@ func (context *VMHooksImpl) SetAsyncContextCallback( gasToUse := metering.GasSchedule().BaseOpsAPICost.SetAsyncContextCallback err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } callbackNameBytes, err := context.MemLoad(callback, callbackLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } dataBytes, err := context.MemLoad(data, dataLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -1398,7 +1459,8 @@ func (context *VMHooksImpl) SetAsyncContextCallback( string(callbackNameBytes), dataBytes, uint64(gas)) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -1426,22 +1488,26 @@ func (context *VMHooksImpl) UpgradeContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } code, err := context.MemLoad(codeOffset, length) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } codeMetadata, err := context.MemLoad(codeMetadataOffset, vmhost.CodeMetadataLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -1451,29 +1517,34 @@ func (context *VMHooksImpl) UpgradeContract( argumentsLengthOffset, dataOffset, ) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } calledSCAddress, err := context.MemLoad(destOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } gasSchedule := metering.GasSchedule() gasToUse = math.MulUint64(gasSchedule.BaseOperationCost.DataCopyPerByte, uint64(length)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } @@ -1499,22 +1570,26 @@ func (context *VMHooksImpl) UpgradeFromSourceContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } sourceContractAddress, err := context.MemLoad(sourceContractAddressOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } codeMetadata, err := context.MemLoad(codeMetadataOffset, vmhost.CodeMetadataLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -1524,22 +1599,26 @@ func (context *VMHooksImpl) UpgradeFromSourceContract( argumentsLengthOffset, dataOffset, ) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } calledSCAddress, err := context.MemLoad(destOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -1564,11 +1643,11 @@ func UpgradeFromSourceContractWithTypedArgs( gasLimit int64, codeMetadata []byte, ) { - runtime := host.Runtime() blockchain := host.Blockchain() code, err := blockchain.GetCode(sourceContractAddress) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -1615,7 +1694,8 @@ func upgradeContract( runtime.SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) return } - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } } @@ -1636,7 +1716,8 @@ func (context *VMHooksImpl) DeleteContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } @@ -1646,22 +1727,26 @@ func (context *VMHooksImpl) DeleteContract( argumentsLengthOffset, dataOffset, ) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } calledSCAddress, err := context.MemLoad(destOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -1707,7 +1792,8 @@ func deleteContract( runtime.SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) return } - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } } @@ -1729,28 +1815,33 @@ func (context *VMHooksImpl) AsyncCall( gasSchedule := metering.GasSchedule() gasToUse := gasSchedule.BaseOpsAPICost.AsyncCallStep err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } calledSCAddress, err := context.MemLoad(destOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } gasToUse = math.MulUint64(gasSchedule.BaseOperationCost.DataCopyPerByte, uint64(length)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -1759,7 +1850,8 @@ func (context *VMHooksImpl) AsyncCall( runtime.SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) return } - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -1772,13 +1864,14 @@ func (context *VMHooksImpl) GetArgumentLength(id int32) int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetArgument err := metering.UseGasBoundedAndAddTracedGas(getArgumentLengthName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } args := runtime.Arguments() if id < 0 || int32(len(args)) <= id { - context.WithFault(vmhost.ErrInvalidArgument, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInvalidArgument) return -1 } @@ -1793,18 +1886,20 @@ func (context *VMHooksImpl) GetArgument(id int32, argOffset executor.MemPtr) int gasToUse := metering.GasSchedule().BaseOpsAPICost.GetArgument err := metering.UseGasBoundedAndAddTracedGas(getArgumentName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } args := runtime.Arguments() if id < 0 || int32(len(args)) <= id { - context.WithFault(vmhost.ErrInvalidArgument, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInvalidArgument) return -1 } err = context.MemStore(argOffset, args[id]) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1819,13 +1914,15 @@ func (context *VMHooksImpl) GetFunction(functionOffset executor.MemPtr) int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetFunction err := metering.UseGasBoundedAndAddTracedGas(getFunctionName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } function := runtime.FunctionName() err = context.MemStore(functionOffset, []byte(function)) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1840,7 +1937,8 @@ func (context *VMHooksImpl) GetNumArguments() int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetNumArguments err := metering.UseGasBoundedAndAddTracedGas(getNumArgumentsName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1874,15 +1972,15 @@ func (context *VMHooksImpl) StorageStoreWithHost( dataOffset executor.MemPtr, dataLength executor.MemLength) int32 { - runtime := host.Runtime() - key, err := context.MemLoad(keyOffset, keyLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := context.MemLoad(dataOffset, dataLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1891,18 +1989,19 @@ func (context *VMHooksImpl) StorageStoreWithHost( // StorageStoreWithTypedArgs - storageStore with args already read from memory func StorageStoreWithTypedArgs(host vmhost.VMHost, key []byte, data []byte) int32 { - runtime := host.Runtime() storage := host.Storage() metering := host.Metering() gasToUse := metering.GasSchedule().BaseOpsAPICost.StorageStore err := metering.UseGasBoundedAndAddTracedGas(storageStoreName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } storageStatus, err := storage.SetStorage(key, data) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1912,17 +2011,18 @@ func StorageStoreWithTypedArgs(host vmhost.VMHost, key []byte, data []byte) int3 // StorageLoadLength VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) StorageLoadLength(keyOffset executor.MemPtr, keyLength executor.MemLength) int32 { - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, trieDepth, usedCache, err := storage.GetStorageUnmetered(key) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1931,7 +2031,8 @@ func (context *VMHooksImpl) StorageLoadLength(keyOffset executor.MemPtr, keyLeng int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.StorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1964,25 +2065,27 @@ func (context *VMHooksImpl) StorageLoadFromAddressWithHost( keyLength executor.MemLength, dataOffset executor.MemPtr) int32 { - runtime := host.Runtime() - key, err := context.MemLoad(keyOffset, keyLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } address, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := StorageLoadFromAddressWithTypedArgs(host, address, key) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } err = context.MemStore(dataOffset, data) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -2023,20 +2126,22 @@ func (context *VMHooksImpl) StorageLoad(keyOffset executor.MemPtr, keyLength exe // StorageLoadWithHost - storageLoad with host instead of pointer context func (context *VMHooksImpl) StorageLoadWithHost(host vmhost.VMHost, keyOffset executor.MemPtr, keyLength executor.MemLength, dataOffset executor.MemPtr) int32 { - runtime := host.Runtime() key, err := context.MemLoad(keyOffset, keyLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := StorageLoadWithWithTypedArgs(host, key) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } err = context.MemStore(dataOffset, data) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -2078,17 +2183,18 @@ func (context *VMHooksImpl) SetStorageLock(keyOffset executor.MemPtr, keyLength // SetStorageLockWithHost - setStorageLock with host instead of pointer context func (context *VMHooksImpl) SetStorageLockWithHost(host vmhost.VMHost, keyOffset executor.MemPtr, keyLength executor.MemLength, lockTimestamp int64) int32 { - runtime := host.Runtime() metering := host.Metering() gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64StorageStore err := metering.UseGasBoundedAndAddTracedGas(setStorageLockName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } key, err := context.MemLoad(keyOffset, keyLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -2097,13 +2203,13 @@ func (context *VMHooksImpl) SetStorageLockWithHost(host vmhost.VMHost, keyOffset // SetStorageLockWithTypedArgs - setStorageLock with args already read from memory func SetStorageLockWithTypedArgs(host vmhost.VMHost, key []byte, lockTimestamp int64) int32 { - runtime := host.Runtime() storage := host.Storage() timeLockKeyPrefix := string(storage.GetVmProtectedPrefix(vmhost.TimeLockKeyPrefix)) timeLockKey := vmhost.CustomStorageKey(timeLockKeyPrefix, key) bigTimestamp := big.NewInt(0).SetInt64(lockTimestamp) storageStatus, err := storage.SetProtectedStorage(timeLockKey, bigTimestamp.Bytes()) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } return int32(storageStatus) @@ -2112,18 +2218,19 @@ func SetStorageLockWithTypedArgs(host vmhost.VMHost, key []byte, lockTimestamp i // GetStorageLock VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetStorageLock(keyOffset executor.MemPtr, keyLength executor.MemLength) int64 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() storage := context.GetStorageContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.StorageLoad err := metering.UseGasBoundedAndAddTracedGas(getStorageLockName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2131,7 +2238,8 @@ func (context *VMHooksImpl) GetStorageLock(keyOffset executor.MemPtr, keyLength timeLockKey := vmhost.CustomStorageKey(timeLockKeyPrefix, key) data, trieDepth, usedCache, err := storage.GetStorage(timeLockKey) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2140,7 +2248,8 @@ func (context *VMHooksImpl) GetStorageLock(keyOffset executor.MemPtr, keyLength int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.StorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2181,14 +2290,16 @@ func (context *VMHooksImpl) GetCaller(resultOffset executor.MemPtr) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller err := metering.UseGasBoundedAndAddTracedGas(getCallerName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } caller := runtime.GetVMInput().CallerAddr err = context.MemStore(resultOffset, caller) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -2201,17 +2312,18 @@ func (context *VMHooksImpl) CheckNoPayment() { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(checkNoPaymentName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } vmInput := runtime.GetVMInput() if vmInput.CallValue.Sign() > 0 { - _ = context.WithFault(vmhost.ErrNonPayableFunctionEgld, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNonPayableFunctionEgld) return } if len(vmInput.ESDTTransfers) > 0 { - _ = context.WithFault(vmhost.ErrNonPayableFunctionEsdt, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNonPayableFunctionEsdt) return } } @@ -2224,7 +2336,8 @@ func (context *VMHooksImpl) GetCallValue(resultOffset executor.MemPtr) int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(callValueName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2232,7 +2345,8 @@ func (context *VMHooksImpl) GetCallValue(resultOffset executor.MemPtr) int32 { value = vmhost.PadBytesLeft(value, vmhost.BalanceLen) err = context.MemStore(resultOffset, value) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2252,12 +2366,12 @@ func (context *VMHooksImpl) GetESDTValue(resultOffset executor.MemPtr) int32 { // GetESDTValueByIndex VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetESDTValueByIndex(resultOffset executor.MemPtr, index int32) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getESDTValueByIndexName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2270,7 +2384,8 @@ func (context *VMHooksImpl) GetESDTValueByIndex(resultOffset executor.MemPtr, in } err = context.MemStore(resultOffset, value) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2290,12 +2405,12 @@ func (context *VMHooksImpl) GetESDTTokenName(resultOffset executor.MemPtr) int32 // GetESDTTokenNameByIndex VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetESDTTokenNameByIndex(resultOffset executor.MemPtr, index int32) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getESDTTokenNameByIndexName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2306,7 +2421,8 @@ func (context *VMHooksImpl) GetESDTTokenNameByIndex(resultOffset executor.MemPtr } err = context.MemStore(resultOffset, tokenName) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2330,7 +2446,8 @@ func (context *VMHooksImpl) GetESDTTokenNonceByIndex(index int32) int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getESDTTokenNonceByIndexName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2349,23 +2466,25 @@ func (context *VMHooksImpl) GetCurrentESDTNFTNonce( tokenIDOffset executor.MemPtr, tokenIDLen executor.MemLength) int64 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() storage := context.GetStorageContext() destination, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } tokenID, err := context.MemLoad(tokenIDOffset, tokenIDLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } key := []byte(core.ProtectedKeyPrefix + core.ESDTNFTLatestNonceIdentifier + string(tokenID)) data, trieDepth, _, err := storage.GetStorageFromAddress(destination, key) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -2374,7 +2493,8 @@ func (context *VMHooksImpl) GetCurrentESDTNFTNonce( int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.StorageLoad, false) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -2399,7 +2519,8 @@ func (context *VMHooksImpl) GetESDTTokenTypeByIndex(index int32) int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getESDTTokenTypeByIndexName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2418,7 +2539,8 @@ func (context *VMHooksImpl) GetNumESDTTransfers() int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getNumESDTTransfersName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2447,7 +2569,8 @@ func (context *VMHooksImpl) GetCallValueTokenNameByIndex( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(getCallValueTokenNameByIndexName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2463,12 +2586,14 @@ func (context *VMHooksImpl) GetCallValueTokenNameByIndex( callValue = vmhost.PadBytesLeft(callValue, vmhost.BalanceLen) err = context.MemStore(tokenNameOffset, tokenName) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = context.MemStore(callValueOffset, callValue) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2485,12 +2610,14 @@ func (context *VMHooksImpl) IsReservedFunctionName(nameHandle int32) int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.IsReservedFunctionName err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } name, err := managedTypes.GetBytes(nameHandle) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2520,24 +2647,27 @@ func (context *VMHooksImpl) WriteLog( if numTopics < 0 || dataLength < 0 { err := vmhost.ErrNegativeLength - context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) return } err := metering.UseGasBoundedAndAddTracedGas(writeLogName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } log, err := context.MemLoad(dataPointer, dataLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } topics := make([][]byte, numTopics) for i := int32(0); i < numTopics; i++ { topics[i], err = context.MemLoad(topicPtr.Offset(i*vmhost.HashLen), vmhost.HashLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -2566,12 +2696,14 @@ func (context *VMHooksImpl) WriteEventLog( topicLengthsOffset, topicOffset, ) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } data, err := context.MemLoad(dataOffset, dataLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -2581,7 +2713,8 @@ func (context *VMHooksImpl) WriteEventLog( uint64(topicDataTotalLen+dataLength)) gasToUse = math.AddUint64(gasToUse, gasForData) err = metering.UseGasBoundedAndAddTracedGas(writeEventLogName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -2596,7 +2729,8 @@ func (context *VMHooksImpl) GetBlockTimestamp() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockTimeStamp err := metering.UseGasBoundedAndAddTracedGas(getBlockTimestampName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2611,7 +2745,8 @@ func (context *VMHooksImpl) GetBlockNonce() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockNonce err := metering.UseGasBoundedAndAddTracedGas(getBlockNonceName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2626,7 +2761,8 @@ func (context *VMHooksImpl) GetBlockRound() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRound err := metering.UseGasBoundedAndAddTracedGas(getBlockRoundName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2641,7 +2777,8 @@ func (context *VMHooksImpl) GetBlockEpoch() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockEpoch err := metering.UseGasBoundedAndAddTracedGas(getBlockEpochName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2651,37 +2788,37 @@ func (context *VMHooksImpl) GetBlockEpoch() int64 { // GetBlockRandomSeed VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetBlockRandomSeed(pointer executor.MemPtr) { - runtime := context.GetRuntimeContext() blockchain := context.GetBlockchainContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRandomSeed err := metering.UseGasBoundedAndAddTracedGas(getBlockRandomSeedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } randomSeed := blockchain.CurrentRandomSeed() err = context.MemStore(pointer, randomSeed) - context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } // GetStateRootHash VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetStateRootHash(pointer executor.MemPtr) { - runtime := context.GetRuntimeContext() blockchain := context.GetBlockchainContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetStateRootHash err := metering.UseGasBoundedAndAddTracedGas(getStateRootHashName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } stateRootHash := blockchain.GetStateRootHash() err = context.MemStore(pointer, stateRootHash) - context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } // GetPrevBlockTimestamp VMHooks implementation. @@ -2692,7 +2829,8 @@ func (context *VMHooksImpl) GetPrevBlockTimestamp() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockTimeStamp err := metering.UseGasBoundedAndAddTracedGas(getPrevBlockTimestampName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2707,7 +2845,8 @@ func (context *VMHooksImpl) GetPrevBlockNonce() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockNonce err := metering.UseGasBoundedAndAddTracedGas(getPrevBlockNonceName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2722,7 +2861,8 @@ func (context *VMHooksImpl) GetPrevBlockRound() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRound err := metering.UseGasBoundedAndAddTracedGas(getPrevBlockRoundName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2737,7 +2877,8 @@ func (context *VMHooksImpl) GetPrevBlockEpoch() int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockEpoch err := metering.UseGasBoundedAndAddTracedGas(getPrevBlockEpochName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -2747,25 +2888,24 @@ func (context *VMHooksImpl) GetPrevBlockEpoch() int64 { // GetPrevBlockRandomSeed VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetPrevBlockRandomSeed(pointer executor.MemPtr) { - runtime := context.GetRuntimeContext() blockchain := context.GetBlockchainContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRandomSeed err := metering.UseGasBoundedAndAddTracedGas(getPrevBlockRandomSeedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } randomSeed := blockchain.LastRandomSeed() err = context.MemStore(pointer, randomSeed) - context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } // Finish VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) Finish(pointer executor.MemPtr, length executor.MemLength) { - runtime := context.GetRuntimeContext() output := context.GetOutputContext() metering := context.GetMeteringContext() metering.StartGasTracing(returnDataName) @@ -2775,12 +2915,13 @@ func (context *VMHooksImpl) Finish(pointer executor.MemPtr, length executor.MemL gasToUse = math.AddUint64(gasToUse, gas) err := metering.UseGasBounded(gasToUse) if err != nil { - _ = context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) return } data, err := context.MemLoad(pointer, length) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -2828,11 +2969,11 @@ func (context *VMHooksImpl) ExecuteOnSameContextWithHost( argumentsLengthOffset executor.MemPtr, dataOffset executor.MemPtr, ) int32 { - runtime := host.Runtime() callArgs, err := context.extractIndirectContractCallArgumentsWithValue( host, addressOffset, valueOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -2860,7 +3001,8 @@ func ExecuteOnSameContextWithTypedArgs( gasToUse := metering.GasSchedule().BaseOpsAPICost.ExecuteOnSameContext err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -2877,17 +3019,19 @@ func ExecuteOnSameContextWithTypedArgs( gasToUse, true, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } if host.IsBuiltinFunctionName(contractCallInput.Function) { - WithFaultAndHost(host, vmhost.ErrInvalidBuiltInFunctionCall, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInvalidBuiltInFunctionCall) return 1 } err = host.ExecuteOnSameContext(contractCallInput) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -2935,11 +3079,11 @@ func (context *VMHooksImpl) ExecuteOnDestContextWithHost( argumentsLengthOffset executor.MemPtr, dataOffset executor.MemPtr, ) int32 { - runtime := host.Runtime() callArgs, err := context.extractIndirectContractCallArgumentsWithValue( host, addressOffset, valueOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -2967,7 +3111,8 @@ func ExecuteOnDestContextWithTypedArgs( gasToUse := metering.GasSchedule().BaseOpsAPICost.ExecuteOnDestContext err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -2984,12 +3129,14 @@ func ExecuteOnDestContextWithTypedArgs( gasToUse, true, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } vmOutput, err := executeOnDestContextFromAPI(host, contractCallInput) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -3036,11 +3183,11 @@ func (context *VMHooksImpl) ExecuteReadOnlyWithHost( argumentsLengthOffset executor.MemPtr, dataOffset executor.MemPtr, ) int32 { - runtime := host.Runtime() callArgs, err := context.extractIndirectContractCallArgumentsWithoutValue( host, addressOffset, functionOffset, functionLength, numArguments, argumentsLengthOffset, dataOffset) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -3066,7 +3213,8 @@ func ExecuteReadOnlyWithTypedArguments( gasToUse := metering.GasSchedule().BaseOpsAPICost.ExecuteReadOnly err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -3083,12 +3231,13 @@ func ExecuteReadOnlyWithTypedArguments( gasToUse, true, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } if host.IsBuiltinFunctionName(contractCallInput.Function) { - WithFaultAndHost(host, vmhost.ErrInvalidBuiltInFunctionCall, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInvalidBuiltInFunctionCall) return 1 } @@ -3097,7 +3246,8 @@ func ExecuteReadOnlyWithTypedArguments( _, err = executeOnDestContextFromAPI(host, contractCallInput) runtime.SetReadOnly(wasReadOnly) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -3151,23 +3301,27 @@ func (context *VMHooksImpl) createContractWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } sender := runtime.GetContextAddress() value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } code, err := context.MemLoad(codeOffset, length) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } codeMetadata, err := context.MemLoad(codeMetadataOffset, vmhost.CodeMetadataLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -3177,25 +3331,29 @@ func (context *VMHooksImpl) createContractWithHost( argumentsLengthOffset, dataOffset, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } valueAsInt := big.NewInt(0).SetBytes(value) newAddress, err := createContract(sender, data, valueAsInt, gasLimit, code, codeMetadata, host, CreateContract) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = context.MemStore(resultOffset, newAddress) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -3221,22 +3379,26 @@ func (context *VMHooksImpl) DeployFromSourceContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } value, err := context.MemLoad(valueOffset, vmhost.BalanceLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sourceContractAddress, err := context.MemLoad(sourceContractAddressOffset, vmhost.AddressLen) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } codeMetadata, err := context.MemLoad(codeMetadataOffset, vmhost.CodeMetadataLen) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -3246,13 +3408,15 @@ func (context *VMHooksImpl) DeployFromSourceContract( argumentsLengthOffset, dataOffset, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(actualLen)) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -3265,12 +3429,14 @@ func (context *VMHooksImpl) DeployFromSourceContract( gasLimit, ) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = context.MemStore(resultAddressOffset, newAddress) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -3291,7 +3457,8 @@ func DeployFromSourceContractWithTypedArgs( blockchain := host.Blockchain() code, err := blockchain.GetCode(sourceContractAddress) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return nil, err } @@ -3340,7 +3507,8 @@ func (context *VMHooksImpl) GetNumReturnData() int32 { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetNumReturnData err := metering.UseGasBoundedAndAddTracedGas(getNumReturnDataName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -3351,19 +3519,19 @@ func (context *VMHooksImpl) GetNumReturnData() int32 { // GetReturnDataSize VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) GetReturnDataSize(resultID int32) int32 { - runtime := context.GetRuntimeContext() output := context.GetOutputContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetReturnDataSize err := metering.UseGasBoundedAndAddTracedGas(getReturnDataSizeName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } returnData := output.ReturnData() if resultID >= int32(len(returnData)) || resultID < 0 { - context.WithFault(vmhost.ErrInvalidArgument, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInvalidArgument) return 0 } @@ -3380,9 +3548,9 @@ func (context *VMHooksImpl) GetReturnData(resultID int32, dataOffset executor.Me return 0 } - runtime := context.GetRuntimeContext() err := context.MemStore(dataOffset, result) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -3395,13 +3563,14 @@ func GetReturnDataWithHostAndTypedArgs(host vmhost.VMHost, resultID int32) []byt gasToUse := metering.GasSchedule().BaseOpsAPICost.GetReturnData err := metering.UseGasBoundedAndAddTracedGas(getReturnDataName, gasToUse) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return nil } returnData := output.ReturnData() if resultID >= int32(len(returnData)) || resultID < 0 { - WithFaultAndHost(host, vmhost.ErrInvalidArgument, host.Runtime().BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInvalidArgument) return nil } @@ -3422,7 +3591,8 @@ func CleanReturnDataWithHost(host vmhost.VMHost) { gasToUse := metering.GasSchedule().BaseOpsAPICost.CleanReturnData err := metering.UseGasBoundedAndAddTracedGas(cleanReturnDataName, gasToUse) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -3443,7 +3613,8 @@ func DeleteFromReturnDataWithHost(host vmhost.VMHost, resultID int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.DeleteFromReturnData err := metering.UseGasBoundedAndAddTracedGas(deleteFromReturnDataName, gasToUse) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -3461,12 +3632,13 @@ func (context *VMHooksImpl) GetOriginalTxHash(dataOffset executor.MemPtr) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetOriginalTxHash err := metering.UseGasBoundedAndAddTracedGas(getOriginalTxHashName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = context.MemStore(dataOffset, runtime.GetOriginalTxHash()) - _ = context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } // GetCurrentTxHash VMHooks implementation. @@ -3477,12 +3649,13 @@ func (context *VMHooksImpl) GetCurrentTxHash(dataOffset executor.MemPtr) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCurrentTxHash err := metering.UseGasBoundedAndAddTracedGas(getCurrentTxHashName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = context.MemStore(dataOffset, runtime.GetCurrentTxHash()) - _ = context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } // GetPrevTxHash VMHooks implementation. @@ -3493,12 +3666,13 @@ func (context *VMHooksImpl) GetPrevTxHash(dataOffset executor.MemPtr) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetPrevTxHash err := metering.UseGasBoundedAndAddTracedGas(getPrevTxHashName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = context.MemStore(dataOffset, runtime.GetPrevTxHash()) - _ = context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(err) } func prepareIndirectContractCallInput( diff --git a/vmhost/vmhooks/bigFloatOps.go b/vmhost/vmhooks/bigFloatOps.go index 647bb4f4f..36661a2c5 100644 --- a/vmhost/vmhooks/bigFloatOps.go +++ b/vmhost/vmhooks/bigFloatOps.go @@ -46,18 +46,18 @@ func setResultIfNotInfinity(host vmhost.VMHost, result *big.Float, destinationHa managedType := host.ManagedTypes() runtime := host.Runtime() if result.IsInf() { - _ = WithFaultAndHost(host, vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) return } exponent := result.MantExp(nil) if managedType.BigFloatExpIsNotValid(exponent) { - _ = WithFaultAndHost(host, vmhost.ErrExponentTooBigOrTooSmall, runtime.BigFloatAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrExponentTooBigOrTooSmall, runtime.BigFloatAPIErrorShouldFailExecution()) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if WithFaultAndHost(host, err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.BigFloatAPIErrorShouldFailExecution()) { return } diff --git a/vmhost/vmhooks/bigIntOps.go b/vmhost/vmhooks/bigIntOps.go index e28b5447f..746ff9b68 100644 --- a/vmhost/vmhooks/bigIntOps.go +++ b/vmhost/vmhooks/bigIntOps.go @@ -152,7 +152,8 @@ func (context *VMHooksImpl) BigIntStorageLoadUnsigned(keyOffset executor.MemPtr, int64(trieDepth), metering.GasSchedule().BigIntAPICost.BigIntStorageLoadUnsigned, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -1216,12 +1217,12 @@ func BigIntToStringWithHost(host vmhost.VMHost, bigIntHandle int32, destinationH gasToUse := metering.GasSchedule().BigIntAPICost.BigIntFinishSigned err := metering.UseGasBoundedAndAddTracedGas(bigIntToStringName, gasToUse) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { return } value, err := managedType.GetBigInt(bigIntHandle) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { return } @@ -1229,7 +1230,7 @@ func BigIntToStringWithHost(host vmhost.VMHost, bigIntHandle int32, destinationH gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(resultStr))) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { return } diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index 5415f34b7..3f74c1729 100644 --- a/vmhost/vmhooks/cryptoei.go +++ b/vmhost/vmhooks/cryptoei.go @@ -229,23 +229,23 @@ func ManagedRipemd160WithHost(host vmhost.VMHost, inputHandle int32, outputHandl crypto := host.Crypto() err := metering.UseGasBoundedAndAddTracedGas(ripemd160Name, metering.GasSchedule().CryptoAPICost.Ripemd160) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } inputBytes, err := managedType.GetBytes(inputHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(inputBytes) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { return 1 } result, err := crypto.Ripemd160(inputBytes) if err != nil { - WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } @@ -350,37 +350,38 @@ func ManagedVerifyBLSWithHost( managedType := host.ManagedTypes() crypto := host.Crypto() err := useGasForCryptoVerify(metering, sigVerificationType) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } keyBytes, err := managedType.GetBytes(keyHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -401,7 +402,7 @@ func ManagedVerifyBLSWithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -479,43 +480,43 @@ func ManagedVerifyEd25519WithHost( gasToUse := metering.GasSchedule().CryptoAPICost.VerifyEd25519 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } keyBytes, err := managedType.GetBytes(keyHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } invalidSigErr := crypto.VerifyEd25519(keyBytes, msgBytes, sigBytes) if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -616,37 +617,38 @@ func ManagedVerifyCustomSecp256k1WithHost( crypto := host.Crypto() err := useGasForCryptoVerify(metering, verifyCryptoFunc) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } keyBytes, err := managedType.GetBytes(keyHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -659,7 +661,7 @@ func ManagedVerifyCustomSecp256k1WithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -768,17 +770,17 @@ func ManagedEncodeSecp256k1DerSignatureWithHost( gasToUse := metering.GasSchedule().CryptoAPICost.EncodeDERSig err := metering.UseGasBoundedAndAddTracedGas(encodeSecp256k1DerSignatureName, gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } r, err := managedType.GetBytes(rHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } s, err := managedType.GetBytes(sHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } @@ -1020,19 +1022,19 @@ func ManagedScalarBaseMultECWithHost( curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(len(data))*oneByteScalarGasCost err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } @@ -1050,23 +1052,23 @@ func commonScalarBaseMultEC( managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResultSBM, yResultSBM := ec.ScalarBaseMult(data) if !ec.IsOnCurve(xResultSBM, yResultSBM) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult.Set(xResultSBM) @@ -1156,19 +1158,19 @@ func ManagedScalarMultECWithHost( curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(len(data))*oneByteScalarGasCost err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } @@ -1190,29 +1192,29 @@ func commonScalarMultEC( metering.StartGasTracing(scalarMultECName) ec, err1 := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err1, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err1, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResult, yResult, err1 := managedType.GetTwoBigInt(xResultHandle, yResultHandle) x, y, err2 := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err1 != nil || err2 != nil { - _ = WithFaultAndHost(host, vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } if !ec.IsOnCurve(x, y) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } err := managedType.ConsumeGasForBigIntCopy(xResult, yResult, ec.P, ec.N, ec.B, ec.Gx, ec.Gy, x, y) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResultSM, yResultSM := ec.ScalarMult(x, y, data) if !ec.IsOnCurve(xResultSM, yResultSM) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult.Set(xResultSM) @@ -1272,7 +1274,7 @@ func ManagedMarshalECWithHost( ) int32 { result, err := commonMarshalEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = WithFaultAndHost(host, err, true) + _ = FailExecution(host, err, true) return -1 } @@ -1379,7 +1381,7 @@ func ManagedMarshalCompressedECWithHost( managedType := host.ManagedTypes() result, err := commonMarshalCompressedEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -1498,12 +1500,12 @@ func ManagedUnmarshalECWithHost( curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } @@ -1526,28 +1528,28 @@ func commonUnmarshalEC( managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } byteLen := (ec.BitSize + 7) / 8 if len(data) != 1+2*byteLen { - _ = WithFaultAndHost(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResultU, yResultU := elliptic.Unmarshal(ec, data) if xResultU == nil || yResultU == nil || !ec.IsOnCurve(xResultU, yResultU) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult.Set(xResultU) @@ -1623,17 +1625,17 @@ func ManagedUnmarshalCompressedECWithHost( curveMultiplier := managedType.GetUCompressed100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalCompressedECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return int32(len(data)) } @@ -1651,28 +1653,28 @@ func commonUnmarshalCompressedEC( managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } byteLen := (ec.BitSize+7)/8 + 1 if len(data) != byteLen { - _ = WithFaultAndHost(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } xResultUC, yResultUC := elliptic.UnmarshalCompressed(ec, data) if xResultUC == nil || yResultUC == nil || !ec.IsOnCurve(xResultUC, yResultUC) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } xResult.Set(xResultUC) @@ -1732,7 +1734,7 @@ func ManagedGenerateKeyECWithHost( runtime := host.Runtime() managedType := host.ManagedTypes() result, err := commonGenerateEC(host, xPubKeyHandle, yPubKeyHandle, ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return 1 } @@ -1844,12 +1846,12 @@ func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { gasToUse := metering.GasSchedule().CryptoAPICost.EllipticCurveNew err := metering.UseGasBoundedAndAddTracedGas(createECName, gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { return -1 } curveChoice := string(data[:]) @@ -1868,7 +1870,7 @@ func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { return managedType.PutEllipticCurve(curveParams) } - _ = WithFaultAndHost(host, vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } diff --git a/vmhost/vmhooks/manBufOps.go b/vmhost/vmhooks/manBufOps.go index f7b3ee650..4924af24b 100644 --- a/vmhost/vmhooks/manBufOps.go +++ b/vmhost/vmhooks/manBufOps.go @@ -185,16 +185,16 @@ func ManagedBufferCopyByteSliceWithHost(host vmhost.VMHost, sourceHandle int32, gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferCopyByteSlice err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } err = managedType.ConsumeGasForBytes(sourceBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -208,7 +208,7 @@ func ManagedBufferCopyByteSliceWithHost(host vmhost.VMHost, sourceHandle int32, gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(slice))) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -314,7 +314,7 @@ func (context *VMHooksImpl) ManagedBufferSetByteSliceWithHost( } data, err := context.MemLoad(dataOffset, dataLength) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -329,12 +329,12 @@ func ManagedBufferSetByteSliceWithTypedArgs(host vmhost.VMHost, mBufferHandle in metering.StartGasTracing(mBufferGetByteSliceName) err := managedType.ConsumeGasForBytes(data) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } bufferBytes, err := managedType.GetBytes(mBufferHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return 1 } @@ -523,7 +523,8 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntUnsigned err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntUnsignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -548,7 +549,8 @@ func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 { gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntSigned err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntSignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -572,7 +574,8 @@ func (context *VMHooksImpl) MBufferFromSmallIntUnsigned(mBufferHandle int32, val gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFromSmallIntUnsigned err := metering.UseGasBoundedAndAddTracedGas(mBufferFromSmallIntUnsignedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -588,7 +591,8 @@ func (context *VMHooksImpl) MBufferFromSmallIntSigned(mBufferHandle int32, value gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFromSmallIntSigned err := metering.UseGasBoundedAndAddTracedGas(mBufferFromSmallIntSignedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -733,7 +737,8 @@ func (context *VMHooksImpl) MBufferStorageLoad(keyHandle int32, destinationHandl int64(trieDepth), metering.GasSchedule().ManagedBufferAPICost.MBufferStorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } diff --git a/vmhost/vmhooks/managedei.go b/vmhost/vmhooks/managedei.go index 5543bd876..60d5e8ed4 100644 --- a/vmhost/vmhooks/managedei.go +++ b/vmhost/vmhooks/managedei.go @@ -57,7 +57,8 @@ func (context *VMHooksImpl) ManagedSCAddress(destinationHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetSCAddress err := metering.UseGasBoundedAndAddTracedGas(managedSCAddressName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -76,12 +77,14 @@ func (context *VMHooksImpl) ManagedOwnerAddress(destinationHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetOwnerAddress err := metering.UseGasBoundedAndAddTracedGas(managedOwnerAddressName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } owner, err := blockchain.GetOwnerAddress() - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -97,7 +100,8 @@ func (context *VMHooksImpl) ManagedCaller(destinationHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller err := metering.UseGasBoundedAndAddTracedGas(managedCallerName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -185,7 +189,8 @@ func (context *VMHooksImpl) ManagedWriteLog( metering.StartGasTracing(managedWriteLogName) topics, sumOfTopicByteLengths, err := managedType.ReadManagedVecOfManagedBuffers(topicsHandle) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -239,7 +244,8 @@ func (context *VMHooksImpl) ManagedGetStateRootHash(resultHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetStateRootHash err := metering.UseGasBoundedAndAddTracedGas(managedGetStateRootHashName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -255,7 +261,8 @@ func (context *VMHooksImpl) ManagedGetBlockRandomSeed(resultHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRandomSeed err := metering.UseGasBoundedAndAddTracedGas(managedGetBlockRandomSeedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -271,7 +278,8 @@ func (context *VMHooksImpl) ManagedGetPrevBlockRandomSeed(resultHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetBlockRandomSeed err := metering.UseGasBoundedAndAddTracedGas(managedGetPrevBlockRandomSeedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -288,7 +296,8 @@ func (context *VMHooksImpl) ManagedGetReturnData(resultID int32, resultHandle in gasToUse := metering.GasSchedule().BaseOpsAPICost.GetReturnData err := metering.UseGasBoundedAndAddTracedGas(managedGetReturnDataName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -310,14 +319,16 @@ func (context *VMHooksImpl) ManagedGetMultiESDTCallValue(multiCallValueHandle in gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(managedGetMultiESDTCallValueName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } esdtTransfers := runtime.GetVMInput().ESDTTransfers multiCallBytes := writeESDTTransfersToBytes(managedType, esdtTransfers) err = managedType.ConsumeGasForBytes(multiCallBytes) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -332,14 +343,16 @@ func (context *VMHooksImpl) ManagedGetBackTransfers(esdtTransfersValueHandle int gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallValue err := metering.UseGasBoundedAndAddTracedGas(managedGetMultiESDTCallValueName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } esdtTransfers, transferValue := managedType.GetBackTransfers() multiCallBytes := writeESDTTransfersToBytes(managedType, esdtTransfers) err = managedType.ConsumeGasForBytes(multiCallBytes) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -358,7 +371,8 @@ func (context *VMHooksImpl) ManagedGetESDTBalance(addressHandle int32, tokenIDHa gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(managedGetESDTBalanceName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -414,24 +428,24 @@ func ManagedGetESDTTokenDataWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return } address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -442,29 +456,34 @@ func ManagedGetESDTTokenDataWithHost( if esdtToken.TokenMetaData != nil { managedType.SetBytes(hashHandle, esdtToken.TokenMetaData.Hash) err = managedType.ConsumeGasForBytes(esdtToken.TokenMetaData.Hash) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } managedType.SetBytes(nameHandle, esdtToken.TokenMetaData.Name) err = managedType.ConsumeGasForBytes(esdtToken.TokenMetaData.Name) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } managedType.SetBytes(attributesHandle, esdtToken.TokenMetaData.Attributes) err = managedType.ConsumeGasForBytes(esdtToken.TokenMetaData.Attributes) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } managedType.SetBytes(creatorHandle, esdtToken.TokenMetaData.Creator) err = managedType.ConsumeGasForBytes(esdtToken.TokenMetaData.Creator) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } royalties := managedType.GetBigIntOrCreate(royaltiesHandle) royalties.SetUint64(uint64(esdtToken.TokenMetaData.Royalties)) err = managedType.WriteManagedVecOfManagedBuffers(esdtToken.TokenMetaData.URIs, urisHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } } @@ -502,12 +521,14 @@ func ManagedAsyncCallWithHost( gasSchedule := metering.GasSchedule() gasToUse := gasSchedule.BaseOpsAPICost.AsyncCallStep err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } vmInput, err := readDestinationFunctionArguments(host, destHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -515,13 +536,14 @@ func ManagedAsyncCallWithHost( value, err := managedType.GetBigInt(valueHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, host.Runtime().BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrArgOutOfRange, host.Runtime().BaseOpsErrorShouldFailExecution()) return } gasToUse = math.MulUint64(gasSchedule.BaseOperationCost.DataCopyPerByte, uint64(len(data))) err = metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } @@ -530,7 +552,8 @@ func ManagedAsyncCallWithHost( runtime.SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) return } - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } } @@ -556,7 +579,8 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( managedType := host.ManagedTypes() vmInput, err := readDestinationFunctionArguments(host, destHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -569,17 +593,20 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( } successFunc, err := context.MemLoad(successOffset, successLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } errorFunc, err := context.MemLoad(errorOffset, errorLength) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } callbackClosure, err := managedType.GetBytes(callbackClosureHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -616,12 +643,13 @@ func GetCallbackClosureWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallbackClosure err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { return } callbackClosure, err := async.GetCallbackClosure() - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -652,17 +680,20 @@ func (context *VMHooksImpl) ManagedUpgradeFromSourceContract( } vmInput, err := readDestinationValueArguments(host, destHandle, valueHandle, argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } sourceContractAddress, err := managedType.GetBytes(addressHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } codeMetadata, err := managedType.GetBytes(codeMetadataHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -678,7 +709,8 @@ func (context *VMHooksImpl) ManagedUpgradeFromSourceContract( codeMetadata, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } } @@ -707,21 +739,25 @@ func (context *VMHooksImpl) ManagedUpgradeContract( } vmInput, err := readDestinationValueArguments(host, destHandle, valueHandle, argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } codeMetadata, err := managedType.GetBytes(codeMetadataHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } code, err := managedType.GetBytes(codeHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -729,7 +765,8 @@ func (context *VMHooksImpl) ManagedUpgradeContract( upgradeContract(host, vmInput.destination, code, codeMetadata, vmInput.value.Bytes(), vmInput.arguments, gas) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } } @@ -763,17 +800,20 @@ func ManagedDeleteContractWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return } calledSCAddress, err := managedType.GetBytes(destHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } data, _, err := managedType.ReadManagedVecOfManagedBuffers(argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -809,12 +849,14 @@ func (context *VMHooksImpl) ManagedDeployFromSourceContract( } vmInput, err := readDestinationValueArguments(host, addressHandle, valueHandle, argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } codeMetadata, err := managedType.GetBytes(codeMetadataHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -828,13 +870,15 @@ func (context *VMHooksImpl) ManagedDeployFromSourceContract( vmInput.arguments, gas, ) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } managedType.SetBytes(resultAddressHandle, newAddress) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -866,12 +910,14 @@ func (context *VMHooksImpl) ManagedCreateContract( sender := runtime.GetContextAddress() value, err := managedType.GetBigInt(valueHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } data, actualLen, err := managedType.ReadManagedVecOfManagedBuffers(argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -882,24 +928,28 @@ func (context *VMHooksImpl) ManagedCreateContract( } codeMetadata, err := managedType.GetBytes(codeMetadataHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } code, err := managedType.GetBytes(codeHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } lenReturnData := len(host.Output().ReturnData()) newAddress, err := createContract(sender, data, value, gas, code, codeMetadata, host, CreateContract) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } managedType.SetBytes(resultAddressHandle, newAddress) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return 1 } @@ -934,7 +984,8 @@ func (context *VMHooksImpl) ManagedExecuteReadOnly( metering.StartGasTracing(managedExecuteReadOnlyName) vmInput, err := readDestinationFunctionArguments(host, addressHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -947,7 +998,7 @@ func (context *VMHooksImpl) ManagedExecuteReadOnly( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { return -1 } @@ -969,7 +1020,8 @@ func (context *VMHooksImpl) ManagedExecuteOnSameContext( metering.StartGasTracing(managedExecuteOnSameContextName) vmInput, err := readDestinationValueFunctionArguments(host, addressHandle, valueHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -983,7 +1035,7 @@ func (context *VMHooksImpl) ManagedExecuteOnSameContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { return -1 } @@ -1005,7 +1057,8 @@ func (context *VMHooksImpl) ManagedExecuteOnDestContext( metering.StartGasTracing(managedExecuteOnDestContextName) vmInput, err := readDestinationValueFunctionArguments(host, addressHandle, valueHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1019,7 +1072,7 @@ func (context *VMHooksImpl) ManagedExecuteOnDestContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { return -1 } @@ -1042,12 +1095,14 @@ func (context *VMHooksImpl) ManagedMultiTransferESDTNFTExecute( metering.StartGasTracing(managedMultiTransferESDTNFTExecuteName) vmInput, err := readDestinationFunctionArguments(host, dstHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } transfers, err := readESDTTransfers(managedType, runtime, tokenTransfersHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1078,22 +1133,25 @@ func (context *VMHooksImpl) ManagedMultiTransferESDTNFTExecuteByUser( metering.StartGasTracing(managedMultiTransferESDTNFTExecuteByUser) if !host.IsAllowedToExecute(managedMultiTransferESDTNFTExecuteByUser) { - _ = WithFaultAndHost(host, vmhost.ErrOpcodeIsNotAllowed, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, vmhost.ErrOpcodeIsNotAllowed, runtime.BaseOpsErrorShouldFailExecution()) return -1 } user, err := managedType.GetBytes(userHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } vmInput, err := readDestinationFunctionArguments(host, dstHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } transfers, err := readESDTTransfers(managedType, runtime, tokenTransfersHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1122,7 +1180,8 @@ func (context *VMHooksImpl) ManagedTransferValueExecute( metering.StartGasTracing(managedTransferValueExecuteName) vmInput, err := readDestinationValueFunctionArguments(host, dstHandle, valueHandle, functionHandle, argumentsHandle) - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1158,24 +1217,25 @@ func ManagedIsESDTFrozenWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(managedIsESDTFrozenName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } @@ -1201,13 +1261,14 @@ func ManagedIsESDTLimitedTransferWithHost(host vmhost.VMHost, tokenIDHandle int3 gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(managedIsESDTLimitedTransferName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } @@ -1233,13 +1294,14 @@ func ManagedIsESDTPausedWithHost(host vmhost.VMHost, tokenIDHandle int32) int32 gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(managedIsESDTPausedName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } @@ -1264,13 +1326,14 @@ func ManagedBufferToHexWithHost(host vmhost.VMHost, sourceHandle int32, destHand gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferSetBytes err := metering.UseGasBoundedAndAddTracedGas(managedBufferToHexName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } mBuff, err := managedType.GetBytes(sourceHandle) if err != nil { - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -1292,25 +1355,27 @@ func ManagedGetCodeMetadataWithHost(host vmhost.VMHost, addressHandle int32, res gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCodeMetadata err := metering.UseGasBoundedAndAddTracedGas(managedGetCodeMetadataName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } gasToUse = metering.GasSchedule().ManagedBufferAPICost.MBufferSetBytes err = metering.UseGasBoundedAndAddTracedGas(managedGetCodeMetadataName, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } mBuffAddress, err := managedType.GetBytes(addressHandle) if err != nil { - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return } contract, err := host.Blockchain().GetUserAccount(mBuffAddress) if err != nil || check.IfNil(contract) { - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -1333,13 +1398,14 @@ func ManagedIsBuiltinFunctionWithHost(host vmhost.VMHost, functionNameHandle int gasToUse := metering.GasSchedule().BaseOpsAPICost.IsBuiltinFunction err := metering.UseGasBoundedAndAddTracedGas(managedIsBuiltinFunction, gasToUse) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } mBuffFunctionName, err := managedType.GetBytes(functionNameHandle) if err != nil { - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) return -1 } diff --git a/vmhost/vmhooks/smallIntOps.go b/vmhost/vmhooks/smallIntOps.go index 0fa179457..6f1a9ea68 100644 --- a/vmhost/vmhooks/smallIntOps.go +++ b/vmhost/vmhooks/smallIntOps.go @@ -85,7 +85,8 @@ func (context *VMHooksImpl) SmallIntFinishUnsigned(value int64) { gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64Finish err := metering.UseGasBoundedAndAddTracedGas(smallIntFinishUnsignedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -101,7 +102,8 @@ func (context *VMHooksImpl) SmallIntFinishSigned(value int64) { gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64Finish err := metering.UseGasBoundedAndAddTracedGas(smallIntFinishSignedName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -118,18 +120,21 @@ func (context *VMHooksImpl) SmallIntStorageStoreUnsigned(keyOffset executor.MemP gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64StorageStore err := metering.UseGasBoundedAndAddTracedGas(smallIntStorageStoreSignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } valueBytes := big.NewInt(0).SetUint64(uint64(value)).Bytes() storageStatus, err := storage.SetStorage(key, valueBytes) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -145,18 +150,21 @@ func (context *VMHooksImpl) SmallIntStorageStoreSigned(keyOffset executor.MemPtr gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64StorageStore err := metering.UseGasBoundedAndAddTracedGas(smallIntStorageStoreSignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } valueBytes := twos.ToBytes(big.NewInt(value)) storageStatus, err := storage.SetStorage(key, valueBytes) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -171,12 +179,14 @@ func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPt metering := context.GetMeteringContext() key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } data, trieDepth, usedCache, err := storage.GetStorage(key) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -185,7 +195,8 @@ func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPt int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.Int64StorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -206,12 +217,14 @@ func (context *VMHooksImpl) SmallIntStorageLoadSigned(keyOffset executor.MemPtr, metering := context.GetMeteringContext() key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } data, trieDepth, usedCache, err := storage.GetStorage(key) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -220,7 +233,8 @@ func (context *VMHooksImpl) SmallIntStorageLoadSigned(keyOffset executor.MemPtr, int64(trieDepth), metering.GasSchedule().BaseOpsAPICost.Int64StorageLoad, usedCache) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } diff --git a/vmhost/vmhooks/vmHooksImpl.go b/vmhost/vmhooks/vmHooksImpl.go index 2466eb2f1..8d5b5e07e 100644 --- a/vmhost/vmhooks/vmHooksImpl.go +++ b/vmhost/vmhooks/vmHooksImpl.go @@ -92,22 +92,15 @@ func (context *VMHooksImpl) GetStorageContext() vmhost.StorageContext { return context.host.Storage() } -// WithFault handles an error, taking into account whether it should completely -// fail the execution of a contract or not. -func (context *VMHooksImpl) WithFault(err error, failExecution bool) bool { - return WithFaultAndHost(context.host, err, failExecution) +// FailExecution fails the execution with the provided error +func (context *VMHooksImpl) FailExecution(err error) { + FailExecution(context.host, err) } -// WithFaultAndHost fails the execution with the provided error -func WithFaultAndHost(host vmhost.VMHost, err error, failExecution bool) bool { - if err == nil || !failExecution { - return false - } - +// FailExecution fails the execution with the provided error +func FailExecution(host vmhost.VMHost, err error) { runtime := host.Runtime() metering := host.Metering() _ = metering.UseGasBounded(metering.GasLeft()) runtime.FailExecution(err) - - return true } diff --git a/vmhost/vmhookstest/manMaps_test.go b/vmhost/vmhookstest/manMaps_test.go index c3de78c46..6e76734ec 100644 --- a/vmhost/vmhookstest/manMaps_test.go +++ b/vmhost/vmhookstest/manMaps_test.go @@ -28,7 +28,7 @@ func TestManagedMap(t *testing.T) { valueBuff := managedType.NewManagedBufferFromBytes(value) err := managedType.ManagedMapPut(mMap, keyBuff, valueBuff) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } @@ -36,19 +36,19 @@ func TestManagedMap(t *testing.T) { make([]byte, len(value))) err = managedType.ManagedMapGet(mMap, keyBuff, outValueBuf) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } outValueBytes, err := managedType.GetBytes(outValueBuf) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } host.Output().Finish(outValueBytes) contains, err := managedType.ManagedMapContains(mMap, keyBuff) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } if contains { @@ -61,14 +61,14 @@ func TestManagedMap(t *testing.T) { make([]byte, len(value))) err = managedType.ManagedMapRemove(mMap, keyBuff, outValueBuf) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } host.Output().Finish(outValueBytes) containsAfterRemove, err := managedType.ManagedMapContains(mMap, keyBuff) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } if containsAfterRemove { @@ -81,12 +81,12 @@ func TestManagedMap(t *testing.T) { make([]byte, len(value))) err = managedType.ManagedMapGet(mMap, keyBuff, outValueBuf) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } outValueBytes, err = managedType.GetBytes(outValueBuf) if err != nil { - vmhooks.WithFaultAndHost(host, err, true) + vmhooks.FailExecution(host, err) return instance } host.Output().Finish(outValueBytes) From 27ca17672ceeba9f574c3136ce63029e1e5c88f7 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 13:07:48 +0300 Subject: [PATCH 2/7] fixing after merge --- vmhost/vmhooks/bigFloatOps.go | 239 ++++++++++++--------- vmhost/vmhooks/bigIntOps.go | 390 ++++++++++++++++++++-------------- vmhost/vmhooks/cryptoei.go | 53 ++--- vmhost/vmhooks/manBufOps.go | 29 +-- vmhost/vmhooks/managedei.go | 10 +- vmhost/vmhooks/smallIntOps.go | 12 +- 6 files changed, 429 insertions(+), 304 deletions(-) diff --git a/vmhost/vmhooks/bigFloatOps.go b/vmhost/vmhooks/bigFloatOps.go index 36661a2c5..f2a0dfe13 100644 --- a/vmhost/vmhooks/bigFloatOps.go +++ b/vmhost/vmhooks/bigFloatOps.go @@ -44,20 +44,20 @@ func areAllZero(values ...*big.Float) bool { func setResultIfNotInfinity(host vmhost.VMHost, result *big.Float, destinationHandle int32) { managedType := host.ManagedTypes() - runtime := host.Runtime() if result.IsInf() { - _ = FailExecution(host, vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInfinityFloatOperation) return } exponent := result.MantExp(nil) if managedType.BigFloatExpIsNotValid(exponent) { - _ = FailExecution(host, vmhost.ErrExponentTooBigOrTooSmall, runtime.BigFloatAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrExponentTooBigOrTooSmall) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if FailExecution(host, err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -68,17 +68,21 @@ func setResultIfNotInfinity(host vmhost.VMHost, result *big.Float, destinationHa // @autogenerate(VMHooks) func (context *VMHooksImpl) BigFloatNewFromParts(integralPart, fractionalPart, exponent int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatNewFromParts err := metering.UseGasBoundedAndAddTracedGas(bigFloatNewFromPartsName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) + return -1 + } + if err != nil { + context.FailExecution(err) return -1 } if exponent > 0 { - _ = context.WithFault(vmhost.ErrPositiveExponent, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPositiveExponent) return -1 } @@ -89,7 +93,8 @@ func (context *VMHooksImpl) BigFloatNewFromParts(integralPart, fractionalPart, e bigFractionalPart := big.NewFloat(float64(fractionalPart)) bigExponentMultiplier := big.NewFloat(math.Pow10(int(exponent))) bigFractional, err = vmMath.MulBigFloat(bigFractionalPart, bigExponentMultiplier) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } } @@ -97,17 +102,20 @@ func (context *VMHooksImpl) BigFloatNewFromParts(integralPart, fractionalPart, e var value *big.Float if integralPart >= 0 { value, err = vmMath.AddBigFloat(big.NewFloat(float64(integralPart)), bigFractional) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } } else { value, err = vmMath.SubBigFloat(big.NewFloat(float64(integralPart)), bigFractional) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } } handle, err := managedType.PutBigFloat(value) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return handle @@ -117,28 +125,30 @@ func (context *VMHooksImpl) BigFloatNewFromParts(integralPart, fractionalPart, e // @autogenerate(VMHooks) func (context *VMHooksImpl) BigFloatNewFromFrac(numerator, denominator int64) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatNewFromParts err := metering.UseGasBoundedAndAddTracedGas(bigFloatNewFromFracName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if denominator == 0 { - _ = context.WithFault(vmhost.ErrDivZero, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrDivZero) return -1 } bigNumerator := big.NewFloat(float64(numerator)) bigDenominator := big.NewFloat(float64(denominator)) value, err := vmMath.QuoBigFloat(bigNumerator, bigDenominator) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } handle, err := managedType.PutBigFloat(value) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return handle @@ -148,22 +158,23 @@ func (context *VMHooksImpl) BigFloatNewFromFrac(numerator, denominator int64) in // @autogenerate(VMHooks) func (context *VMHooksImpl) BigFloatNewFromSci(significand, exponent int64) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatNewFromParts err := metering.UseGasBoundedAndAddTracedGas(bigFloatNewFromSciName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if exponent > 0 { - _ = context.WithFault(vmhost.ErrPositiveExponent, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPositiveExponent) return -1 } if exponent < -322 { handle, err := managedType.PutBigFloat(big.NewFloat(0)) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return handle @@ -172,11 +183,13 @@ func (context *VMHooksImpl) BigFloatNewFromSci(significand, exponent int64) int3 bigSignificand := big.NewFloat(float64(significand)) bigExponentMultiplier := big.NewFloat(math.Pow10(int(exponent))) value, err := vmMath.MulBigFloat(bigSignificand, bigExponentMultiplier) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } handle, err := managedType.PutBigFloat(value) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return handle @@ -187,22 +200,24 @@ func (context *VMHooksImpl) BigFloatNewFromSci(significand, exponent int64) int3 func (context *VMHooksImpl) BigFloatAdd(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatAddName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatAdd err := metering.UseGasBoundedAndAddTracedGas(bigFloatAddName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op1, op2, err := managedType.GetTwoBigFloats(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } resultAdd, err := vmMath.AddBigFloat(op1, op2) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -214,22 +229,24 @@ func (context *VMHooksImpl) BigFloatAdd(destinationHandle, op1Handle, op2Handle func (context *VMHooksImpl) BigFloatSub(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatSubName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatSub err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op1, op2, err := managedType.GetTwoBigFloats(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } resultSub, err := vmMath.SubBigFloat(op1, op2) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } setResultIfNotInfinity(context.GetVMHost(), resultSub, destinationHandle) @@ -240,23 +257,25 @@ func (context *VMHooksImpl) BigFloatSub(destinationHandle, op1Handle, op2Handle func (context *VMHooksImpl) BigFloatMul(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatMulName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatMul err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op1, op2, err := managedType.GetTwoBigFloats(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } resultMul, err := vmMath.MulBigFloat(op1, op2) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } setResultIfNotInfinity(context.GetVMHost(), resultMul, destinationHandle) @@ -267,27 +286,29 @@ func (context *VMHooksImpl) BigFloatMul(destinationHandle, op1Handle, op2Handle func (context *VMHooksImpl) BigFloatDiv(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatDivName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatDiv err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op1, op2, err := managedType.GetTwoBigFloats(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if areAllZero(op1, op2) { - _ = context.WithFault(vmhost.ErrAllOperandsAreEqualToZero, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrAllOperandsAreEqualToZero) return } resultDiv, err := vmMath.QuoBigFloat(op1, op2) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } setResultIfNotInfinity(context.GetVMHost(), resultDiv, destinationHandle) @@ -298,22 +319,24 @@ func (context *VMHooksImpl) BigFloatDiv(destinationHandle, op1Handle, op2Handle func (context *VMHooksImpl) BigFloatNeg(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatNegName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatNeg err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest.Neg(op) @@ -324,22 +347,24 @@ func (context *VMHooksImpl) BigFloatNeg(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatClone(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatCloneName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatClone err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest.Copy(op) @@ -350,18 +375,19 @@ func (context *VMHooksImpl) BigFloatClone(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatCmp(op1Handle, op2Handle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatCmpName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatCmp err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } op1, op2, err := managedType.GetTwoBigFloats(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } return int32(op1.Cmp(op2)) @@ -372,22 +398,24 @@ func (context *VMHooksImpl) BigFloatCmp(op1Handle, op2Handle int32) int32 { func (context *VMHooksImpl) BigFloatAbs(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatAbsName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatAbs err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest.Abs(op) @@ -398,16 +426,17 @@ func (context *VMHooksImpl) BigFloatAbs(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatSign(opHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatAbs err := metering.UseGasBoundedAndAddTracedGas(bigFloatSignName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } return int32(op.Sign()) @@ -418,30 +447,33 @@ func (context *VMHooksImpl) BigFloatSign(opHandle int32) int32 { func (context *VMHooksImpl) BigFloatSqrt(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatSqrtName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatSqrt err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if op.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBadLowerBounds, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadLowerBounds) return } resultSqrt, err := vmMath.SqrtBigFloat(op) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest.Set(resultSqrt) @@ -452,17 +484,18 @@ func (context *VMHooksImpl) BigFloatSqrt(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatPow(destinationHandle, opHandle, exponent int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatPowName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatPow err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -476,12 +509,14 @@ func (context *VMHooksImpl) BigFloatPow(destinationHandle, opHandle, exponent in //this calculates the length of the result in bytes lengthOfResult := big.NewInt(0).Div(big.NewInt(0).Mul(op2BigInt, big.NewInt(int64(opBigInt.BitLen()))), big.NewInt(8)) err = managedType.ConsumeGasForThisBigIntNumberOfBytes(lengthOfResult) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } powResult, err := context.pow(op, exponent) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } setResultIfNotInfinity(context.GetVMHost(), powResult, destinationHandle) @@ -511,23 +546,25 @@ func (context *VMHooksImpl) pow(base *big.Float, exp int32) (*big.Float, error) func (context *VMHooksImpl) BigFloatFloor(destBigIntHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatFloorName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatFloor err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigIntOp := managedType.GetBigIntOrCreate(destBigIntHandle) err = managedType.ConsumeGasForBigIntCopy(bigIntOp) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -545,23 +582,25 @@ func (context *VMHooksImpl) BigFloatFloor(destBigIntHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatCeil(destBigIntHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatCeilName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatCeil err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigIntOp := managedType.GetBigIntOrCreate(destBigIntHandle) err = managedType.ConsumeGasForBigIntCopy(bigIntOp) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -579,23 +618,25 @@ func (context *VMHooksImpl) BigFloatCeil(destBigIntHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatTruncate(destBigIntHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatTruncateName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatTruncate err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigIntValue := managedType.GetBigIntOrCreate(destBigIntHandle) err = managedType.ConsumeGasForBigIntCopy(bigIntValue) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -607,16 +648,17 @@ func (context *VMHooksImpl) BigFloatTruncate(destBigIntHandle, opHandle int32) { func (context *VMHooksImpl) BigFloatSetInt64(destinationHandle int32, value int64) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatSetInt64 err := metering.UseGasBoundedAndAddTracedGas(bigFloatSetInt64Name, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest.SetInt64(value) @@ -627,17 +669,18 @@ func (context *VMHooksImpl) BigFloatSetInt64(destinationHandle int32, value int6 func (context *VMHooksImpl) BigFloatIsInt(opHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatIsIntName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatIsInt err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } op, err := managedType.GetBigFloat(opHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if op.IsInt() { @@ -651,22 +694,24 @@ func (context *VMHooksImpl) BigFloatIsInt(opHandle int32) int32 { func (context *VMHooksImpl) BigFloatSetBigInt(destinationHandle, bigIntHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigFloatSetBigIntName) gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatSetBigInt err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigIntValue, err := managedType.GetBigInt(bigIntHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(bigIntValue) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -679,16 +724,17 @@ func (context *VMHooksImpl) BigFloatSetBigInt(destinationHandle, bigIntHandle in func (context *VMHooksImpl) BigFloatGetConstPi(destinationHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatGetConst err := metering.UseGasBoundedAndAddTracedGas(bigFloatGetConstPiName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } pi, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } pi.SetFloat64(math.Pi) @@ -699,16 +745,17 @@ func (context *VMHooksImpl) BigFloatGetConstPi(destinationHandle int32) { func (context *VMHooksImpl) BigFloatGetConstE(destinationHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatGetConst err := metering.UseGasBoundedAndAddTracedGas(bigFloatGetConstEName, gasToUse) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } e, err := managedType.GetBigFloatOrCreate(destinationHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } e.SetFloat64(math.E) diff --git a/vmhost/vmhooks/bigIntOps.go b/vmhost/vmhooks/bigIntOps.go index 746ff9b68..99cebf0c6 100644 --- a/vmhost/vmhooks/bigIntOps.go +++ b/vmhost/vmhooks/bigIntOps.go @@ -63,7 +63,8 @@ func (context *VMHooksImpl) BigIntGetUnsignedArgument(id int32, destinationHandl gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetUnsignedArgument err := metering.UseGasBoundedAndAddTracedGas(bigIntGetUnsignedArgumentName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -86,7 +87,8 @@ func (context *VMHooksImpl) BigIntGetSignedArgument(id int32, destinationHandle gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetSignedArgument err := metering.UseGasBoundedAndAddTracedGas(bigIntGetSignedArgumentName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -104,18 +106,19 @@ func (context *VMHooksImpl) BigIntGetSignedArgument(id int32, destinationHandle // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntStorageStoreUnsigned(keyOffset executor.MemPtr, keyLength executor.MemLength, sourceHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntStorageStoreUnsigned err := metering.UseGasBoundedAndAddTracedGas(bigIntStorageStoreUnsignedName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -123,7 +126,8 @@ func (context *VMHooksImpl) BigIntStorageStoreUnsigned(keyOffset executor.MemPtr bytes := value.Bytes() storageStatus, err := storage.SetStorage(key, bytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -134,17 +138,18 @@ func (context *VMHooksImpl) BigIntStorageStoreUnsigned(keyOffset executor.MemPtr // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntStorageLoadUnsigned(keyOffset executor.MemPtr, keyLength executor.MemLength, destinationHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } bytes, trieDepth, usedCache, err := storage.GetStorage(key) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -172,7 +177,8 @@ func (context *VMHooksImpl) BigIntGetCallValue(destinationHandle int32) { gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetCallValue err := metering.UseGasBoundedAndAddTracedGas(bigIntGetCallValueName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -198,7 +204,8 @@ func (context *VMHooksImpl) BigIntGetESDTCallValueByIndex(destinationHandle int3 gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetCallValue err := metering.UseGasBoundedAndAddTracedGas(bigIntGetESDTCallValueByIndexName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -215,18 +222,19 @@ func (context *VMHooksImpl) BigIntGetESDTCallValueByIndex(destinationHandle int3 // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntGetExternalBalance(addressOffset executor.MemPtr, result int32) { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() blockchain := context.GetBlockchainContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(bigIntGetExternalBalanceName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } address, err := context.MemLoad(addressOffset, vmhost.AddressLen) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -246,18 +254,19 @@ func (context *VMHooksImpl) BigIntGetESDTExternalBalance( resultHandle int32) { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(bigIntGetESDTExternalBalanceName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetExternalBalance err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } esdtData, err := getESDTDataFromBlockchainHook(context, addressOffset, tokenIDOffset, tokenIDLen, nonce) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if esdtData == nil { @@ -276,7 +285,8 @@ func (context *VMHooksImpl) BigIntNew(smallValue int64) int32 { gasToUse := metering.GasSchedule().BigIntAPICost.BigIntNew err := metering.UseGasBoundedAndAddTracedGas(bigIntNewName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -288,16 +298,17 @@ func (context *VMHooksImpl) BigIntNew(smallValue int64) int32 { func (context *VMHooksImpl) BigIntUnsignedByteLength(referenceHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntUnsignedByteLength err := metering.UseGasBoundedAndAddTracedGas(bigIntUnsignedByteLengthName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -310,16 +321,17 @@ func (context *VMHooksImpl) BigIntUnsignedByteLength(referenceHandle int32) int3 func (context *VMHooksImpl) BigIntSignedByteLength(referenceHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSignedByteLength err := metering.UseGasBoundedAndAddTracedGas(bigIntSignedByteLengthName, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -331,30 +343,33 @@ func (context *VMHooksImpl) BigIntSignedByteLength(referenceHandle int32) int32 // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntGetUnsignedBytes(referenceHandle int32, byteOffset executor.MemPtr) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(bigIntGetUnsignedBytesName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetUnsignedBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } bytes := value.Bytes() err = context.MemStore(byteOffset, bytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(bytes))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -365,30 +380,33 @@ func (context *VMHooksImpl) BigIntGetUnsignedBytes(referenceHandle int32, byteOf // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntGetSignedBytes(referenceHandle int32, byteOffset executor.MemPtr) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(bigIntGetSignedBytesName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetSignedBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } bytes := twos.ToBytes(value) err = context.MemStore(byteOffset, bytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(bytes))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -399,24 +417,26 @@ func (context *VMHooksImpl) BigIntGetSignedBytes(referenceHandle int32, byteOffs // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntSetUnsignedBytes(destinationHandle int32, byteOffset executor.MemPtr, byteLength executor.MemLength) { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(bigIntSetUnsignedBytesName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSetUnsignedBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bytes, err := context.MemLoad(byteOffset, byteLength) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(bytes))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -428,24 +448,26 @@ func (context *VMHooksImpl) BigIntSetUnsignedBytes(destinationHandle int32, byte // @autogenerate(VMHooks) func (context *VMHooksImpl) BigIntSetSignedBytes(destinationHandle int32, byteOffset executor.MemPtr, byteLength executor.MemLength) { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(bigIntSetSignedBytesName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSetSignedBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bytes, err := context.MemLoad(byteOffset, byteLength) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(bytes))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -458,16 +480,17 @@ func (context *VMHooksImpl) BigIntSetSignedBytes(destinationHandle int32, byteOf func (context *VMHooksImpl) BigIntIsInt64(destinationHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntIsInt64 err := metering.UseGasBoundedAndAddTracedGas(bigIntIsInt64Name, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value, err := managedType.GetBigInt(destinationHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if value.IsInt64() { @@ -481,19 +504,18 @@ func (context *VMHooksImpl) BigIntIsInt64(destinationHandle int32) int32 { func (context *VMHooksImpl) BigIntGetInt64(destinationHandle int32) int64 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetInt64 err := metering.UseGasBoundedAndAddTracedGas(bigIntGetInt64Name, gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } value := managedType.GetBigIntOrCreate(destinationHandle) if !value.IsInt64() { - if context.WithFault(vmhost.ErrBigIntCannotBeRepresentedAsInt64, runtime.BigIntAPIErrorShouldFailExecution()) { - return -1 - } + context.FailExecution(vmhost.ErrBigIntCannotBeRepresentedAsInt64) + return -1 } return value.Int64() } @@ -506,7 +528,8 @@ func (context *VMHooksImpl) BigIntSetInt64(destinationHandle int32, value int64) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSetInt64 err := metering.UseGasBoundedAndAddTracedGas(bigIntSetInt64Name, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -519,23 +542,25 @@ func (context *VMHooksImpl) BigIntSetInt64(destinationHandle int32, value int64) func (context *VMHooksImpl) BigIntAdd(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntAddName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntAdd err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -547,23 +572,25 @@ func (context *VMHooksImpl) BigIntAdd(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntSub(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntSubName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSub err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -575,23 +602,25 @@ func (context *VMHooksImpl) BigIntSub(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntMul(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntMulName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntMul err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -603,28 +632,30 @@ func (context *VMHooksImpl) BigIntMul(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntTDiv(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntTDivName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntTDiv err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if b.Sign() == 0 { - _ = context.WithFault(vmhost.ErrDivZero, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrDivZero) return } dest.Quo(a, b) // Quo implements truncated division (like Go) @@ -635,28 +666,30 @@ func (context *VMHooksImpl) BigIntTDiv(destinationHandle, op1Handle, op2Handle i func (context *VMHooksImpl) BigIntTMod(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntTModName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntTMod err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if b.Sign() == 0 { - _ = context.WithFault(vmhost.ErrDivZero, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrDivZero) return } dest.Rem(a, b) // Rem implements truncated modulus (like Go) @@ -667,28 +700,30 @@ func (context *VMHooksImpl) BigIntTMod(destinationHandle, op1Handle, op2Handle i func (context *VMHooksImpl) BigIntEDiv(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntEDivName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntEDiv err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if b.Sign() == 0 { - _ = context.WithFault(vmhost.ErrDivZero, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrDivZero) return } dest.Div(a, b) // Div implements Euclidean division (unlike Go) @@ -699,28 +734,30 @@ func (context *VMHooksImpl) BigIntEDiv(destinationHandle, op1Handle, op2Handle i func (context *VMHooksImpl) BigIntEMod(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntEModName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntEMod err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if b.Sign() == 0 { - _ = context.WithFault(vmhost.ErrDivZero, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrDivZero) return } dest.Mod(a, b) // Mod implements Euclidean division (unlike Go) @@ -731,28 +768,30 @@ func (context *VMHooksImpl) BigIntEMod(destinationHandle, op1Handle, op2Handle i func (context *VMHooksImpl) BigIntSqrt(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntSqrtName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSqrt err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBadLowerBounds, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadLowerBounds) return } dest.Sqrt(a) @@ -763,18 +802,19 @@ func (context *VMHooksImpl) BigIntSqrt(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigIntPow(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntPowName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntPow err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -782,17 +822,19 @@ func (context *VMHooksImpl) BigIntPow(destinationHandle, op1Handle, op2Handle in lengthOfResult := big.NewInt(0).Div(big.NewInt(0).Mul(b, big.NewInt(int64(a.BitLen()))), big.NewInt(8)) err = managedType.ConsumeGasForThisBigIntNumberOfBytes(lengthOfResult) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if b.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBadLowerBounds, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadLowerBounds) return } @@ -804,27 +846,29 @@ func (context *VMHooksImpl) BigIntPow(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntLog2(op1Handle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntLog2Name) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntLog err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } a, err := managedType.GetBigInt(op1Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = managedType.ConsumeGasForBigIntCopy(a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if a.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBadLowerBounds, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadLowerBounds) return -1 } @@ -836,23 +880,25 @@ func (context *VMHooksImpl) BigIntLog2(op1Handle int32) int32 { func (context *VMHooksImpl) BigIntAbs(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntAbsName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntAbs err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -864,23 +910,25 @@ func (context *VMHooksImpl) BigIntAbs(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigIntNeg(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntNegName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntNeg err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -892,22 +940,24 @@ func (context *VMHooksImpl) BigIntNeg(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigIntSign(opHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntSignName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntSign err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } err = managedType.ConsumeGasForBigIntCopy(a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } @@ -919,22 +969,24 @@ func (context *VMHooksImpl) BigIntSign(opHandle int32) int32 { func (context *VMHooksImpl) BigIntCmp(op1Handle, op2Handle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntCmpName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntCmp err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } err = managedType.ConsumeGasForBigIntCopy(a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -2 } @@ -946,28 +998,30 @@ func (context *VMHooksImpl) BigIntCmp(op1Handle, op2Handle int32) int32 { func (context *VMHooksImpl) BigIntNot(destinationHandle, opHandle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntNotName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntNot err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(dest, a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBitwiseNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBitwiseNegative) return } dest.Not(a) @@ -978,28 +1032,30 @@ func (context *VMHooksImpl) BigIntNot(destinationHandle, opHandle int32) { func (context *VMHooksImpl) BigIntAnd(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntAndName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntAnd err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 || b.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBitwiseNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBitwiseNegative) return } dest.And(a, b) @@ -1010,28 +1066,30 @@ func (context *VMHooksImpl) BigIntAnd(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntOr(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntOrName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntOr err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 || b.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBitwiseNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBitwiseNegative) return } dest.Or(a, b) @@ -1042,28 +1100,30 @@ func (context *VMHooksImpl) BigIntOr(destinationHandle, op1Handle, op2Handle int func (context *VMHooksImpl) BigIntXor(destinationHandle, op1Handle, op2Handle int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntXorName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntXor err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, b, err := managedType.GetTwoBigInt(op1Handle, op2Handle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a, b) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 || b.Sign() < 0 { - _ = context.WithFault(vmhost.ErrBitwiseNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBitwiseNegative) return } dest.Xor(a, b) @@ -1074,34 +1134,37 @@ func (context *VMHooksImpl) BigIntXor(destinationHandle, op1Handle, op2Handle in func (context *VMHooksImpl) BigIntShr(destinationHandle, opHandle, bits int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntShrName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntShr err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 || bits < 0 { - _ = context.WithFault(vmhost.ErrShiftNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrShiftNegative) return } dest.Rsh(a, uint(bits)) err = managedType.ConsumeGasForBigIntCopy(dest) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -1111,34 +1174,37 @@ func (context *VMHooksImpl) BigIntShr(destinationHandle, opHandle, bits int32) { func (context *VMHooksImpl) BigIntShl(destinationHandle, opHandle, bits int32) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntShlName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntShl err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } dest := managedType.GetBigIntOrCreate(destinationHandle) a, err := managedType.GetBigInt(opHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBigIntCopy(a) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } if a.Sign() < 0 || bits < 0 { - _ = context.WithFault(vmhost.ErrShiftNegative, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrShiftNegative) return } dest.Lsh(a, uint(bits)) err = managedType.ConsumeGasForBigIntCopy(dest) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } } @@ -1149,24 +1215,26 @@ func (context *VMHooksImpl) BigIntFinishUnsigned(referenceHandle int32) { managedType := context.GetManagedTypesContext() output := context.GetOutputContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntFinishUnsignedName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntFinishUnsigned err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigIntBytes := value.Bytes() gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.PersistPerByte, uint64(len(value.Bytes()))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -1179,24 +1247,26 @@ func (context *VMHooksImpl) BigIntFinishSigned(referenceHandle int32) { managedType := context.GetManagedTypesContext() output := context.GetOutputContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(bigIntFinishSignedName) gasToUse := metering.GasSchedule().BigIntAPICost.BigIntFinishSigned err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } value, err := managedType.GetBigInt(referenceHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } bigInt2cBytes := twos.ToBytes(value) gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.PersistPerByte, uint64(len(bigInt2cBytes))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -1211,18 +1281,19 @@ func (context *VMHooksImpl) BigIntToString(bigIntHandle int32, destinationHandle } func BigIntToStringWithHost(host vmhost.VMHost, bigIntHandle int32, destinationHandle int32) { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntFinishSigned err := metering.UseGasBoundedAndAddTracedGas(bigIntToStringName, gasToUse) - if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } value, err := managedType.GetBigInt(bigIntHandle) - if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -1230,7 +1301,8 @@ func BigIntToStringWithHost(host vmhost.VMHost, bigIntHandle int32, destinationH gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(resultStr))) err = metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index 3f74c1729..6e398bcd0 100644 --- a/vmhost/vmhooks/cryptoei.go +++ b/vmhost/vmhooks/cryptoei.go @@ -99,7 +99,8 @@ func (context *VMHooksImpl) ManagedSha256(inputHandle, outputHandle int32) int32 } err = managedType.ConsumeGasForBytes(inputBytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -166,7 +167,8 @@ func (context *VMHooksImpl) ManagedKeccak256(inputHandle, outputHandle int32) in } err = managedType.ConsumeGasForBytes(inputBytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -239,7 +241,8 @@ func ManagedRipemd160WithHost(host vmhost.VMHost, inputHandle int32, outputHandl } err = managedType.ConsumeGasForBytes(inputBytes) - if FailExecution(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -545,7 +548,7 @@ func (context *VMHooksImpl) VerifyCustomSecp256k1( } if keyLength != secp256k1CompressedPublicKeyLength && keyLength != secp256k1UncompressedPublicKeyLength { - _ = context.WithFault(vmhost.ErrInvalidPublicKeySize, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInvalidPublicKeySize, runtime.BaseOpsErrorShouldFailExecution()) return 1 } @@ -808,7 +811,7 @@ func (context *VMHooksImpl) AddEC( curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return } gasToUse := metering.GasSchedule().CryptoAPICost.AddECC * uint64(curveMultiplier) / 100 @@ -824,22 +827,22 @@ func (context *VMHooksImpl) AddEC( xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) if err != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) return } x1, y1, err := managedType.GetTwoBigInt(fstPointXHandle, fstPointYHandle) if err != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) return } x2, y2, err := managedType.GetTwoBigInt(sndPointXHandle, sndPointYHandle) if err != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) return } if !ec.IsOnCurve(x1, y1) || !ec.IsOnCurve(x2, y2) { - _ = context.WithFault(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return } @@ -868,7 +871,7 @@ func (context *VMHooksImpl) DoubleEC( curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return } gasToUse := metering.GasSchedule().CryptoAPICost.DoubleECC * uint64(curveMultiplier) / 100 @@ -885,11 +888,11 @@ func (context *VMHooksImpl) DoubleEC( xResult, yResult, err1 := managedType.GetTwoBigInt(xResultHandle, yResultHandle) x, y, err2 := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err1 != nil || err2 != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return } if !ec.IsOnCurve(x, y) { - _ = context.WithFault(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) return } @@ -917,7 +920,7 @@ func (context *VMHooksImpl) IsOnCurveEC( curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.IsOnCurveECC * uint64(curveMultiplier) / 100 @@ -933,7 +936,7 @@ func (context *VMHooksImpl) IsOnCurveEC( x, y, err := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err != nil || x == nil || y == nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -964,13 +967,13 @@ func (context *VMHooksImpl) ScalarBaseMultEC( metering.StartGasTracing(scalarBaseMultECName) if length < 0 { - _ = context.WithFault(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 @@ -1094,13 +1097,13 @@ func (context *VMHooksImpl) ScalarMultEC( metering.StartGasTracing(scalarMultECName) if length < 0 { - _ = context.WithFault(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 @@ -1235,7 +1238,7 @@ func (context *VMHooksImpl) MarshalEC( host := context.GetVMHost() result, err := commonMarshalEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -1340,7 +1343,7 @@ func (context *VMHooksImpl) MarshalCompressedEC( host := context.GetVMHost() result, err := commonMarshalCompressedEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -1449,7 +1452,7 @@ func (context *VMHooksImpl) UnmarshalEC( curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalECC * uint64(curveMultiplier) / 100 @@ -1574,7 +1577,7 @@ func (context *VMHooksImpl) UnmarshalCompressedEC( curveMultiplier := managedType.GetUCompressed100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalCompressedECC * uint64(curveMultiplier) / 100 @@ -1806,7 +1809,7 @@ func (context *VMHooksImpl) CreateEC(dataOffset executor.MemPtr, dataLength exec } if dataLength != curveNameLength { - _ = context.WithFault(vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } data, err := context.MemLoad(dataOffset, dataLength) @@ -1889,7 +1892,7 @@ func (context *VMHooksImpl) GetCurveLengthEC(ecHandle int32) int32 { ecLength := managedType.GetEllipticCurveSizeOfField(ecHandle) if ecLength == -1 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) } return ecLength @@ -1910,7 +1913,7 @@ func (context *VMHooksImpl) GetPrivKeyByteLengthEC(ecHandle int32) int32 { byteLength := managedType.GetPrivateKeyByteLengthEC(ecHandle) if byteLength == -1 { - _ = context.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) } return byteLength diff --git a/vmhost/vmhooks/manBufOps.go b/vmhost/vmhooks/manBufOps.go index 4924af24b..aa50795de 100644 --- a/vmhost/vmhooks/manBufOps.go +++ b/vmhost/vmhooks/manBufOps.go @@ -89,7 +89,7 @@ func (context *VMHooksImpl) MBufferGetLength(mBufferHandle int32) int32 { length := managedType.GetLength(mBufferHandle) if length == -1 { - _ = context.WithFault(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) return -1 } @@ -380,7 +380,7 @@ func (context *VMHooksImpl) MBufferAppend(accumulatorHandle int32, dataHandle in isSuccess := managedType.AppendBytes(accumulatorHandle, dataBufferBytes) if !isSuccess { - _ = context.WithFault(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) return 1 } @@ -408,7 +408,7 @@ func (context *VMHooksImpl) MBufferAppendBytes(accumulatorHandle int32, dataOffs isSuccess := managedType.AppendBytes(accumulatorHandle, data) if !isSuccess { - _ = context.WithFault(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) return 1 } @@ -483,7 +483,8 @@ func (context *VMHooksImpl) MBufferFromBigIntUnsigned(mBufferHandle int32, bigIn } value, err := managedType.GetBigInt(bigIntHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -506,7 +507,8 @@ func (context *VMHooksImpl) MBufferFromBigIntSigned(mBufferHandle int32, bigIntH } value, err := managedType.GetBigInt(bigIntHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -534,7 +536,7 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 } bigInt := big.NewInt(0).SetBytes(data) if !bigInt.IsUint64() { - _ = context.WithFault(vmhost.ErrBytesExceedUint64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedUint64, runtime.BaseOpsErrorShouldFailExecution()) return 0 } return int64(bigInt.Uint64()) @@ -560,7 +562,7 @@ func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 { } bigInt := twos.SetBytes(big.NewInt(0), data) if !bigInt.IsInt64() { - _ = context.WithFault(vmhost.ErrBytesExceedInt64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedInt64, runtime.BaseOpsErrorShouldFailExecution()) return 0 } return bigInt.Int64() @@ -625,7 +627,7 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3 } if managedType.EncodedBigFloatIsNotValid(managedBuffer) { - _ = context.WithFault(vmhost.ErrBigFloatWrongPrecision, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBigFloatWrongPrecision, runtime.BigFloatAPIErrorShouldFailExecution()) return 1 } @@ -640,7 +642,7 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3 return 1 } if bigFloat.IsInf() { - _ = context.WithFault(vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) return 1 } @@ -663,7 +665,8 @@ func (context *VMHooksImpl) MBufferFromBigFloat(mBufferHandle, bigFloatHandle in } value, err := managedType.GetBigFloat(bigFloatHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -761,7 +764,7 @@ func (context *VMHooksImpl) MBufferStorageLoadFromAddress(addressHandle, keyHand address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -818,7 +821,7 @@ func (context *VMHooksImpl) MBufferFinish(sourceHandle int32) int32 { gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.PersistPerByte, uint64(len(sourceBytes))) err = metering.UseGasBounded(gasToUse) if err != nil { - _ = context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) return 1 } @@ -834,7 +837,7 @@ func (context *VMHooksImpl) MBufferSetRandom(destinationHandle int32, length int metering := context.GetMeteringContext() if length < 1 { - _ = context.WithFault(vmhost.ErrLengthOfBufferNotCorrect, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrLengthOfBufferNotCorrect, runtime.ManagedBufferAPIErrorShouldFailExecution()) return -1 } diff --git a/vmhost/vmhooks/managedei.go b/vmhost/vmhooks/managedei.go index 60d5e8ed4..4e00b426f 100644 --- a/vmhost/vmhooks/managedei.go +++ b/vmhost/vmhooks/managedei.go @@ -303,7 +303,7 @@ func (context *VMHooksImpl) ManagedGetReturnData(resultID int32, resultHandle in returnData := output.ReturnData() if resultID >= int32(len(returnData)) || resultID < 0 { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -378,18 +378,18 @@ func (context *VMHooksImpl) ManagedGetESDTBalance(addressHandle int32, tokenIDHa address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return } @@ -588,7 +588,7 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( value, err := managedType.GetBigInt(valueHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 1 } diff --git a/vmhost/vmhooks/smallIntOps.go b/vmhost/vmhooks/smallIntOps.go index 6f1a9ea68..b785ff691 100644 --- a/vmhost/vmhooks/smallIntOps.go +++ b/vmhost/vmhooks/smallIntOps.go @@ -37,14 +37,14 @@ func (context *VMHooksImpl) SmallIntGetUnsignedArgument(id int32) int64 { args := runtime.Arguments() if id < 0 || id >= int32(len(args)) { - _ = context.WithFault(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } arg := args[id] argBigInt := big.NewInt(0).SetBytes(arg) if !argBigInt.IsUint64() { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } return int64(argBigInt.Uint64()) @@ -64,14 +64,14 @@ func (context *VMHooksImpl) SmallIntGetSignedArgument(id int32) int64 { args := runtime.Arguments() if id < 0 || id >= int32(len(args)) { - _ = context.WithFault(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } arg := args[id] argBigInt := twos.SetBytes(big.NewInt(0), arg) if !argBigInt.IsInt64() { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } return argBigInt.Int64() @@ -202,7 +202,7 @@ func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPt valueBigInt := big.NewInt(0).SetBytes(data) if !valueBigInt.IsUint64() { - _ = context.WithFault(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } @@ -240,7 +240,7 @@ func (context *VMHooksImpl) SmallIntStorageLoadSigned(keyOffset executor.MemPtr, valueBigInt := twos.SetBytes(big.NewInt(0), data) if !valueBigInt.IsInt64() { - _ = context.WithFault(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) return 0 } From 123123b4ea6056cf7222ff824d34b5154781209a Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 13:34:22 +0300 Subject: [PATCH 3/7] fixing after refactor --- vmhost/vmhooks/cryptoei.go | 460 ++++++++++++++++++++-------------- vmhost/vmhooks/manBufOps.go | 235 +++++++++-------- vmhost/vmhooks/manMapOps.go | 31 ++- vmhost/vmhooks/managedei.go | 110 ++++---- vmhost/vmhooks/smallIntOps.go | 22 +- 5 files changed, 489 insertions(+), 369 deletions(-) diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index 6e398bcd0..a7d57b747 100644 --- a/vmhost/vmhooks/cryptoei.go +++ b/vmhost/vmhooks/cryptoei.go @@ -50,30 +50,32 @@ func (context *VMHooksImpl) Sha256( length executor.MemLength, resultOffset executor.MemPtr) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() memLoadGas := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(length)) gasToUse := math.AddUint64(metering.GasSchedule().CryptoAPICost.SHA256, memLoadGas) err := metering.UseGasBoundedAndAddTracedGas(sha256Name, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } result, err := crypto.Sha256(data) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -84,17 +86,18 @@ func (context *VMHooksImpl) Sha256( // @autogenerate(VMHooks) func (context *VMHooksImpl) ManagedSha256(inputHandle, outputHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() err := metering.UseGasBoundedAndAddTracedGas(sha256Name, metering.GasSchedule().CryptoAPICost.SHA256) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } inputBytes, err := managedType.GetBytes(inputHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -106,7 +109,7 @@ func (context *VMHooksImpl) ManagedSha256(inputHandle, outputHandle int32) int32 resultBytes, err := crypto.Sha256(inputBytes) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -118,30 +121,32 @@ func (context *VMHooksImpl) ManagedSha256(inputHandle, outputHandle int32) int32 // Keccak256 VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) Keccak256(dataOffset executor.MemPtr, length executor.MemLength, resultOffset executor.MemPtr) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() memLoadGas := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(length)) gasToUse := math.AddUint64(metering.GasSchedule().CryptoAPICost.Keccak256, memLoadGas) err := metering.UseGasBoundedAndAddTracedGas(keccak256Name, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } result, err := crypto.Keccak256(data) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -152,17 +157,18 @@ func (context *VMHooksImpl) Keccak256(dataOffset executor.MemPtr, length executo // @autogenerate(VMHooks) func (context *VMHooksImpl) ManagedKeccak256(inputHandle, outputHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() err := metering.UseGasBoundedAndAddTracedGas(keccak256Name, metering.GasSchedule().CryptoAPICost.Keccak256) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } inputBytes, err := managedType.GetBytes(inputHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -174,7 +180,7 @@ func (context *VMHooksImpl) ManagedKeccak256(inputHandle, outputHandle int32) in resultBytes, err := crypto.Keccak256(inputBytes) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -186,30 +192,32 @@ func (context *VMHooksImpl) ManagedKeccak256(inputHandle, outputHandle int32) in // Ripemd160 VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) Ripemd160(dataOffset executor.MemPtr, length executor.MemLength, resultOffset executor.MemPtr) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() memLoadGas := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(length)) gasToUse := math.AddUint64(metering.GasSchedule().CryptoAPICost.Ripemd160, memLoadGas) err := metering.UseGasBoundedAndAddTracedGas(ripemd160Name, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } result, err := crypto.Ripemd160(data) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -225,18 +233,19 @@ func (context *VMHooksImpl) ManagedRipemd160(inputHandle int32, outputHandle int // ManagedRipemd160WithHost VMHooks implementation. func ManagedRipemd160WithHost(host vmhost.VMHost, inputHandle int32, outputHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() crypto := host.Crypto() err := metering.UseGasBoundedAndAddTracedGas(ripemd160Name, metering.GasSchedule().CryptoAPICost.Ripemd160) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } inputBytes, err := managedType.GetBytes(inputHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -248,7 +257,7 @@ func ManagedRipemd160WithHost(host vmhost.VMHost, inputHandle int32, outputHandl result, err := crypto.Ripemd160(inputBytes) if err != nil { - FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, err) return 1 } @@ -265,41 +274,45 @@ func (context *VMHooksImpl) VerifyBLS( messageLength executor.MemLength, sigOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() metering.StartGasTracing(verifyBLSName) gasToUse := metering.GasSchedule().CryptoAPICost.VerifyBLS err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } key, err := context.MemLoad(keyOffset, blsPublicKeyLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(messageLength)) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } message, err := context.MemLoad(messageOffset, messageLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sig, err := context.MemLoad(sigOffset, blsSignatureLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } invalidSigErr := crypto.VerifyBLS(key, message, sig) if invalidSigErr != nil { - context.WithFault(invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(invalidSigErr) return -1 } @@ -359,32 +372,38 @@ func ManagedVerifyBLSWithHost( } keyBytes, err := managedType.GetBytes(keyHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -405,7 +424,7 @@ func ManagedVerifyBLSWithHost( } if invalidSigErr != nil { - FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -420,41 +439,45 @@ func (context *VMHooksImpl) VerifyEd25519( messageLength executor.MemLength, sigOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() metering.StartGasTracing(verifyEd25519Name) gasToUse := metering.GasSchedule().CryptoAPICost.VerifyEd25519 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } key, err := context.MemLoad(keyOffset, ed25519PublicKeyLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(messageLength)) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } message, err := context.MemLoad(messageOffset, messageLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sig, err := context.MemLoad(sigOffset, ed25519SignatureLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } invalidSigErr := crypto.VerifyEd25519(key, message, sig) if invalidSigErr != nil { - context.WithFault(invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(invalidSigErr) return -1 } @@ -475,7 +498,6 @@ func ManagedVerifyEd25519WithHost( host vmhost.VMHost, keyHandle, messageHandle, sigHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() crypto := host.Crypto() @@ -483,43 +505,50 @@ func ManagedVerifyEd25519WithHost( gasToUse := metering.GasSchedule().CryptoAPICost.VerifyEd25519 err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } keyBytes, err := managedType.GetBytes(keyHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } invalidSigErr := crypto.VerifyEd25519(keyBytes, msgBytes, sigBytes) if invalidSigErr != nil { - FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -536,35 +565,38 @@ func (context *VMHooksImpl) VerifyCustomSecp256k1( sigOffset executor.MemPtr, hashType int32, ) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() metering.StartGasTracing(verifyCustomSecp256k1Name) gasToUse := metering.GasSchedule().CryptoAPICost.VerifySecp256k1 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } if keyLength != secp256k1CompressedPublicKeyLength && keyLength != secp256k1UncompressedPublicKeyLength { - context.FailExecution(vmhost.ErrInvalidPublicKeySize, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInvalidPublicKeySize) return 1 } key, err := context.MemLoad(keyOffset, keyLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(messageLength)) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } message, err := context.MemLoad(messageOffset, messageLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -573,18 +605,20 @@ func (context *VMHooksImpl) VerifyCustomSecp256k1( // byte2: the remaining buffer length const sigHeaderLength = 2 sigHeader, err := context.MemLoad(sigOffset, sigHeaderLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sigLength := int32(sigHeader[1]) + sigHeaderLength sig, err := context.MemLoad(sigOffset, sigLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } invalidSigErr := crypto.VerifySecp256k1(key, message, sig, uint8(hashType)) if invalidSigErr != nil { - context.WithFault(invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(invalidSigErr) return -1 } @@ -626,32 +660,38 @@ func ManagedVerifyCustomSecp256k1WithHost( } keyBytes, err := managedType.GetBytes(keyHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -664,7 +704,7 @@ func ManagedVerifyCustomSecp256k1WithHost( } if invalidSigErr != nil { - FailExecution(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -723,29 +763,32 @@ func (context *VMHooksImpl) EncodeSecp256k1DerSignature( sLength executor.MemLength, sigOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() crypto := context.GetCryptoContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().CryptoAPICost.EncodeDERSig err := metering.UseGasBoundedAndAddTracedGas(encodeSecp256k1DerSignatureName, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } r, err := context.MemLoad(rOffset, rLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } s, err := context.MemLoad(sOffset, sLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } derSig := crypto.EncodeSecp256k1DERSignature(r, s) err = context.MemStore(sigOffset, derSig) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -766,24 +809,26 @@ func ManagedEncodeSecp256k1DerSignatureWithHost( host vmhost.VMHost, rHandle, sHandle, sigHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() crypto := host.Crypto() gasToUse := metering.GasSchedule().CryptoAPICost.EncodeDERSig err := metering.UseGasBoundedAndAddTracedGas(encodeSecp256k1DerSignatureName, gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } r, err := managedType.GetBytes(rHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } s, err := managedType.GetBytes(sHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -806,48 +851,49 @@ func (context *VMHooksImpl) AddEC( ) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(addECName) curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return } gasToUse := metering.GasSchedule().CryptoAPICost.AddECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } ec, err1 := managedType.GetEllipticCurve(ecHandle) - if context.WithFault(err1, runtime.CryptoAPIErrorShouldFailExecution()) { - return + if err1 != nil { + context.FailExecution(err1) } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) if err != nil { - context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } x1, y1, err := managedType.GetTwoBigInt(fstPointXHandle, fstPointYHandle) if err != nil { - context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } x2, y2, err := managedType.GetTwoBigInt(sndPointXHandle, sndPointYHandle) if err != nil { - context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } if !ec.IsOnCurve(x1, y1) || !ec.IsOnCurve(x2, y2) { - context.FailExecution(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPointNotOnCurve) return } err = managedType.ConsumeGasForBigIntCopy(xResult, yResult, ec.P, ec.N, ec.B, ec.Gx, ec.Gy, x1, y1, x2, y2) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } xResultAdd, yResultAdd := ec.Add(x1, y1, x2, y2) @@ -866,38 +912,40 @@ func (context *VMHooksImpl) DoubleEC( ) { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(doubleECName) curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return } gasToUse := metering.GasSchedule().CryptoAPICost.DoubleECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } ec, err1 := managedType.GetEllipticCurve(ecHandle) - if context.WithFault(err1, runtime.CryptoAPIErrorShouldFailExecution()) { + if err1 != nil { + context.FailExecution(err1) return } xResult, yResult, err1 := managedType.GetTwoBigInt(xResultHandle, yResultHandle) x, y, err2 := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err1 != nil || err2 != nil { - context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } if !ec.IsOnCurve(x, y) { - context.FailExecution(vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPointNotOnCurve) return } err = managedType.ConsumeGasForBigIntCopy(xResult, yResult, ec.P, ec.N, ec.B, ec.Gx, ec.Gy, x, y) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -915,33 +963,35 @@ func (context *VMHooksImpl) IsOnCurveEC( ) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(isOnCurveECName) curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.IsOnCurveECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } ec, err := managedType.GetEllipticCurve(ecHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } x, y, err := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err != nil || x == nil || y == nil { - context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return -1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, x, y) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -961,30 +1011,31 @@ func (context *VMHooksImpl) ScalarBaseMultEC( dataOffset executor.MemPtr, length executor.MemLength, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() metering.StartGasTracing(scalarBaseMultECName) if length < 0 { - context.FailExecution(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(length)*oneByteScalarGasCost err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -1018,26 +1069,27 @@ func ManagedScalarBaseMultECWithHost( ecHandle int32, dataHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() metering.StartGasTracing(scalarBaseMultECName) curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } data, err := managedType.GetBytes(dataHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(len(data))*oneByteScalarGasCost err = metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1051,27 +1103,29 @@ func commonScalarBaseMultEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultSBM, yResultSBM := ec.ScalarBaseMult(data) if !ec.IsOnCurve(xResultSBM, yResultSBM) { - _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultSBM) @@ -1091,30 +1145,31 @@ func (context *VMHooksImpl) ScalarMultEC( dataOffset executor.MemPtr, length executor.MemLength, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() metering.StartGasTracing(scalarMultECName) if length < 0 { - context.FailExecution(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(length)*oneByteScalarGasCost err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -1154,26 +1209,27 @@ func ManagedScalarMultECWithHost( pointYHandle int32, dataHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() metering.StartGasTracing(scalarMultECName) curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } data, err := managedType.GetBytes(dataHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } oneByteScalarGasCost := metering.GasSchedule().CryptoAPICost.ScalarMultECC * uint64(curveMultiplier) / 100 gasToUse := oneByteScalarGasCost + uint64(len(data))*oneByteScalarGasCost err = metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1189,35 +1245,36 @@ func commonScalarMultEC( pointYHandle int32, data []byte, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() metering.StartGasTracing(scalarMultECName) ec, err1 := managedType.GetEllipticCurve(ecHandle) - if FailExecution(host, err1, runtime.CryptoAPIErrorShouldFailExecution()) { + if err1 != nil { + FailExecution(host, err1) return 1 } xResult, yResult, err1 := managedType.GetTwoBigInt(xResultHandle, yResultHandle) x, y, err2 := managedType.GetTwoBigInt(pointXHandle, pointYHandle) if err1 != nil || err2 != nil { - _ = FailExecution(host, vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoBigIntUnderThisHandle) return 1 } if !ec.IsOnCurve(x, y) { - _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } err := managedType.ConsumeGasForBigIntCopy(xResult, yResult, ec.P, ec.N, ec.B, ec.Gx, ec.Gy, x, y) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultSM, yResultSM := ec.ScalarMult(x, y, data) if !ec.IsOnCurve(xResultSM, yResultSM) { - _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultSM) @@ -1234,16 +1291,16 @@ func (context *VMHooksImpl) MarshalEC( ecHandle int32, resultOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() host := context.GetVMHost() result, err := commonMarshalEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - context.FailExecution(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return -1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return int32(len(result)) @@ -1277,7 +1334,7 @@ func ManagedMarshalECWithHost( ) int32 { result, err := commonMarshalEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = FailExecution(host, err, true) + FailExecution(host, err) return -1 } @@ -1339,16 +1396,16 @@ func (context *VMHooksImpl) MarshalCompressedEC( ecHandle int32, resultOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() host := context.GetVMHost() result, err := commonMarshalCompressedEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - context.FailExecution(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return -1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } return int32(len(result)) @@ -1380,11 +1437,10 @@ func ManagedMarshalCompressedECWithHost( ecHandle int32, resultHandle int32, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() result, err := commonMarshalCompressedEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1445,24 +1501,25 @@ func (context *VMHooksImpl) UnmarshalEC( dataOffset executor.MemPtr, length executor.MemLength, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() metering.StartGasTracing(unmarshalECName) curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -1496,19 +1553,19 @@ func ManagedUnmarshalECWithHost( ecHandle int32, dataHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() metering.StartGasTracing(unmarshalECName) curveMultiplier := managedType.Get100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1527,32 +1584,34 @@ func commonUnmarshalEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } byteLen := (ec.BitSize + 7) / 8 if len(data) != 1+2*byteLen { - _ = FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultU, yResultU := elliptic.Unmarshal(ec, data) if xResultU == nil || yResultU == nil || !ec.IsOnCurve(xResultU, yResultU) { - _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultU) @@ -1570,24 +1629,25 @@ func (context *VMHooksImpl) UnmarshalCompressedEC( dataOffset executor.MemPtr, length executor.MemLength, ) int32 { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() metering.StartGasTracing(unmarshalCompressedECName) curveMultiplier := managedType.GetUCompressed100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalCompressedECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, err := context.MemLoad(dataOffset, length) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return int32(len(data)) } @@ -1621,24 +1681,25 @@ func ManagedUnmarshalCompressedECWithHost( ecHandle int32, dataHandle int32, ) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() metering.StartGasTracing(unmarshalCompressedECName) curveMultiplier := managedType.GetUCompressed100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalCompressedECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := managedType.GetBytes(dataHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return int32(len(data)) } @@ -1652,32 +1713,34 @@ func commonUnmarshalCompressedEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } byteLen := (ec.BitSize+7)/8 + 1 if len(data) != byteLen { - _ = FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBigIntCopy(ec.P, ec.N, ec.B, ec.Gx, ec.Gy, xResult, yResult) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultUC, yResultUC := elliptic.UnmarshalCompressed(ec, data) if xResultUC == nil || yResultUC == nil || !ec.IsOnCurve(xResultUC, yResultUC) { - _ = FailExecution(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultUC) @@ -1693,15 +1756,16 @@ func (context *VMHooksImpl) GenerateKeyEC( ecHandle int32, resultOffset executor.MemPtr, ) int32 { - runtime := context.GetRuntimeContext() host := context.GetVMHost() result, err := commonGenerateEC(host, xPubKeyHandle, yPubKeyHandle, ecHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = context.MemStore(resultOffset, result) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return int32(len(result)) } @@ -1734,10 +1798,10 @@ func ManagedGenerateKeyECWithHost( ecHandle int32, resultHandle int32, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() result, err := commonGenerateEC(host, xPubKeyHandle, yPubKeyHandle, ecHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -1799,21 +1863,22 @@ func commonGenerateEC( // @autogenerate(VMHooks) func (context *VMHooksImpl) CreateEC(dataOffset executor.MemPtr, dataLength executor.MemLength) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().CryptoAPICost.EllipticCurveNew err := metering.UseGasBoundedAndAddTracedGas(createECName, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } if dataLength != curveNameLength { - context.FailExecution(vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBadBounds) return -1 } data, err := context.MemLoad(dataOffset, dataLength) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } curveChoice := string(data[:]) @@ -1843,18 +1908,19 @@ func (context *VMHooksImpl) ManagedCreateEC(dataHandle int32) int32 { // ManagedCreateECWithHost VMHooks implementation. func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() gasToUse := metering.GasSchedule().CryptoAPICost.EllipticCurveNew err := metering.UseGasBoundedAndAddTracedGas(createECName, gasToUse) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := managedType.GetBytes(dataHandle) - if FailExecution(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } curveChoice := string(data[:]) @@ -1873,7 +1939,7 @@ func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { return managedType.PutEllipticCurve(curveParams) } - _ = FailExecution(host, vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrBadBounds) return -1 } @@ -1882,17 +1948,17 @@ func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { func (context *VMHooksImpl) GetCurveLengthEC(ecHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetInt64 err := metering.UseGasBoundedAndAddTracedGas(getCurveLengthECName, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } ecLength := managedType.GetEllipticCurveSizeOfField(ecHandle) if ecLength == -1 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) } return ecLength @@ -1903,17 +1969,17 @@ func (context *VMHooksImpl) GetCurveLengthEC(ecHandle int32) int32 { func (context *VMHooksImpl) GetPrivKeyByteLengthEC(ecHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetInt64 err := metering.UseGasBoundedAndAddTracedGas(getPrivKeyByteLengthECName, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } byteLength := managedType.GetPrivateKeyByteLengthEC(ecHandle) if byteLength == -1 { - context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) } return byteLength @@ -1924,28 +1990,32 @@ func (context *VMHooksImpl) GetPrivKeyByteLengthEC(ecHandle int32) int32 { func (context *VMHooksImpl) EllipticCurveGetValues(ecHandle int32, fieldOrderHandle int32, basePointOrderHandle int32, eqConstantHandle int32, xBasePointHandle int32, yBasePointHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().BigIntAPICost.BigIntGetInt64 * 5 err := metering.UseGasBoundedAndAddTracedGas(ellipticCurveGetValuesName, gasToUse) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } ec, err := managedType.GetEllipticCurve(ecHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } fieldOrder, basePointOrder, err := managedType.GetTwoBigInt(fieldOrderHandle, basePointOrderHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } eqConstant, err := managedType.GetBigInt(eqConstantHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } xBasePoint, yBasePoint, err := managedType.GetTwoBigInt(xBasePointHandle, yBasePointHandle) - if context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } fieldOrder.Set(ec.P) diff --git a/vmhost/vmhooks/manBufOps.go b/vmhost/vmhooks/manBufOps.go index aa50795de..cf4090ece 100644 --- a/vmhost/vmhooks/manBufOps.go +++ b/vmhost/vmhooks/manBufOps.go @@ -46,7 +46,8 @@ func (context *VMHooksImpl) MBufferNew() int32 { gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferNew err := metering.UseGasBoundedAndAddTracedGas(mBufferNewName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -57,17 +58,18 @@ func (context *VMHooksImpl) MBufferNew() int32 { // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferNewFromBytes(dataOffset executor.MemPtr, dataLength executor.MemLength) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferNewFromBytes err := metering.UseGasBoundedAndAddTracedGas(mBufferNewFromBytesName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } data, err := context.MemLoad(dataOffset, dataLength) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -78,18 +80,18 @@ func (context *VMHooksImpl) MBufferNewFromBytes(dataOffset executor.MemPtr, data // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferGetLength(mBufferHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferGetLength err := metering.UseGasBoundedAndAddTracedGas(mBufferGetLengthName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } length := managedType.GetLength(mBufferHandle) if length == -1 { - context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle) return -1 } @@ -100,27 +102,30 @@ func (context *VMHooksImpl) MBufferGetLength(mBufferHandle int32) int32 { // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferGetBytes(mBufferHandle int32, resultOffset executor.MemPtr) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferGetBytesName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferGetBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } mBufferBytes, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(mBufferBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = context.MemStore(resultOffset, mBufferBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -136,22 +141,24 @@ func (context *VMHooksImpl) MBufferGetByteSlice( resultOffset executor.MemPtr) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferGetByteSliceName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferGetByteSlice err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(sourceBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -162,7 +169,8 @@ func (context *VMHooksImpl) MBufferGetByteSlice( slice := sourceBytes[startingPosition : startingPosition+sliceLength] err = context.MemStore(resultOffset, slice) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -179,22 +187,24 @@ func (context *VMHooksImpl) MBufferCopyByteSlice(sourceHandle int32, startingPos // ManagedBufferCopyByteSliceWithHost VMHooks implementation. func ManagedBufferCopyByteSliceWithHost(host vmhost.VMHost, sourceHandle int32, startingPosition int32, sliceLength int32, destinationHandle int32) int32 { managedType := host.ManagedTypes() - runtime := host.Runtime() metering := host.Metering() metering.StartGasTracing(mBufferCopyByteSliceName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferCopyByteSlice err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sourceBytes) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -208,7 +218,8 @@ func ManagedBufferCopyByteSliceWithHost(host vmhost.VMHost, sourceHandle int32, gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(slice))) err = metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -219,31 +230,35 @@ func ManagedBufferCopyByteSliceWithHost(host vmhost.VMHost, sourceHandle int32, // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferEq(mBufferHandle1 int32, mBufferHandle2 int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferEqName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferCopyByteSlice err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } bytes1, err := managedType.GetBytes(mBufferHandle1) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = managedType.ConsumeGasForBytes(bytes1) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } bytes2, err := managedType.GetBytes(mBufferHandle2) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } err = managedType.ConsumeGasForBytes(bytes2) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -258,23 +273,25 @@ func (context *VMHooksImpl) MBufferEq(mBufferHandle1 int32, mBufferHandle2 int32 // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferSetBytes(mBufferHandle int32, dataOffset executor.MemPtr, dataLength executor.MemLength) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferSetBytesName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferSetBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, dataLength) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(data) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -303,18 +320,19 @@ func (context *VMHooksImpl) ManagedBufferSetByteSliceWithHost( dataLength executor.MemLength, dataOffset executor.MemPtr) int32 { - runtime := host.Runtime() metering := host.Metering() metering.StartGasTracing(mBufferGetByteSliceName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferSetBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, dataLength) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -324,17 +342,18 @@ func (context *VMHooksImpl) ManagedBufferSetByteSliceWithHost( // ManagedBufferSetByteSliceWithTypedArgs VMHooks implementation. func ManagedBufferSetByteSliceWithTypedArgs(host vmhost.VMHost, mBufferHandle int32, startingPosition int32, dataLength int32, data []byte) int32 { managedType := host.ManagedTypes() - runtime := host.Runtime() metering := host.Metering() metering.StartGasTracing(mBufferGetByteSliceName) err := managedType.ConsumeGasForBytes(data) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } bufferBytes, err := managedType.GetBytes(mBufferHandle) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -358,29 +377,31 @@ func ManagedBufferSetByteSliceWithTypedArgs(host vmhost.VMHost, mBufferHandle in // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferAppend(accumulatorHandle int32, dataHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferAppendName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferAppend err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } dataBufferBytes, err := managedType.GetBytes(dataHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(dataBufferBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } isSuccess := managedType.AppendBytes(accumulatorHandle, dataBufferBytes) if !isSuccess { - context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle) return 1 } @@ -391,30 +412,32 @@ func (context *VMHooksImpl) MBufferAppend(accumulatorHandle int32, dataHandle in // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferAppendBytes(accumulatorHandle int32, dataOffset executor.MemPtr, dataLength executor.MemLength) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferAppendBytesName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferAppendBytes err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } data, err := context.MemLoad(dataOffset, dataLength) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } isSuccess := managedType.AppendBytes(accumulatorHandle, data) if !isSuccess { - context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoManagedBufferUnderThisHandle) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(data))) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -425,17 +448,18 @@ func (context *VMHooksImpl) MBufferAppendBytes(accumulatorHandle int32, dataOffs // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferToBigIntUnsigned(mBufferHandle int32, bigIntHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToBigIntUnsigned err := metering.UseGasBoundedAndAddTracedGas(mBufferToBigIntUnsignedName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } managedBuffer, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -449,17 +473,18 @@ func (context *VMHooksImpl) MBufferToBigIntUnsigned(mBufferHandle int32, bigIntH // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferToBigIntSigned(mBufferHandle int32, bigIntHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToBigIntSigned err := metering.UseGasBoundedAndAddTracedGas(mBufferToBigIntSignedName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } managedBuffer, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -473,12 +498,12 @@ func (context *VMHooksImpl) MBufferToBigIntSigned(mBufferHandle int32, bigIntHan // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferFromBigIntUnsigned(mBufferHandle int32, bigIntHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFromBigIntUnsigned err := metering.UseGasBoundedAndAddTracedGas(mBufferFromBigIntUnsignedName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -497,12 +522,12 @@ func (context *VMHooksImpl) MBufferFromBigIntUnsigned(mBufferHandle int32, bigIn // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferFromBigIntSigned(mBufferHandle int32, bigIntHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFromBigIntSigned err := metering.UseGasBoundedAndAddTracedGas(mBufferFromBigIntSignedName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } @@ -520,7 +545,6 @@ func (context *VMHooksImpl) MBufferFromBigIntSigned(mBufferHandle int32, bigIntH // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntUnsigned @@ -531,12 +555,13 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 } data, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } bigInt := big.NewInt(0).SetBytes(data) if !bigInt.IsUint64() { - context.FailExecution(vmhost.ErrBytesExceedUint64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedUint64) return 0 } return int64(bigInt.Uint64()) @@ -546,7 +571,6 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntSigned @@ -557,12 +581,13 @@ func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 { } data, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } bigInt := twos.SetBytes(big.NewInt(0), data) if !bigInt.IsInt64() { - context.FailExecution(vmhost.ErrBytesExceedInt64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedInt64) return 0 } return bigInt.Int64() @@ -606,43 +631,47 @@ func (context *VMHooksImpl) MBufferFromSmallIntSigned(mBufferHandle int32, value // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferToBigFloatName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToBigFloat err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } managedBuffer, err := managedType.GetBytes(mBufferHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(managedBuffer) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } if managedType.EncodedBigFloatIsNotValid(managedBuffer) { - context.FailExecution(vmhost.ErrBigFloatWrongPrecision, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBigFloatWrongPrecision) return 1 } value, err := managedType.GetBigFloatOrCreate(bigFloatHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } bigFloat := new(big.Float) err = bigFloat.GobDecode(managedBuffer) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } if bigFloat.IsInf() { - context.FailExecution(vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInfinityFloatOperation) return 1 } @@ -654,13 +683,13 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3 // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferFromBigFloat(mBufferHandle, bigFloatHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() metering.StartGasTracing(mBufferFromBigFloatName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFromBigFloat err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -671,12 +700,14 @@ func (context *VMHooksImpl) MBufferFromBigFloat(mBufferHandle, bigFloatHandle in } encodedFloat, err := value.GobEncode() - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ConsumeGasForBytes(encodedFloat) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -689,28 +720,31 @@ func (context *VMHooksImpl) MBufferFromBigFloat(mBufferHandle, bigFloatHandle in // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferStorageStore(keyHandle int32, sourceHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferStorageStore err := metering.UseGasBoundedAndAddTracedGas(mBufferStorageStoreName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } key, err := managedType.GetBytes(keyHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } _, err = storage.SetStorage(key, sourceBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -721,17 +755,18 @@ func (context *VMHooksImpl) MBufferStorageStore(keyHandle int32, sourceHandle in // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferStorageLoad(keyHandle int32, destinationHandle int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() key, err := managedType.GetBytes(keyHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } storageBytes, trieDepth, usedCache, err := storage.GetStorage(key) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } @@ -755,21 +790,22 @@ func (context *VMHooksImpl) MBufferStorageLoad(keyHandle int32, destinationHandl func (context *VMHooksImpl) MBufferStorageLoadFromAddress(addressHandle, keyHandle, destinationHandle int32) { host := context.GetVMHost() managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() key, err := managedType.GetBytes(keyHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } address, err := managedType.GetBytes(addressHandle) if err != nil { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } storageBytes, err := StorageLoadFromAddressWithTypedArgs(host, address, key) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -785,13 +821,14 @@ func (context *VMHooksImpl) MBufferGetArgument(id int32, destinationHandle int32 gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferGetArgument err := metering.UseGasBoundedAndAddTracedGas(mBufferGetArgumentName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } args := runtime.Arguments() if int32(len(args)) <= id || id < 0 { - context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return 1 } managedType.SetBytes(destinationHandle, args[id]) @@ -804,24 +841,25 @@ func (context *VMHooksImpl) MBufferFinish(sourceHandle int32) int32 { managedType := context.GetManagedTypesContext() output := context.GetOutputContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() metering.StartGasTracing(mBufferFinishName) gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferFinish err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.PersistPerByte, uint64(len(sourceBytes))) err = metering.UseGasBounded(gasToUse) if err != nil { - context.FailExecution(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -833,11 +871,10 @@ func (context *VMHooksImpl) MBufferFinish(sourceHandle int32) int32 { // @autogenerate(VMHooks) func (context *VMHooksImpl) MBufferSetRandom(destinationHandle int32, length int32) int32 { managedType := context.GetManagedTypesContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() if length < 1 { - context.FailExecution(vmhost.ErrLengthOfBufferNotCorrect, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrLengthOfBufferNotCorrect) return -1 } @@ -845,14 +882,16 @@ func (context *VMHooksImpl) MBufferSetRandom(destinationHandle int32, length int lengthDependentGasToUse := math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(length)) gasToUse := math.AddUint64(baseGasToUse, lengthDependentGasToUse) err := metering.UseGasBoundedAndAddTracedGas(mBufferSetRandomName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } randomizer := managedType.GetRandReader() buffer := make([]byte, length) _, err = randomizer.Read(buffer) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return -1 } diff --git a/vmhost/vmhooks/manMapOps.go b/vmhost/vmhooks/manMapOps.go index db5c3076d..0b85de66c 100644 --- a/vmhost/vmhooks/manMapOps.go +++ b/vmhost/vmhooks/manMapOps.go @@ -16,7 +16,8 @@ func (context *VMHooksImpl) ManagedMapNew() int32 { gasToUse := metering.GasSchedule().ManagedMapAPICost.ManagedMapNew err := metering.UseGasBoundedAndAddTracedGas(managedMapNewName, gasToUse) - if context.WithFault(err, context.GetRuntimeContext().ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -28,16 +29,17 @@ func (context *VMHooksImpl) ManagedMapNew() int32 { func (context *VMHooksImpl) ManagedMapPut(mMapHandle int32, keyHandle int32, valueHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().ManagedMapAPICost.ManagedMapPut err := metering.UseGasBoundedAndAddTracedGas(managedMapPutName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ManagedMapPut(mMapHandle, keyHandle, valueHandle) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -49,16 +51,17 @@ func (context *VMHooksImpl) ManagedMapPut(mMapHandle int32, keyHandle int32, val func (context *VMHooksImpl) ManagedMapGet(mMapHandle int32, keyHandle int32, outValueHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().ManagedMapAPICost.ManagedMapGet err := metering.UseGasBoundedAndAddTracedGas(managedMapGetName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ManagedMapGet(mMapHandle, keyHandle, outValueHandle) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -70,16 +73,17 @@ func (context *VMHooksImpl) ManagedMapGet(mMapHandle int32, keyHandle int32, out func (context *VMHooksImpl) ManagedMapRemove(mMapHandle int32, keyHandle int32, outValueHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().ManagedMapAPICost.ManagedMapRemove err := metering.UseGasBoundedAndAddTracedGas(managedMapRemoveName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } err = managedType.ManagedMapRemove(mMapHandle, keyHandle, outValueHandle) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -91,16 +95,17 @@ func (context *VMHooksImpl) ManagedMapRemove(mMapHandle int32, keyHandle int32, func (context *VMHooksImpl) ManagedMapContains(mMapHandle int32, keyHandle int32) int32 { managedType := context.GetManagedTypesContext() metering := context.GetMeteringContext() - runtime := context.GetRuntimeContext() gasToUse := metering.GasSchedule().ManagedMapAPICost.ManagedMapContains err := metering.UseGasBoundedAndAddTracedGas(managedMapContainsName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 2 } foundValue, err := managedType.ManagedMapContains(mMapHandle, keyHandle) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 2 } diff --git a/vmhost/vmhooks/managedei.go b/vmhost/vmhooks/managedei.go index 4e00b426f..699b0f9d2 100644 --- a/vmhost/vmhooks/managedei.go +++ b/vmhost/vmhooks/managedei.go @@ -72,7 +72,6 @@ func (context *VMHooksImpl) ManagedSCAddress(destinationHandle int32) { func (context *VMHooksImpl) ManagedOwnerAddress(destinationHandle int32) { managedType := context.GetManagedTypesContext() blockchain := context.GetBlockchainContext() - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetOwnerAddress @@ -118,7 +117,8 @@ func (context *VMHooksImpl) ManagedGetOriginalCallerAddr(destinationHandle int32 gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller err := metering.UseGasBoundedAndAddTracedGas(managedCallerName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -135,7 +135,8 @@ func (context *VMHooksImpl) ManagedGetRelayerAddr(destinationHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCaller err := metering.UseGasBoundedAndAddTracedGas(managedCallerName, gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -153,23 +154,27 @@ func (context *VMHooksImpl) ManagedSignalError(errHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.SignalError err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } errBytes, err := managedType.GetBytes(errHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBytes(errBytes) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } gasToUse = metering.GasSchedule().BaseOperationCost.PersistPerByte * uint64(len(errBytes)) err = metering.UseGasBounded(gasToUse) - if err != nil && context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } @@ -195,12 +200,14 @@ func (context *VMHooksImpl) ManagedWriteLog( } dataBytes, err := managedType.GetBytes(dataHandle) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } err = managedType.ConsumeGasForBytes(dataBytes) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -212,7 +219,8 @@ func (context *VMHooksImpl) ManagedWriteLog( sumOfTopicByteLengths+dataByteLen) gasToUse = math.AddUint64(gasToUse, gasForData) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -228,7 +236,8 @@ func (context *VMHooksImpl) ManagedGetOriginalTxHash(resultHandle int32) { gasToUse := metering.GasSchedule().BaseOpsAPICost.GetOriginalTxHash err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } @@ -289,7 +298,6 @@ func (context *VMHooksImpl) ManagedGetPrevBlockRandomSeed(resultHandle int32) { // ManagedGetReturnData VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) ManagedGetReturnData(resultID int32, resultHandle int32) { - runtime := context.GetRuntimeContext() output := context.GetOutputContext() metering := context.GetMeteringContext() managedType := context.GetManagedTypesContext() @@ -303,7 +311,7 @@ func (context *VMHooksImpl) ManagedGetReturnData(resultID int32, resultHandle in returnData := output.ReturnData() if resultID >= int32(len(returnData)) || resultID < 0 { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } @@ -364,7 +372,6 @@ func (context *VMHooksImpl) ManagedGetBackTransfers(esdtTransfersValueHandle int // ManagedGetESDTBalance VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) ManagedGetESDTBalance(addressHandle int32, tokenIDHandle int32, nonce int64, valueHandle int32) { - runtime := context.GetRuntimeContext() metering := context.GetMeteringContext() blockchain := context.GetBlockchainContext() managedType := context.GetManagedTypesContext() @@ -378,18 +385,18 @@ func (context *VMHooksImpl) ManagedGetESDTBalance(addressHandle int32, tokenIDHa address, err := managedType.GetBytes(addressHandle) if err != nil { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } @@ -420,7 +427,6 @@ func ManagedGetESDTTokenDataWithHost( tokenIDHandle int32, nonce int64, valueHandle, propertiesHandle, hashHandle, nameHandle, attributesHandle, creatorHandle, royaltiesHandle, urisHandle int32) { - runtime := host.Runtime() metering := host.Metering() blockchain := host.Blockchain() managedType := host.ManagedTypes() @@ -428,24 +434,25 @@ func ManagedGetESDTTokenDataWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = FailExecution(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } @@ -536,7 +543,7 @@ func ManagedAsyncCallWithHost( value, err := managedType.GetBigInt(valueHandle) if err != nil { - _ = FailExecution(host, vmhost.ErrArgOutOfRange, host.Runtime().BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } @@ -575,7 +582,6 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( ) int32 { host := context.GetVMHost() - runtime := host.Runtime() managedType := host.ManagedTypes() vmInput, err := readDestinationFunctionArguments(host, destHandle, functionHandle, argumentsHandle) @@ -588,7 +594,7 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( value, err := managedType.GetBigInt(valueHandle) if err != nil { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return 1 } @@ -634,7 +640,6 @@ func GetCallbackClosureWithHost( host vmhost.VMHost, callbackClosureHandle int32, ) { - runtime := host.Runtime() async := host.Async() metering := host.Metering() managedTypes := host.ManagedTypes() @@ -643,7 +648,8 @@ func GetCallbackClosureWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallbackClosure err := metering.UseGasBounded(gasToUse) - if FailExecution(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -675,7 +681,8 @@ func (context *VMHooksImpl) ManagedUpgradeFromSourceContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } @@ -734,7 +741,8 @@ func (context *VMHooksImpl) ManagedUpgradeContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return } @@ -844,7 +852,8 @@ func (context *VMHooksImpl) ManagedDeployFromSourceContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return -1 } @@ -904,7 +913,8 @@ func (context *VMHooksImpl) ManagedCreateContract( gasToUse := metering.GasSchedule().BaseOpsAPICost.CreateContract err := metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return -1 } @@ -923,7 +933,8 @@ func (context *VMHooksImpl) ManagedCreateContract( gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, actualLen) err = metering.UseGasBounded(gasToUse) - if context.WithFault(err, runtime.UseGasBoundedShouldFailExecution()) { + if err != nil && runtime.UseGasBoundedShouldFailExecution() { + context.FailExecution(err) return -1 } @@ -998,7 +1009,8 @@ func (context *VMHooksImpl) ManagedExecuteReadOnly( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -1035,7 +1047,8 @@ func (context *VMHooksImpl) ManagedExecuteOnSameContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -1072,7 +1085,8 @@ func (context *VMHooksImpl) ManagedExecuteOnDestContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if FailExecution(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -1133,7 +1147,7 @@ func (context *VMHooksImpl) ManagedMultiTransferESDTNFTExecuteByUser( metering.StartGasTracing(managedMultiTransferESDTNFTExecuteByUser) if !host.IsAllowedToExecute(managedMultiTransferESDTNFTExecuteByUser) { - _ = FailExecution(host, vmhost.ErrOpcodeIsNotAllowed, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrOpcodeIsNotAllowed) return -1 } @@ -1210,7 +1224,6 @@ func ManagedIsESDTFrozenWithHost( addressHandle int32, tokenIDHandle int32, nonce int64) int32 { - runtime := host.Runtime() metering := host.Metering() blockchain := host.Blockchain() managedType := host.ManagedTypes() @@ -1224,18 +1237,18 @@ func ManagedIsESDTFrozenWithHost( address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1254,7 +1267,6 @@ func (context *VMHooksImpl) ManagedIsESDTLimitedTransfer(tokenIDHandle int32) in } func ManagedIsESDTLimitedTransferWithHost(host vmhost.VMHost, tokenIDHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() blockchain := host.Blockchain() managedType := host.ManagedTypes() @@ -1268,7 +1280,7 @@ func ManagedIsESDTLimitedTransferWithHost(host vmhost.VMHost, tokenIDHandle int3 tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1287,7 +1299,6 @@ func (context *VMHooksImpl) ManagedIsESDTPaused(tokenIDHandle int32) int32 { } func ManagedIsESDTPausedWithHost(host vmhost.VMHost, tokenIDHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() blockchain := host.Blockchain() managedType := host.ManagedTypes() @@ -1301,7 +1312,7 @@ func ManagedIsESDTPausedWithHost(host vmhost.VMHost, tokenIDHandle int32) int32 tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1320,7 +1331,6 @@ func (context *VMHooksImpl) ManagedBufferToHex(sourceHandle int32, destHandle in } func ManagedBufferToHexWithHost(host vmhost.VMHost, sourceHandle int32, destHandle int32) { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() @@ -1333,7 +1343,7 @@ func ManagedBufferToHexWithHost(host vmhost.VMHost, sourceHandle int32, destHand mBuff, err := managedType.GetBytes(sourceHandle) if err != nil { - FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return } @@ -1349,7 +1359,6 @@ func (context *VMHooksImpl) ManagedGetCodeMetadata(addressHandle int32, response } func ManagedGetCodeMetadataWithHost(host vmhost.VMHost, addressHandle int32, responseHandle int32) { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() @@ -1369,13 +1378,13 @@ func ManagedGetCodeMetadataWithHost(host vmhost.VMHost, addressHandle int32, res mBuffAddress, err := managedType.GetBytes(addressHandle) if err != nil { - FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return } contract, err := host.Blockchain().GetUserAccount(mBuffAddress) if err != nil || check.IfNil(contract) { - FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return } @@ -1392,7 +1401,6 @@ func (context *VMHooksImpl) ManagedIsBuiltinFunction(functionNameHandle int32) i } func ManagedIsBuiltinFunctionWithHost(host vmhost.VMHost, functionNameHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() @@ -1405,7 +1413,7 @@ func ManagedIsBuiltinFunctionWithHost(host vmhost.VMHost, functionNameHandle int mBuffFunctionName, err := managedType.GetBytes(functionNameHandle) if err != nil { - FailExecution(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } diff --git a/vmhost/vmhooks/smallIntOps.go b/vmhost/vmhooks/smallIntOps.go index b785ff691..8b6be7949 100644 --- a/vmhost/vmhooks/smallIntOps.go +++ b/vmhost/vmhooks/smallIntOps.go @@ -31,20 +31,21 @@ func (context *VMHooksImpl) SmallIntGetUnsignedArgument(id int32) int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64GetArgument err := metering.UseGasBoundedAndAddTracedGas(smallIntGetUnsignedArgumentName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } args := runtime.Arguments() if id < 0 || id >= int32(len(args)) { - context.FailExecution(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange) return 0 } arg := args[id] argBigInt := big.NewInt(0).SetBytes(arg) if !argBigInt.IsUint64() { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return 0 } return int64(argBigInt.Uint64()) @@ -58,20 +59,21 @@ func (context *VMHooksImpl) SmallIntGetSignedArgument(id int32) int64 { gasToUse := metering.GasSchedule().BaseOpsAPICost.Int64GetArgument err := metering.UseGasBoundedAndAddTracedGas(smallIntGetSignedArgumentName, gasToUse) - if context.WithFault(err, runtime.ManagedMapAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } args := runtime.Arguments() if id < 0 || id >= int32(len(args)) { - context.FailExecution(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange) return 0 } arg := args[id] argBigInt := twos.SetBytes(big.NewInt(0), arg) if !argBigInt.IsInt64() { - context.FailExecution(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return 0 } return argBigInt.Int64() @@ -114,7 +116,6 @@ func (context *VMHooksImpl) SmallIntFinishSigned(value int64) { // SmallIntStorageStoreUnsigned VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) SmallIntStorageStoreUnsigned(keyOffset executor.MemPtr, keyLength executor.MemLength, value int64) int32 { - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() @@ -144,7 +145,6 @@ func (context *VMHooksImpl) SmallIntStorageStoreUnsigned(keyOffset executor.MemP // SmallIntStorageStoreSigned VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) SmallIntStorageStoreSigned(keyOffset executor.MemPtr, keyLength executor.MemLength, value int64) int32 { - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() @@ -174,7 +174,6 @@ func (context *VMHooksImpl) SmallIntStorageStoreSigned(keyOffset executor.MemPtr // SmallIntStorageLoadUnsigned VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPtr, keyLength executor.MemLength) int64 { - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() @@ -202,7 +201,7 @@ func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPt valueBigInt := big.NewInt(0).SetBytes(data) if !valueBigInt.IsUint64() { - context.FailExecution(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange) return 0 } @@ -212,7 +211,6 @@ func (context *VMHooksImpl) SmallIntStorageLoadUnsigned(keyOffset executor.MemPt // SmallIntStorageLoadSigned VMHooks implementation. // @autogenerate(VMHooks) func (context *VMHooksImpl) SmallIntStorageLoadSigned(keyOffset executor.MemPtr, keyLength executor.MemLength) int64 { - runtime := context.GetRuntimeContext() storage := context.GetStorageContext() metering := context.GetMeteringContext() @@ -240,7 +238,7 @@ func (context *VMHooksImpl) SmallIntStorageLoadSigned(keyOffset executor.MemPtr, valueBigInt := twos.SetBytes(big.NewInt(0), data) if !valueBigInt.IsInt64() { - context.FailExecution(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange) return 0 } From 0032ebee01d6435105f3a6b2f4672d9bc4c174c3 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 13:36:52 +0300 Subject: [PATCH 4/7] fixing after refactor --- mock/context/runtimeContextWrapper.go | 61 +-------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/mock/context/runtimeContextWrapper.go b/mock/context/runtimeContextWrapper.go index f44ca3fbd..86c1b85cc 100644 --- a/mock/context/runtimeContextWrapper.go +++ b/mock/context/runtimeContextWrapper.go @@ -260,30 +260,6 @@ func NewRuntimeContextWrapper(inputRuntimeContext *vmhost.RuntimeContext) *Runti runtimeWrapper.runtimeContext.SetPointsUsed(gasPoints) } - runtimeWrapper.BaseOpsErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.BaseOpsErrorShouldFailExecution() - } - - runtimeWrapper.SyncExecAPIErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.SyncExecAPIErrorShouldFailExecution() - } - - runtimeWrapper.CryptoAPIErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.CryptoAPIErrorShouldFailExecution() - } - - runtimeWrapper.BigIntAPIErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.BigIntAPIErrorShouldFailExecution() - } - - runtimeWrapper.BigFloatAPIErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.BigFloatAPIErrorShouldFailExecution() - } - - runtimeWrapper.ManagedBufferAPIErrorShouldFailExecutionFunc = func() bool { - return runtimeWrapper.runtimeContext.ManagedBufferAPIErrorShouldFailExecution() - } - runtimeWrapper.AddErrorFunc = func(err error, otherInfo ...string) { runtimeWrapper.runtimeContext.AddError(err, otherInfo...) } @@ -498,41 +474,6 @@ func (contextWrapper *RuntimeContextWrapper) SetPointsUsed(gasPoints uint64) { contextWrapper.SetPointsUsedFunc(gasPoints) } -// BaseOpsErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) BaseOpsErrorShouldFailExecution() bool { - return contextWrapper.BaseOpsErrorShouldFailExecutionFunc() -} - -// SyncExecAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) SyncExecAPIErrorShouldFailExecution() bool { - return contextWrapper.SyncExecAPIErrorShouldFailExecutionFunc() -} - -// CryptoAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) CryptoAPIErrorShouldFailExecution() bool { - return contextWrapper.CryptoAPIErrorShouldFailExecutionFunc() -} - -// BigIntAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) BigIntAPIErrorShouldFailExecution() bool { - return contextWrapper.BigIntAPIErrorShouldFailExecutionFunc() -} - -// BigFloatAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) BigFloatAPIErrorShouldFailExecution() bool { - return contextWrapper.BigFloatAPIErrorShouldFailExecutionFunc() -} - -// ManagedBufferAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) ManagedBufferAPIErrorShouldFailExecution() bool { - return contextWrapper.runtimeContext.ManagedBufferAPIErrorShouldFailExecution() -} - -// ManagedMapAPIErrorShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext -func (contextWrapper *RuntimeContextWrapper) ManagedMapAPIErrorShouldFailExecution() bool { - return contextWrapper.runtimeContext.ManagedMapAPIErrorShouldFailExecution() -} - // UseGasBoundedShouldFailExecution calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext func (contextWrapper *RuntimeContextWrapper) UseGasBoundedShouldFailExecution() bool { return contextWrapper.runtimeContext.UseGasBoundedShouldFailExecution() @@ -544,7 +485,7 @@ func (contextWrapper *RuntimeContextWrapper) GetVMExecutor() executor.Executor { } // ReplaceVMExecutor mocked method -func (contextWrapper *RuntimeContextWrapper) ReplaceVMExecutor(vmExecutor executor.Executor) { +func (contextWrapper *RuntimeContextWrapper) ReplaceVMExecutor(_ executor.Executor) { } // AddError calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext From 704673123e771e08aa20ca2c3341f5aae1111bcc Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 13:52:29 +0300 Subject: [PATCH 5/7] fixing after refactor --- vmhost/vmhooks/baseOps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmhost/vmhooks/baseOps.go b/vmhost/vmhooks/baseOps.go index eb4c16f68..87ae626c9 100644 --- a/vmhost/vmhooks/baseOps.go +++ b/vmhost/vmhooks/baseOps.go @@ -1166,7 +1166,7 @@ func TransferESDTNFTExecuteWithTypedArgs( SenderForExec: sender, } gasLimitForExec, executeErr := output.TransferESDT(transfersArgs, contractCallInput) - if err != nil { + if executeErr != nil { FailExecution(host, executeErr) return 1 } From 8a661cbf6b1f6915195e7678c9fb2282ed2bf977 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 17:59:53 +0300 Subject: [PATCH 6/7] fixes after refactor --- vmhost/vmhooks/baseOps.go | 24 ++++++++++++++++++------ vmhost/vmhooks/vmHooksImpl.go | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/vmhost/vmhooks/baseOps.go b/vmhost/vmhooks/baseOps.go index 87ae626c9..72547da21 100644 --- a/vmhost/vmhooks/baseOps.go +++ b/vmhost/vmhooks/baseOps.go @@ -2800,7 +2800,9 @@ func (context *VMHooksImpl) GetBlockRandomSeed(pointer executor.MemPtr) { randomSeed := blockchain.CurrentRandomSeed() err = context.MemStore(pointer, randomSeed) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } // GetStateRootHash VMHooks implementation. @@ -2818,7 +2820,9 @@ func (context *VMHooksImpl) GetStateRootHash(pointer executor.MemPtr) { stateRootHash := blockchain.GetStateRootHash() err = context.MemStore(pointer, stateRootHash) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } // GetPrevBlockTimestamp VMHooks implementation. @@ -2900,7 +2904,9 @@ func (context *VMHooksImpl) GetPrevBlockRandomSeed(pointer executor.MemPtr) { randomSeed := blockchain.LastRandomSeed() err = context.MemStore(pointer, randomSeed) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } // Finish VMHooks implementation. @@ -3638,7 +3644,9 @@ func (context *VMHooksImpl) GetOriginalTxHash(dataOffset executor.MemPtr) { } err = context.MemStore(dataOffset, runtime.GetOriginalTxHash()) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } // GetCurrentTxHash VMHooks implementation. @@ -3655,7 +3663,9 @@ func (context *VMHooksImpl) GetCurrentTxHash(dataOffset executor.MemPtr) { } err = context.MemStore(dataOffset, runtime.GetCurrentTxHash()) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } // GetPrevTxHash VMHooks implementation. @@ -3672,7 +3682,9 @@ func (context *VMHooksImpl) GetPrevTxHash(dataOffset executor.MemPtr) { } err = context.MemStore(dataOffset, runtime.GetPrevTxHash()) - context.FailExecution(err) + if err != nil { + context.FailExecution(err) + } } func prepareIndirectContractCallInput( diff --git a/vmhost/vmhooks/vmHooksImpl.go b/vmhost/vmhooks/vmHooksImpl.go index 8d5b5e07e..5324caa16 100644 --- a/vmhost/vmhooks/vmHooksImpl.go +++ b/vmhost/vmhooks/vmHooksImpl.go @@ -99,6 +99,10 @@ func (context *VMHooksImpl) FailExecution(err error) { // FailExecution fails the execution with the provided error func FailExecution(host vmhost.VMHost, err error) { + if err == nil { + return + } + runtime := host.Runtime() metering := host.Metering() _ = metering.UseGasBounded(metering.GasLeft()) From b0ce92c85e15e269a2b859d3b9b8fcc524acc557 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 22 Aug 2024 18:09:12 +0300 Subject: [PATCH 7/7] fix after review --- vmhost/vmhooks/bigFloatOps.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vmhost/vmhooks/bigFloatOps.go b/vmhost/vmhooks/bigFloatOps.go index f2a0dfe13..a4555d980 100644 --- a/vmhost/vmhooks/bigFloatOps.go +++ b/vmhost/vmhooks/bigFloatOps.go @@ -76,10 +76,6 @@ func (context *VMHooksImpl) BigFloatNewFromParts(integralPart, fractionalPart, e context.FailExecution(err) return -1 } - if err != nil { - context.FailExecution(err) - return -1 - } if exponent > 0 { context.FailExecution(vmhost.ErrPositiveExponent)