-
Notifications
You must be signed in to change notification settings - Fork 19
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
Added Checks for the Length of Arguments List #533
Added Checks for the Length of Arguments List #533
Conversation
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.
I would go for Generator::TypeError
for all these. Giving one too many or too few arguments to a function doesn't respect the signature of the function, which I would qualify as a typing error.
What do you think?
InternalError
should be reserved for the cases where something unexpected happens with the compilation process.
@Acaccia I would expect a What you think in adding a new |
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.
Added a comment to discussion.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #533 +/- ##
==========================================
+ Coverage 85.91% 86.38% +0.47%
==========================================
Files 45 45
Lines 21257 22686 +1429
Branches 21257 22686 +1429
==========================================
+ Hits 18263 19598 +1335
- Misses 1422 1443 +21
- Partials 1572 1645 +73 ☔ View full report in Codecov by Sentry. |
@chris We can always add more types of errors, our current error handling is left to be desired. For example, in #516, I had to use a disgusting regex to match the string representation of the error instead of dealing directly with an error type. That was subpar. I'm not entirely sure what this type would add compared to a type error here (whatever way I look at this, for me passing the wrong number of arguments to a function is a type error). But here you are the one who dealt with adapting our errors to the interpreter's, so I will defer to your judgement here. |
Not sure I understand your question @csgui . Why should a compile-time error be thrown before traversal? Should it be a runtime-error instead of compile-time? UPDATE: we clarified it on slack. The issue is that some errors due to the number of arguments are detected during the typechecking phase, some aren't. |
@hugocaillard did a few tests, and it seems some contracts can be deployed if the typechecking doesn't detect the (define-map squares { x: int } { square: int })
(define-public (insert)
(begin
(map-insert squares { x: 255 } { square: 2147483648 } { square: 1 })
(ok true)
)
) @BowTiedWoo I would recommend you change all the return Err(GeneratorError::ArgumentLengthError(format!(
"... expected at least 2 arguments, got {}",
args.len()
))); by the generation of a wasm runtime error. @csgui has a lot of experience with runtime errors if you need any help. |
Hi, I've updated the tests and saw that they indeed do not always return the error I've added in traverse. I followed where the error was coming from and went into the From here I've made some modifications for the I opened a draft PR for this. I wasn’t sure if it would create any backwards incompatibility, but from your message, @Acaccia, I understand that I shouldn’t modify on the |
@BowTiedWoo exactly, we cannot change the typechecker. The contracts that were already deployed "exploiting" this bug should still deploy with the compiled version. We'll rewrite a new version later of the typechecker later, but we still need to be compatible with the 2 currently existing versions. Here you will have to throw runtime-errors like this: clarity-wasm/clar2wasm/src/words/arithmetic.rs Lines 98 to 102 in db50363
It will require a new type of |
Makes sense, thank you. Will start looking into it. |
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.
Nice job, now to replicate it to all functions.........
@BowTiedWoo, it might be better to update your branch with the latest |
@BowTiedWoo Great work so far! 👍 Now it's necessary to validate (and tag) all the tests you've written where the typechecker is failing and the runtime error is being thrown. You can check the example below and use it to guide your work. Let me know if you have any question. Thanks for the patience on all work on this issue. fn get_block_info_more_than_two_args() {
// TODO: see issue #488
// The inconsistency in function arguments should have been caught by the typechecker.
// The runtime error below is being used as a workaround for a typechecker issue
// where certain errors are not properly handled.
// This test should be re-worked once the typechecker is fixed
// and can correctly detect all argument inconsistencies
crosscheck(
"(get-block-info? burnchain-header-hash u0 u0)",
Err(Error::Unchecked(CheckErrors::IncorrectArgumentCount(2, 3))),
)
} |
Thank you @csgui! I added comments for the tests where typechecker fails. |
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.
Code LGTM! Thanks @BowTiedWoo for the great work on this PR!
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.
Great job! Two remarks:
- there is an optimization that could be done by short-cutting the traversal of an expression.
- we should also handle the number of arguments of user-defined functions. Look for
WasmGenerator::traverse_call_user_defined
short-cut the traverse functions that do not have the right argument count.
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.
Looks great, just two questions...
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.
LGTM!
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.
LGTM! Thanks.
Added checks in
traverse
functions throughout the code in order to verify that the number of arguments provided at compile-time is the expected one for the given function.Reference issue: #159