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 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 f7ef74e5b..9449c430f 100644 --- a/vmhost/contexts/runtime.go +++ b/vmhost/contexts/runtime.go @@ -691,44 +691,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 fa51f831b..563d91a78 100644 --- a/vmhost/hosttest/execution_test.go +++ b/vmhost/hosttest/execution_test.go @@ -1313,11 +1313,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). @@ -1329,34 +1324,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) }) } @@ -1377,11 +1347,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). @@ -1396,27 +1361,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) }) } @@ -1608,26 +1556,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) }) } @@ -1806,16 +1738,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) }) } @@ -1862,11 +1788,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). @@ -1878,38 +1799,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) }) } @@ -1930,11 +1822,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). @@ -1950,27 +1837,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) }) } @@ -2415,15 +2285,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) }) } @@ -3233,7 +3098,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 @@ -3276,7 +3141,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..72547da21 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 executeErr != 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,41 @@ 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()) + if err != nil { + 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()) + if err != nil { + context.FailExecution(err) + } } // GetPrevBlockTimestamp VMHooks implementation. @@ -2692,7 +2833,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 +2849,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 +2865,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 +2881,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 +2892,26 @@ 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()) + if err != nil { + 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 +2921,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 +2975,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 +3007,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 +3025,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 +3085,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 +3117,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 +3135,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 +3189,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 +3219,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 +3237,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 +3252,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 +3307,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 +3337,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 +3385,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 +3414,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 +3435,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 +3463,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 +3513,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 +3525,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 +3554,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 +3569,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 +3597,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 +3619,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 +3638,15 @@ 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()) + if err != nil { + context.FailExecution(err) + } } // GetCurrentTxHash VMHooks implementation. @@ -3477,12 +3657,15 @@ 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()) + if err != nil { + context.FailExecution(err) + } } // GetPrevTxHash VMHooks implementation. @@ -3493,12 +3676,15 @@ 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()) + if err != nil { + context.FailExecution(err) + } } func prepareIndirectContractCallInput( diff --git a/vmhost/vmhooks/bigFloatOps.go b/vmhost/vmhooks/bigFloatOps.go index 647bb4f4f..a4555d980 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() { - _ = WithFaultAndHost(host, vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrInfinityFloatOperation) return } exponent := result.MantExp(nil) if managedType.BigFloatExpIsNotValid(exponent) { - _ = WithFaultAndHost(host, vmhost.ErrExponentTooBigOrTooSmall, runtime.BigFloatAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrExponentTooBigOrTooSmall) return } dest, err := managedType.GetBigFloatOrCreate(destinationHandle) - if WithFaultAndHost(host, err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -68,17 +68,17 @@ 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 exponent > 0 { - _ = context.WithFault(vmhost.ErrPositiveExponent, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrPositiveExponent) return -1 } @@ -89,7 +89,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 +98,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 +121,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 +154,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 +179,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 +196,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 +225,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 +253,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 +282,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 +315,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 +343,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 +371,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 +394,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 +422,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 +443,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 +480,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 +505,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 +542,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 +578,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 +614,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 +644,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 +665,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 +690,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 +720,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 +741,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 e28b5447f..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 } @@ -152,7 +157,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 } @@ -171,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 } @@ -197,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 } @@ -214,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 } @@ -245,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 { @@ -275,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 } @@ -287,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 } @@ -309,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 } @@ -330,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 } @@ -364,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 } @@ -398,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 } @@ -427,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 } @@ -457,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() { @@ -480,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() } @@ -505,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 } @@ -518,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 } @@ -546,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 } @@ -574,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 } @@ -602,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) @@ -634,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) @@ -666,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) @@ -698,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) @@ -730,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) @@ -762,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 } @@ -781,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 } @@ -803,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 } @@ -835,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 } @@ -863,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 } @@ -891,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 } @@ -918,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 } @@ -945,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) @@ -977,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) @@ -1009,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) @@ -1041,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) @@ -1073,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 } } @@ -1110,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 } } @@ -1148,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 } @@ -1178,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 } @@ -1210,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 WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } value, err := managedType.GetBigInt(bigIntHandle) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -1229,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 WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index 5415f34b7..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,28 +86,30 @@ 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 } err = managedType.ConsumeGasForBytes(inputBytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } resultBytes, err := crypto.Sha256(inputBytes) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -117,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 } @@ -151,28 +157,30 @@ 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 } err = managedType.ConsumeGasForBytes(inputBytes) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } resultBytes, err := crypto.Keccak256(inputBytes) if err != nil { - context.WithFault(err, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -184,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 } @@ -223,29 +233,31 @@ 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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } inputBytes, err := managedType.GetBytes(inputHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(inputBytes) - if WithFaultAndHost(host, err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } result, err := crypto.Ripemd160(inputBytes) if err != nil { - WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, err) return 1 } @@ -262,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 } @@ -350,37 +366,44 @@ 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 err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -401,7 +424,7 @@ func ManagedVerifyBLSWithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -416,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 } @@ -471,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() @@ -479,43 +505,50 @@ func ManagedVerifyEd25519WithHost( gasToUse := metering.GasSchedule().CryptoAPICost.VerifyEd25519 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } keyBytes, err := managedType.GetBytes(keyHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } invalidSigErr := crypto.VerifyEd25519(keyBytes, msgBytes, sigBytes) if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -532,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.WithFault(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 } @@ -569,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 } @@ -616,37 +654,44 @@ 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 err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(keyBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } msgBytes, err := managedType.GetBytes(messageHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(msgBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sigBytes, err := managedType.GetBytes(sigHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sigBytes) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -659,7 +704,7 @@ func ManagedVerifyCustomSecp256k1WithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, invalidSigErr) return -1 } @@ -718,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 } @@ -761,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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } r, err := managedType.GetBytes(rHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } s, err := managedType.GetBytes(sHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -801,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.WithFault(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.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } x1, y1, err := managedType.GetTwoBigInt(fstPointXHandle, fstPointYHandle) if err != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } x2, y2, err := managedType.GetTwoBigInt(sndPointXHandle, sndPointYHandle) if err != nil { - _ = context.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } if !ec.IsOnCurve(x1, y1) || !ec.IsOnCurve(x2, y2) { - _ = context.WithFault(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) @@ -861,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.WithFault(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.WithFault(vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoBigIntUnderThisHandle) return } if !ec.IsOnCurve(x, y) { - _ = context.WithFault(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 } @@ -910,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.WithFault(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.WithFault(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 } @@ -956,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.WithFault(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(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 } @@ -1013,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 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1046,27 +1103,29 @@ func commonScalarBaseMultEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultSBM, yResultSBM := ec.ScalarBaseMult(data) if !ec.IsOnCurve(xResultSBM, yResultSBM) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultSBM) @@ -1086,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.WithFault(vmhost.ErrNegativeLength, runtime.CryptoAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNegativeLength) return 1 } curveMultiplier := managedType.GetScalarMult100xCurveGasCostMultiplier(ecHandle) if curveMultiplier < 0 { - _ = context.WithFault(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 } @@ -1149,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 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1184,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 WithFaultAndHost(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 { - _ = WithFaultAndHost(host, vmhost.ErrNoBigIntUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoBigIntUnderThisHandle) return 1 } if !ec.IsOnCurve(x, y) { - _ = WithFaultAndHost(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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } xResultSM, yResultSM := ec.ScalarMult(x, y, data) if !ec.IsOnCurve(xResultSM, yResultSM) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultSM) @@ -1229,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.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 } return int32(len(result)) @@ -1272,7 +1334,7 @@ func ManagedMarshalECWithHost( ) int32 { result, err := commonMarshalEC(host, xPairHandle, yPairHandle, ecHandle) if err != nil { - _ = WithFaultAndHost(host, err, true) + FailExecution(host, err) return -1 } @@ -1334,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.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 } return int32(len(result)) @@ -1375,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 { - _ = WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1440,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.WithFault(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 } @@ -1491,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 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } @@ -1522,32 +1584,34 @@ func commonUnmarshalEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } byteLen := (ec.BitSize + 7) / 8 if len(data) != 1+2*byteLen { - _ = WithFaultAndHost(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(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 WithFaultAndHost(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) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultU) @@ -1565,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.WithFault(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)) } @@ -1616,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 { - _ = WithFaultAndHost(host, vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrNoEllipticCurveUnderThisHandle) return 1 } gasToUse := metering.GasSchedule().CryptoAPICost.UnmarshalCompressedECC * uint64(curveMultiplier) / 100 err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return int32(len(data)) } @@ -1647,32 +1713,34 @@ func commonUnmarshalCompressedEC( ecHandle int32, data []byte, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() ec, err := managedType.GetEllipticCurve(ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } byteLen := (ec.BitSize+7)/8 + 1 if len(data) != byteLen { - _ = WithFaultAndHost(host, vmhost.ErrLengthOfBufferNotCorrect, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrLengthOfBufferNotCorrect) return 1 } xResult, yResult, err := managedType.GetTwoBigInt(xResultHandle, yResultHandle) - if WithFaultAndHost(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 WithFaultAndHost(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) { - _ = WithFaultAndHost(host, vmhost.ErrPointNotOnCurve, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrPointNotOnCurve) return 1 } xResult.Set(xResultUC) @@ -1688,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)) } @@ -1729,10 +1798,10 @@ func ManagedGenerateKeyECWithHost( ecHandle int32, resultHandle int32, ) int32 { - runtime := host.Runtime() managedType := host.ManagedTypes() result, err := commonGenerateEC(host, xPubKeyHandle, yPubKeyHandle, ecHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -1794,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.WithFault(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[:]) @@ -1838,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 WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } data, err := managedType.GetBytes(dataHandle) - if WithFaultAndHost(host, err, runtime.CryptoAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return -1 } curveChoice := string(data[:]) @@ -1868,7 +1939,7 @@ func ManagedCreateECWithHost(host vmhost.VMHost, dataHandle int32) int32 { return managedType.PutEllipticCurve(curveParams) } - _ = WithFaultAndHost(host, vmhost.ErrBadBounds, runtime.CryptoAPIErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrBadBounds) return -1 } @@ -1877,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.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) } return ecLength @@ -1898,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.WithFault(vmhost.ErrNoEllipticCurveUnderThisHandle, runtime.BigIntAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrNoEllipticCurveUnderThisHandle) } return byteLength @@ -1919,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 f7b3ee650..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.WithFault(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 WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } sourceBytes, err := managedType.GetBytes(sourceHandle) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } err = managedType.ConsumeGasForBytes(sourceBytes) - if WithFaultAndHost(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 WithFaultAndHost(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 WithFaultAndHost(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 WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } bufferBytes, err := managedType.GetBytes(mBufferHandle) - if WithFaultAndHost(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.WithFault(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.WithFault(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,17 +498,18 @@ 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 } value, err := managedType.GetBigInt(bigIntHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -496,17 +522,18 @@ 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 } value, err := managedType.GetBigInt(bigIntHandle) - if context.WithFault(err, runtime.BigIntAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } @@ -518,22 +545,23 @@ 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 err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntUnsignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } 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.WithFault(vmhost.ErrBytesExceedUint64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedUint64) return 0 } return int64(bigInt.Uint64()) @@ -543,22 +571,23 @@ 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 err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntSignedName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 0 } 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.WithFault(vmhost.ErrBytesExceedInt64, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrBytesExceedInt64) return 0 } return bigInt.Int64() @@ -572,7 +601,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 +618,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 } @@ -600,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.WithFault(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.WithFault(vmhost.ErrInfinityFloatOperation, runtime.BigFloatAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrInfinityFloatOperation) return 1 } @@ -648,28 +683,31 @@ 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 } value, err := managedType.GetBigFloat(bigFloatHandle) - if context.WithFault(err, runtime.BigFloatAPIErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return 1 } 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 } @@ -682,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 } @@ -714,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 } @@ -733,7 +775,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 } @@ -747,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.WithFault(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 } @@ -777,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]) @@ -796,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.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(err) return 1 } @@ -825,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.WithFault(vmhost.ErrLengthOfBufferNotCorrect, runtime.ManagedBufferAPIErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrLengthOfBufferNotCorrect) return -1 } @@ -837,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 5543bd876..699b0f9d2 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 } @@ -71,17 +72,18 @@ 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 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 +99,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 } @@ -114,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 } @@ -131,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 } @@ -149,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 } @@ -185,17 +194,20 @@ 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 } 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 } @@ -207,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 } @@ -223,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 } @@ -239,7 +253,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 +270,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 +287,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 } @@ -281,20 +298,20 @@ 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() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetReturnData err := metering.UseGasBoundedAndAddTracedGas(managedGetReturnDataName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } returnData := output.ReturnData() if resultID >= int32(len(returnData)) || resultID < 0 { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } @@ -310,14 +327,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 +351,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 } @@ -351,31 +372,31 @@ 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() gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBoundedAndAddTracedGas(managedGetESDTBalanceName, gasToUse) - if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + context.FailExecution(err) return } address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) return } @@ -406,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() @@ -414,24 +434,25 @@ func ManagedGetESDTTokenDataWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetExternalBalance err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } address, err := managedType.GetBytes(addressHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) return } @@ -442,29 +463,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 +528,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 +543,14 @@ func ManagedAsyncCallWithHost( value, err := managedType.GetBigInt(valueHandle) if err != nil { - _ = WithFaultAndHost(host, vmhost.ErrArgOutOfRange, host.Runtime().BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrArgOutOfRange) 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 +559,8 @@ func ManagedAsyncCallWithHost( runtime.SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) return } - if WithFaultAndHost(host, err, host.Runtime().BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } } @@ -552,11 +582,11 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( ) int32 { host := context.GetVMHost() - runtime := host.Runtime() 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 } @@ -564,22 +594,25 @@ func (context *VMHooksImpl) ManagedCreateAsyncCall( value, err := managedType.GetBigInt(valueHandle) if err != nil { - _ = context.WithFault(vmhost.ErrArgOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgOutOfRange) 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 } callbackClosure, err := managedType.GetBytes(callbackClosureHandle) - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return 1 } @@ -607,7 +640,6 @@ func GetCallbackClosureWithHost( host vmhost.VMHost, callbackClosureHandle int32, ) { - runtime := host.Runtime() async := host.Async() metering := host.Metering() managedTypes := host.ManagedTypes() @@ -616,12 +648,14 @@ func GetCallbackClosureWithHost( gasToUse := metering.GasSchedule().BaseOpsAPICost.GetCallbackClosure err := metering.UseGasBounded(gasToUse) - if WithFaultAndHost(host, err, runtime.ManagedBufferAPIErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } callbackClosure, err := async.GetCallbackClosure() - if WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) { + if err != nil { + FailExecution(host, err) return } @@ -647,22 +681,26 @@ 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 } 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 +716,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 } } @@ -702,26 +741,31 @@ 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 } 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 +773,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 +808,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 } @@ -804,17 +852,20 @@ 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 } 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 +879,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 } @@ -860,46 +913,54 @@ 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 } 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 } 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 } 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 +995,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 +1009,8 @@ func (context *VMHooksImpl) ManagedExecuteReadOnly( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -969,7 +1032,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 +1047,8 @@ func (context *VMHooksImpl) ManagedExecuteOnSameContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -1005,7 +1070,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 +1085,8 @@ func (context *VMHooksImpl) ManagedExecuteOnDestContext( vmInput.arguments, ) err = setReturnDataIfExists(host, lenReturnData, resultHandle) - if WithFaultAndHost(host, err, host.Runtime().UseGasBoundedShouldFailExecution()) { + if err != nil && host.Runtime().UseGasBoundedShouldFailExecution() { + FailExecution(host, err) return -1 } @@ -1042,12 +1109,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 +1147,25 @@ func (context *VMHooksImpl) ManagedMultiTransferESDTNFTExecuteByUser( metering.StartGasTracing(managedMultiTransferESDTNFTExecuteByUser) if !host.IsAllowedToExecute(managedMultiTransferESDTNFTExecuteByUser) { - _ = WithFaultAndHost(host, vmhost.ErrOpcodeIsNotAllowed, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, vmhost.ErrOpcodeIsNotAllowed) 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 +1194,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 } @@ -1151,31 +1224,31 @@ func ManagedIsESDTFrozenWithHost( addressHandle int32, tokenIDHandle int32, nonce int64) int32 { - runtime := host.Runtime() metering := host.Metering() blockchain := host.Blockchain() managedType := host.ManagedTypes() 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) return -1 } tokenID, err := managedType.GetBytes(tokenIDHandle) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } esdtToken, err := blockchain.GetESDTToken(address, tokenID, uint64(nonce)) if err != nil { - _ = WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return -1 } @@ -1194,20 +1267,20 @@ 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() 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) return -1 } @@ -1226,20 +1299,20 @@ 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() 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) return -1 } @@ -1258,19 +1331,19 @@ 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() 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) return } @@ -1286,31 +1359,32 @@ 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() 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) return } contract, err := host.Blockchain().GetUserAccount(mBuffAddress) if err != nil || check.IfNil(contract) { - WithFaultAndHost(host, err, runtime.BaseOpsErrorShouldFailExecution()) + FailExecution(host, err) return } @@ -1327,19 +1401,19 @@ func (context *VMHooksImpl) ManagedIsBuiltinFunction(functionNameHandle int32) i } func ManagedIsBuiltinFunctionWithHost(host vmhost.VMHost, functionNameHandle int32) int32 { - runtime := host.Runtime() metering := host.Metering() managedType := host.ManagedTypes() 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) return -1 } diff --git a/vmhost/vmhooks/smallIntOps.go b/vmhost/vmhooks/smallIntOps.go index 0fa179457..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.WithFault(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange) return 0 } arg := args[id] argBigInt := big.NewInt(0).SetBytes(arg) if !argBigInt.IsUint64() { - _ = context.WithFault(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.WithFault(vmhost.ErrArgIndexOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrArgIndexOutOfRange) 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) return 0 } return argBigInt.Int64() @@ -85,7 +87,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 +104,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 } @@ -112,24 +116,26 @@ 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() 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 } @@ -139,24 +145,26 @@ 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() 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 } @@ -166,17 +174,18 @@ 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() 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,13 +194,14 @@ 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 } valueBigInt := big.NewInt(0).SetBytes(data) if !valueBigInt.IsUint64() { - _ = context.WithFault(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange) return 0 } @@ -201,17 +211,18 @@ 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() 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,13 +231,14 @@ 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 } valueBigInt := twos.SetBytes(big.NewInt(0), data) if !valueBigInt.IsInt64() { - _ = context.WithFault(vmhost.ErrStorageValueOutOfRange, runtime.BaseOpsErrorShouldFailExecution()) + context.FailExecution(vmhost.ErrStorageValueOutOfRange) return 0 } diff --git a/vmhost/vmhooks/vmHooksImpl.go b/vmhost/vmhooks/vmHooksImpl.go index 2466eb2f1..5324caa16 100644 --- a/vmhost/vmhooks/vmHooksImpl.go +++ b/vmhost/vmhooks/vmHooksImpl.go @@ -92,22 +92,19 @@ 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) { + if err == nil { + return } 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)