-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARC-64: AVM Run Time Errors based on program source map #305
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a3850bf
doc: AVM run time errors source map
cusma dc76d15
doc: add discussions-to field
cusma ff31f8a
doc: nit
cusma 85819cd
doc: typo
cusma 6c8652b
doc: nit
cusma 5b39eda
doc: minor nits
cusma 6dc3bf9
doc: nit
cusma e962e2e
Merge remote-tracking branch 'origin/main' into arc64
cusma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
arc: 64 | ||
title: AVM Run Time Errors Source Map | ||
description: Informative AVM run time errors based on program counter source map | ||
author: Cosimo Bassi (@cusma), Tasos Bitsios (@tasosbit), Steve Ferrigno (@nullun) | ||
discussions-to: https://github.com/algorandfoundation/ARCs/issues/305 | ||
status: Draft | ||
type: Standards Track | ||
category: ARC | ||
created: 2024-08-05 | ||
--- | ||
|
||
## Abstract | ||
|
||
This document introduces a convention for rising informative run time error on the | ||
Algorand Virtual Machine (AVM) based on a program counter *source map*. | ||
|
||
## Motivation | ||
|
||
The AVM does not offer native opcodes to catch and raise run time errors. | ||
|
||
The lack of native error handling semantics could lead to fragmentation of tooling | ||
and frictions for AVM clients, who are unable to retrieve informative and useful | ||
hints about the occurred run time failures. | ||
|
||
This ARC formalizes conventions to raise AVM run time errors based on a program | ||
counter source map. | ||
|
||
## Specification | ||
|
||
The keywords "**MUST**", "**MUST NOT**", "**REQUIRED**", "**SHALL**", "**SHALL NOT**", | ||
"**SHOULD**", "**SHOULD NOT**", "**RECOMMENDED**", "**MAY**", and "**OPTIONAL**" | ||
in this document are to be interpreted as described in <a href="https://datatracker.ietf.org/doc/html/rfc2119">RFC 2119</a>. | ||
|
||
> Notes like this are non-normative. | ||
|
||
### Program Counter Error Source Map | ||
|
||
> TEAL source code instructions are uniquely identified by a program counter, returned | ||
> in the Algod API response upon AVM run time failure. | ||
|
||
> A program counter source map maps program counters back to the original TEAL | ||
> source code lines. | ||
|
||
> The program counter error source map convention is based on error messages written | ||
> as comments in the TEAL source code. | ||
|
||
When a program wants to emit a run time error, it **MUST**: | ||
|
||
1. Precede the failing TEAL instruction with a comment (error message); | ||
1. Produce a program counter source map for the client. | ||
|
||
Upon a program run time failure, the Algod API returns the failed *program counter* | ||
(`pc`). | ||
|
||
Using the program counter, the client **MUST**: | ||
|
||
1. Retrieve the error message preceding the failed TEAL instruction from the program | ||
counter source map; | ||
1. Return the error message. | ||
|
||
### Example | ||
|
||
``` | ||
int 0 [pc=0] | ||
int 1 [pc=1] | ||
&& [pc=2] | ||
// ERR_LOGIC_FALSE | ||
assert [pc=3] | ||
``` | ||
|
||
> The evaluation of the example program would result in a run time error on the | ||
> `assert` instruction, returning the failed program counter (`[pc=3]`) as part | ||
> of the Algod API response. Using a program counter source map, the client is | ||
> then able to retrieve and return the corresponding error message `ERR_LOGIC_FALSE` | ||
> (i.e. the comment preceding the failed program counter). | ||
|
||
## Rationale | ||
|
||
The program counter error source map convention for AVM run time error messages | ||
presents the following PROS and CONS. | ||
|
||
### PROS | ||
|
||
- No program size consumed by error messages. | ||
|
||
### CONS | ||
|
||
- Standard program source maps required for clients to map errors to failed program | ||
counter; | ||
- Developers or compilers need to create an extra “errors source map” to map program | ||
assertion locations to specific error codes; | ||
- Portability: errors source map needs to be kept up to date through different | ||
iterations of a program; | ||
- Error message not returned directly in the Algod API response. | ||
|
||
## Security Considerations | ||
|
||
> Not applicable. | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via <a href="https://creativecommons.org/publicdomain/zero/1.0/">CCO</a>. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another con here is that using the PC will be unreliable for contracts that have template variables. Integer or dynamic byteslice template variable values will change the PC. This is why ARC56 proposes using disassembled TEAL lines in the event template variables. Regardless of the width of the template variable values, the disassembled TEAL will always be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our side conversation about this you said the steps required to make use of this (from front-end perspective) are:
Given a front-end will just get a pc=xxx error (that it has to parse out), for it to have to do all that (assuming the node its connecting to even allows the disassemble/compile endpoints!) just to get the error message associated with that PC is extremely onerous. I think it kills the whole thing imo.
Short of dynamic strings, I think the template variables being variable sized is a fixable issue. Instead of having templates do pushint, pushbytes etc at every reference, perhaps have them initialized at start into scratch storage from fixed size values, ie: btoi(0x0000000000000001) for a templated int 1 - and then reference that scratch slot late for the constant reference?