Skip to content

Commit

Permalink
feat: support registering errors from another package
Browse files Browse the repository at this point in the history
this is useful in scenarios where we want to return errors expected by
the users of the package, which is often the case when integrating
fhevm-go with other blockchain frameworks
  • Loading branch information
youben11 authored and dartdart26 committed Oct 27, 2023
1 parent 1c14cd6 commit a4b245a
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions fhevm/errors.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
package fhevm

import (
"errors"
)

// List of EVM execution errors needed by the fhEVM.
// TODO: initialize errors from erros passed by users. That would make fhevm-go errors match the EVM environment's errors.
// List of EVM execution errors needed by the fhEVM
var (
ErrExecutionReverted = errors.New("execution reverted")
ErrOutOfGas error
ErrCodeStoreOutOfGas error
ErrDepth error
ErrInsufficientBalance error
ErrContractAddressCollision error
ErrExecutionReverted error
ErrMaxInitCodeSizeExceeded error
ErrMaxCodeSizeExceeded error
ErrInvalidJump error
ErrWriteProtection error
ErrReturnDataOutOfBounds error
ErrGasUintOverflow error
ErrInvalidCode error
ErrNonceUintOverflow error
ErrAddrProhibited error
ErrInvalidCoinbase error
ErrSenderAddressNotAllowListed error
)

// Register package errors with other custom errors.
//
// This is useful in cases where returned errors need to be recognized by the framework
// using fhevm-go, without much code changes in the framework.
func RegisterErrors(
outOfGasError error,
codeStoreOutOfGasError error,
depthError error,
insufficientBalanceError error,
contractAddressCollisionError error,
executionRevertedError error,
maxInitCodeSizeExceededError error,
maxCodeSizeExceededError error,
invalidJumpError error,
writeProtectionError error,
returnDataOutOfBoundsError error,
gasUintOverflowError error,
invalidCodeError error,
nonceUintOverflowError error,
addrProhibitedError error,
invalidCoinbaseError error,
senderAddressNotAllowListedError error) {
ErrOutOfGas = outOfGasError
ErrCodeStoreOutOfGas = codeStoreOutOfGasError
ErrDepth = depthError
ErrInsufficientBalance = insufficientBalanceError
ErrContractAddressCollision = contractAddressCollisionError
ErrExecutionReverted = executionRevertedError
ErrMaxInitCodeSizeExceeded = maxInitCodeSizeExceededError
ErrMaxCodeSizeExceeded = maxCodeSizeExceededError
ErrInvalidJump = invalidJumpError
ErrWriteProtection = writeProtectionError
ErrReturnDataOutOfBounds = returnDataOutOfBoundsError
ErrGasUintOverflow = gasUintOverflowError
ErrInvalidCode = invalidCodeError
ErrNonceUintOverflow = nonceUintOverflowError
ErrAddrProhibited = addrProhibitedError
ErrInvalidCoinbase = invalidCoinbaseError
ErrSenderAddressNotAllowListed = senderAddressNotAllowListedError
}

0 comments on commit a4b245a

Please sign in to comment.