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

External messages - accept_message seems to cause silent failures #7

Closed
shaharyakir opened this issue Feb 15, 2023 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@shaharyakir
Copy link
Contributor

Describe the bug
External messages - accept_message seems to cause silent failures

To Reproduce

;; This will throw an error, as expected (assuming the slice doesn't in fact contain a ref)
() recv_external(slice in_msg) impure {
  var x = in_msg~load_ref();
  accept_message();
  ~dump x; ;; Without this line, error doesn't get thrown
}

;; This will NOT throw an error
() recv_external(slice in_msg) impure {
  accept_message();
  var x = in_msg~load_ref();
  ~dump x;
}

Expected behavior
I'd expect:

  1. Error to be thrown upon loading of the ref (9: cell underflow), regardless of whether we're using the value (using ~dump, send_raw_message, etc.)
  2. Error to be thrown regardless of message having been accepted.

Actual behavior
Error is thrown only if the loading which causes the underflow happens before accepting the message.

System information

  • Package version: 0.4.0
  • Node version: v16.15.0
  • OS name and version: Mac OS M1 Ventura 13.0

Additional context
Add any other context about the problem here.

@shaharyakir shaharyakir added the bug Something isn't working label Feb 15, 2023
@EmelyanenkoK
Copy link

EmelyanenkoK commented Feb 15, 2023

It is funC related behavior, not TVM/sandbox.
The thing is that load_ref is considered pure (while actually it can be impure if throw exception). In other words funC drops load_ref operation if result is not used:
Both

;; This will throw an error, as expected (assuming the slice doesn't in fact contain a ref)
() recv_external(slice in_msg) impure {
  var x = in_msg~load_ref();
  accept_message();
}

and

;; This will NOT throw an error
() recv_external(slice in_msg) impure {
  accept_message();
  var x = in_msg~load_ref();
}

will compile to

recv_external PROC:<{
  DROP
  ACCEPT
}>

@shaharyakir
Copy link
Contributor Author

This explains why the error isn't thrown when the loaded ref isn't used.

But in this case:

() recv_external(slice in_msg) impure {
  accept_message();
  var x = in_msg~load_ref();
  ~dump x;
}

The value is used. Shouldn't an error be thrown then?

@EmelyanenkoK
Copy link

() recv_external(slice in_msg) impure {
  accept_message();
  var x = in_msg~load_ref();
  ~dump x;
}

compiles to

recv_external PROC:<{
  ACCEPT
  LDREF
  DROP
  s0 DUMP
  DROP
}>

so yes, I'm expecting failed transaction in this case

@krigga
Copy link
Collaborator

krigga commented Feb 15, 2023

This explains why the error isn't thrown when the loaded ref isn't used.

But in this case:

() recv_external(slice in_msg) impure {
  accept_message();
  var x = in_msg~load_ref();
  ~dump x;
}

The value is used. Shouldn't an error be thrown then?

With this code, I'm getting exit code 9 (to be expected). Do you get the same result?

@shaharyakir
Copy link
Contributor Author

shaharyakir commented Feb 16, 2023

I'll check, it was probably a misunderstanding of mine of how errors work before and after accepting messages. will reopen issue if needed

Trinketer22 pushed a commit to Trinketer22/sandbox that referenced this issue Jan 22, 2024
Merge pull request ton-org#7 from ton-community/tal-features1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants