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: use zksync-error for halt and revert errors #571

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

dutterbutter
Copy link
Collaborator

@dutterbutter dutterbutter commented Jan 31, 2025

Note: This is branched off from #555 to initiate discussion on defining halt / revert errors and how we would prefer them displayed to users.

Once zksync-error repo is made public and #555 is updated / merged, and feedback is provided for error definitions / display I will prepare this PR to be merged.

The following etc/resources/anvil.json json file outlines the errors that could be hit based on the errors defined here. To make it easier to review and have discussion please refer to this Notion page where the json schema and display are also present for easier dialogue. Feedback would be appreciated, especially as many error cases I am unfamiliar with so assistance in properly defining cause / fixes would be helpful.

cc: @sayon @itegulov @popzxc

What 💻

Why ✋

  • Provide the user with informative and actionable error messaging

Evidence 📷

Include screenshots, screen recordings, or console output here demonstrating that your changes work as intended

Previous errors shown

03:11:55  INFO Unable to estimate gas for the request with our suggested gas limit of 104010000. The transaction is most likely unexecutable. Breakdown of estimation:
03:11:55  INFO 	Estimated transaction body gas cost: 80000000
03:11:55  INFO 	Gas for pubdata: 0
03:11:55  INFO 	Overhead: 10000
03:11:55  INFO execution reverted: Account validation error: Error function_selector = 0x03eb8b54, data = 0x03eb8b540000000000000000000000000000000000000000000000008ad7db82e7522d000000000000000000000000000000000000000000000000000010b87e5d6a2d00

Note: We print gas estimation details implying its a gas issue even though this error is the account having insufficient funds.

Defined structured errors shown

error: [anvil-halt-1] Account validation error: InsufficientFunds(uint256,uint256): 03eb8b540000000000000000000000000000000000000000000000008ad7db82e7522d000000000000000000000000000000000000000000000000000010b87e5d6a2d00
    |
    = error: Account validation failed during execution.
    | 
    | Transaction details:
    |   Transaction Type: EIP1559Transaction
    |   Nonce: 0
    |   To: 0x36615cf349d7f6344891b1e7ca7c72883f5dc049
    |   From: 0xfac041bcf2c4b43319c2c0a39aba53f4cbe44fe5
    |   Gas Limit: 0
    |   Gas Price: 0.04525000 gwei
    |   Gas Per Pubdata Limit: 50000
    | 
    | Likely causes:
    |   - Insufficient funds to cover transaction costs.
    |   - Invalid account state or credentials.
    | 
    | Possible fixes:
    |   - Add enough balance to the account to pay for gas and the transaction amount.
    |   - Verify that the account used has a valid signature and nonce.
    |
note: This error occurs when the account validation step fails during the verification and execution of a transaction.
error: transaction execution halted due to the above error

Note: same error.

@dutterbutter
Copy link
Collaborator Author

Not sure how to handle linting checks for zksync-error crate given its mostly auto generated?

@dutterbutter dutterbutter changed the title Uses zksync-error for halt and revert errors feat: use zksync-error for halt and revert errors Jan 31, 2025
@popzxc
Copy link
Member

popzxc commented Jan 31, 2025

Not sure how to handle linting checks for zksync-error crate given its mostly auto generated?

Normally the generated code must have all the related allow(clippy::whatever) attributes. E.g. it should be handled by the codegen.

contracts Outdated Show resolved Hide resolved
@dutterbutter
Copy link
Collaborator Author

Not sure how to handle linting checks for zksync-error crate given its mostly auto generated?

Normally the generated code must have all the related allow(clippy::whatever) attributes. E.g. it should be handled by the codegen.

@sayon can you add that to the library please 🙏

@sayon
Copy link

sayon commented Jan 31, 2025

Sure, I am currently cleaning the generator and will make it produce a warning-free code.

Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

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

Overall I think it's a great effort and I like what I see a lot

@@ -410,27 +409,23 @@ impl InMemoryNode {
.take()
.unwrap_or_default();

// TODO: I dont think we need to log any of this. The success and errors are
Copy link
Member

Choose a reason for hiding this comment

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

Agreed

"identifier_encoding": "anvil",
"components": [
{
"component_name": "Halt",
Copy link
Member

Choose a reason for hiding this comment

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

Something we need to figure out about hierarchy: I guess these errors would be the same for the main node.
How do we avoid duplication? Should the domain be EraVM maybe? Although then it becomes a bit less clear how to share the error definitions between anvil-zksync and core. Hmm..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, very much so agree. Unfortunately cannot use EraVM here as its already defined in the error definitions.

It would be nice to have conformity, a written standard / policy perhaps, that keeps error code component naming conventional?

Copy link

@sayon sayon Feb 3, 2025

Choose a reason for hiding this comment

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

We can define another piece of error hierarchy related to eravm and wrap these errors as a field or one of anvil errors. It would however require to simulateneously change eravm code, or writing an adapter here. I will produce an example to illustrate wrapping

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking more about changing the error schema as it evolves. Writing adapters makes it even more complex.
OTOH once these errors are battle-tested, we can move them to EraVM scope and deprecate them here.

sayon added 4 commits February 3, 2025 21:38
to be substituted with a link to zksync-error once it becomes public
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