Skip to content
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

feat(avm): remove rethrowable reverts hack #9752

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

fcarreiro
Copy link
Contributor

@fcarreiro fcarreiro commented Nov 5, 2024

This PR removes the RethrowableError hack in the AVM simulator, and relies on the PublicContext's rethrow to propagate the errors. There are two caveats.

First, because currently Aztec-nr does not keep track of the cause chain, it would be impossible to have the call stack and original contract address available, so that the PXE can interpret the error and show debug information. Solidity has the same problem. I'm introducing a heuristic to keep track of the call stack for the simple case where the caller always rethrows: the simulator keeps a running trace in the machineState, and the caller uses this trace IF the revertData coincides. That is, if you are (re)throwing the same as what we were tracking.

Second, while this all works well for errors in user code (e.g., assert in Noir), because they generate a revertData with an error selector and data, the "intrinsic" errors from the simulator (aka exceptional halts) do not work as well. E.g., "division by zero", "duplicated nullifier", "l1 to l2 blah blah". These errors are exceptions in typescript and do not have an associated error selector, and do not add to the revertdata. This could be done with enshrined error selectors. That's easy in the simulator, but it's not easy in the circuit for several reasons that are beyond the scope of this description. The current solution is to propagate the error message (the user will see the right error) but you cannot "catch and process" the error in aztec.nr because there is no selector. This is not a limitation right now because there's no interface in the PublicContext that would let you catch errors. To be continued.

Part of #9061.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @fcarreiro and the rest of your teammates on Graphite Graphite

@fcarreiro fcarreiro marked this pull request as ready for review November 5, 2024 15:29
@@ -37,112 +34,6 @@ export interface ACIRExecutionResult {
returnWitness: ACVMWitness;
}

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to "simulator/common"

Copy link
Contributor

github-actions bot commented Nov 5, 2024

Changes to public function bytecode sizes

Generated at commit: 2b8fcb174c0e5a0e027a7364095217fbfccaebab, compared to commit: 0d1e2389c483cc3a053e829d4451e97131cb8ac7

🧾 Summary (100% most significant diffs)

Program Bytecode size in bytes (+/-) %
AvmTest::public_dispatch +851 ❌ +1.43%

Full diff report 👇
Program Bytecode size in bytes (+/-) %
AvmTest::public_dispatch 60,539 (+851) +1.43%

@fcarreiro fcarreiro added the e2e-all CI: Enables this CI job. label Nov 5, 2024 — with Graphite App
Copy link
Contributor

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@fcarreiro fcarreiro removed the e2e-all CI: Enables this CI job. label Nov 5, 2024
@ludamad ludamad merged commit 2ab33e7 into master Nov 5, 2024
5 checks passed
@ludamad ludamad deleted the fc/avm-remove-reverts-hack branch November 5, 2024 16:54
Maddiaa0 pushed a commit that referenced this pull request Nov 6, 2024
This PR removes the RethrowableError hack in the AVM simulator, and
relies on the PublicContext's
[rethrow](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/aztec-nr/aztec/src/context/public_context.nr#L88)
to propagate the errors. There are two caveats.

First, because currently Aztec-nr does not keep track of the cause
chain, it would be impossible to have the call stack and original
contract address available, so that the PXE can interpret the error and
show debug information. Solidity has the same problem. I'm introducing a
heuristic to keep track of the call stack for the simple case where the
caller always rethrows: the simulator keeps a running trace in the
machineState, and the caller uses this trace IF the revertData
coincides. That is, if you are (re)throwing the same as what we were
tracking.

Second, while this all works well for errors in user code (e.g.,
`assert` in Noir), because they generate a revertData with an error
selector and data, the "intrinsic" errors from the simulator (aka
exceptional halts) do not work as well. E.g., "division by zero",
"duplicated nullifier", "l1 to l2 blah blah". These errors are
exceptions in typescript and do not have an associated error selector,
and do not add to the revertdata. This _could_ be done with enshrined
error selectors. That's easy in the simulator, but it's not easy in the
circuit for several reasons that are beyond the scope of this
description. The current solution is to propagate the error message (the
user will see the right error) but you cannot "catch and process" the
error in aztec.nr because there is no selector. This is not a limitation
right now because there's no interface in the PublicContext that would
let you catch errors. To be continued.

Part of #9061.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants