Overview
Theexit syscall terminates the current program execution, either returning to the calling program or ending transaction execution. It can optionally revert the transaction or return with an error code.
Syscall Code
Code:0x0B (TN_SYSCALL_CODE_EXIT)
C SDK Function
Arguments
User-defined error code to return. This value is passed to the calling program or transaction result.
Revert flag. If non-zero, causes transaction revert; if zero, normal exit.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Normal exit (when returning to caller)TN_VM_SYSCALL_SUCCESS_EXIT(1) - Transaction exit (when ending transaction)
TN_VM_ERR_SYSCALL_REVERT(-24) - Transaction revert requested
Resource Consumption
Compute Units
- Base cost: None (exit syscalls donβt charge compute units)
- Total cost: 0 units
- Rationale: Exit operations are not charged since they terminate execution
Memory Pages
- Page usage: No page allocation or deallocation
- Shadow stack: Uses existing shadow stack to restore previous execution state
- Memory cleanup: No explicit cleanup (handled by transaction end)
Side Effects
- Register a0: Set to the user error code
- Program execution: Terminates current program
- Call stack: Pops current frame (if not root) or ends transaction
- Transaction state: May trigger revert if revert flag is set
Exit Behavior
- Normal Exit (revert = 0)
- Revert Exit (revert β 0)
Root Program: Ends transaction execution with success
- Sets transaction result to user error code
- Transaction commits successfully
- Restores previous execution frame
- Calling program continues execution
- User error code available in a0
Call Stack Behavior
When exiting from a called program:- Current frame index decremented
- Previous execution state restored from shadow stack
- Program context switched back to caller
- User error code placed in a0
Usage Notes
- The user error code is application-defined and can convey success/failure information
- Revert flag provides transaction-level error handling
- Normal exits from root programs complete the transaction successfully
- Multiple nested calls can be unwound with appropriate exit calls
Error Code Conventions
While error codes are user-defined, common conventions include:0: Success1-999: Application-specific success codes1000+: Application-specific error codes