VM Exception Handling

Four exceptions may be incurred during contract execution:

  1. Asset-style Exception

  2. Require-style Exception

  3. Validation-style Exception

  4. VMillegal-style Exception

Asset-Style Exception

The following triggers an assert-style exception leading to an invalid opcode error, depleting all Energy (including both consumed and unconsumed Energy thus far):

  1. If the array index you are accessing is excessively large or negative (e.g., x[i] where i >= x.length or i < 0).

  2. If you access a fixed length of bytesN, and the index is overly large or negative.

  3. If you attempt division or modulo operations with zero as the divisor (e.g., 5 / 0 or 23 % 0).

  4. If there's a negative digit shift.

  5. If you convert a value that is excessively large or negative to an enumerated type.

  6. If you invoke an uninitialized internal function type variable.

  7. If you call the argument of the assert (expression), and the resulting outcome is false.

  8. Timeout during contract execution.

  9. In case of a PolluxStackOverFlowException.

  10. If an OutofMem exception occurs, surpassing the 3M memory limit.

  11. During contract operation, an overflow transpires, such as in addition.

Require-style Exception

The following conditions result in a require-style exception, leading to a revert error and only consuming the previously consumed energy, excluding the unconsumed energy.

  1. Calling throw.

  2. If you invoke the require parameter (expression), and the final outcome is false.

  3. When calling a function through a message, but the function doesn't conclude correctly (e.g., running out of Energy or encountering its own exception). If Energy isn't specified during the function call, all consumed Energy is passed in and utilized. Note that this function excludes low-level operations like call, send, delegatecall, or callcode. Low-level operations do not throw an exception but return false to denote failure.

  4. Creating a contract with the new keyword, but the contract isn't formed correctly (since Energy can't be specified during contract creation, all Energy is passed in and consumed).

  5. If your contract receives POX via a public function lacking a payable modifier (including constructors, fallback functions, and generic public functions).

  6. When transfer() encounters a failure.

  7. Calling revert().

  8. Reaching the maximum function stack depth of 64.

Validation-style Exception

A PVMIllegal-style exception arises in the following scenarios. This particular type of exception doesn't lead to transaction chaining, but the node initiating the transaction will incur penalties at the network layer for a specific duration.

  1. OwnerAddress and OriginAddress are not equal during contract creation.

  2. Broadcasting a constant request.

Exception Handling Process

  1. The entry is a go() exception that will be caught and processed in go() and will not be passed outside of go().

  1. The play() function is where the virtual machine actually executes. Three places call play(), go() (described above), call To Address() (the CALL instruction is called, which is called in the contract), and create Contract() (CREATE directive, which is when the contract is created in the contract). The latter two will not handle catching exceptions, and the exceptions thrown out of play will continue to be thrown out in the latter two.

  1. step() function

Last updated