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

Improve ergonomics of failing instruction assert and assert_vector #324

Open
jan-ferdinand opened this issue Sep 12, 2024 · 3 comments
Open
Labels
🧑‍💻 dx/ux Developer experience & user experience 🟡 prio: medium Not super urgent 🛠️ tooling Developer tools

Comments

@jan-ferdinand
Copy link
Member

jan-ferdinand commented Sep 12, 2024

When Triton VM tries to execute instruction assert while the top of its stack is unequal to 1, it fails. Currently, the error it returns does not give any further context. It would be beneficial for developers writing Triton assembly if instruction assert could be decorated with some context, indicating which of potentially many assert statements failed, and potentially also why it failed.

One idea would be to allow specifying an error code:

push 42
assert 127 ; Triton VM returns `InstructionError::AssertionFailed(127)`

Another possibility is to be more explicit about the failure reason:

push 42
assert [expect = "The moon should be blue."]

User-provided context should be optional. That is, the following program should remain syntactically correct (even though it will not halt successfully):

push 42
assert
halt

Note that all syntax examples are simply first drafts of suggestions and should be designed properly.

@jan-ferdinand jan-ferdinand added 🛠️ tooling Developer tools 🟡 prio: medium Not super urgent 🧑‍💻 dx/ux Developer experience & user experience labels Sep 12, 2024
@aszepieniec
Copy link
Collaborator

Possible duplicate: #269

@jan-ferdinand jan-ferdinand changed the title Improve feedback on failing instruction assert Improve ergonomics of failing instruction assert Sep 13, 2024
@jan-ferdinand jan-ferdinand changed the title Improve ergonomics of failing instruction assert Improve ergonomics of failing instruction assert and assert_vector Sep 13, 2024
@Sword-Smith
Copy link
Collaborator

My main motivation for wanting this is fine-grained negative tests. In tasm-lib I have this test helper function.

Currently, I call the function like so

negative_test(
    &ShadowedAccessor::new(snippet),
    init_state.into(),
    &[InstructionError::AssertionFailed],
)

I'd like to be able to add a value to the AssertionFailed (and arguably VectorAssertionFailed too) such that the test can verify exactly where in the code the assert instruction is throwing.

@jan-ferdinand
Copy link
Member Author

What are the additional design requirements from these raised points?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧑‍💻 dx/ux Developer experience & user experience 🟡 prio: medium Not super urgent 🛠️ tooling Developer tools
Projects
None yet
Development

No branches or pull requests

3 participants