github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/types/codeFinder.go (about) 1 package types 2 3 import ( 4 "errors" 5 6 gethCore "github.com/onflow/go-ethereum/core" 7 gethVM "github.com/onflow/go-ethereum/core/vm" 8 ) 9 10 func ValidationErrorCode(err error) ErrorCode { 11 // direct errors that are returned by the evm 12 switch err { 13 case gethVM.ErrGasUintOverflow: 14 return ValidationErrCodeGasUintOverflow 15 } 16 17 // wrapped errors return from the evm 18 nested := errors.Unwrap(err) 19 switch nested { 20 case gethCore.ErrNonceTooLow: 21 return ValidationErrCodeNonceTooLow 22 case gethCore.ErrNonceTooHigh: 23 return ValidationErrCodeNonceTooHigh 24 case gethCore.ErrNonceMax: 25 return ValidationErrCodeNonceMax 26 case gethCore.ErrGasLimitReached: 27 return ValidationErrCodeGasLimitReached 28 case gethCore.ErrInsufficientFundsForTransfer: 29 return ValidationErrCodeInsufficientFundsForTransfer 30 case gethCore.ErrMaxInitCodeSizeExceeded: 31 return ValidationErrCodeMaxInitCodeSizeExceeded 32 case gethCore.ErrInsufficientFunds: 33 return ValidationErrCodeInsufficientFunds 34 case gethCore.ErrIntrinsicGas: 35 return ValidationErrCodeIntrinsicGas 36 case gethCore.ErrTxTypeNotSupported: 37 return ValidationErrCodeTxTypeNotSupported 38 case gethCore.ErrTipAboveFeeCap: 39 return ValidationErrCodeTipAboveFeeCap 40 case gethCore.ErrTipVeryHigh: 41 return ValidationErrCodeTipVeryHigh 42 case gethCore.ErrFeeCapVeryHigh: 43 return ValidationErrCodeFeeCapVeryHigh 44 case gethCore.ErrFeeCapTooLow: 45 return ValidationErrCodeFeeCapTooLow 46 case gethCore.ErrSenderNoEOA: 47 return ValidationErrCodeSenderNoEOA 48 case gethCore.ErrBlobFeeCapTooLow: 49 return ValidationErrCodeBlobFeeCapTooLow 50 default: 51 return ValidationErrCodeMisc 52 } 53 } 54 55 func ExecutionErrorCode(err error) ErrorCode { 56 // execution VM errors are never wrapped 57 switch err { 58 case gethVM.ErrOutOfGas: 59 return ExecutionErrCodeOutOfGas 60 case gethVM.ErrCodeStoreOutOfGas: 61 return ExecutionErrCodeCodeStoreOutOfGas 62 case gethVM.ErrDepth: 63 return ExecutionErrCodeDepth 64 case gethVM.ErrInsufficientBalance: 65 return ExecutionErrCodeInsufficientBalance 66 case gethVM.ErrContractAddressCollision: 67 return ExecutionErrCodeContractAddressCollision 68 case gethVM.ErrExecutionReverted: 69 return ExecutionErrCodeExecutionReverted 70 case gethVM.ErrMaxInitCodeSizeExceeded: 71 return ExecutionErrCodeMaxInitCodeSizeExceeded 72 case gethVM.ErrMaxCodeSizeExceeded: 73 return ExecutionErrCodeMaxCodeSizeExceeded 74 case gethVM.ErrInvalidJump: 75 return ExecutionErrCodeInvalidJump 76 case gethVM.ErrWriteProtection: 77 return ExecutionErrCodeWriteProtection 78 case gethVM.ErrReturnDataOutOfBounds: 79 return ExecutionErrCodeReturnDataOutOfBounds 80 case gethVM.ErrGasUintOverflow: 81 return ExecutionErrCodeGasUintOverflow 82 case gethVM.ErrInvalidCode: 83 return ExecutionErrCodeInvalidCode 84 case gethVM.ErrNonceUintOverflow: 85 return ExecutionErrCodeNonceUintOverflow 86 default: 87 return ExecutionErrCodeMisc 88 } 89 }