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

security: should non-terminating (non-deterministic) code be caught and reported? #3417

Open
odeke-em opened this issue Dec 28, 2024 · 2 comments
Labels
🐞 bug Something isn't working

Comments

@odeke-em
Copy link
Contributor

While thinking through the expectations and guarantees of Gno, I was thinking about what the VM’s runtime should do and expect then wrote this bit of code https://play.gno.land/p/O4oI9CuhyOv

package hello

func main() {
  for {}
  println("hello world")
}

in which that for loop will never terminate. Gno says it is a fully deterministic variation of the Go programming language but it is also a smart contracting platform. Code that somehow sneaks into a dependency and could run forever would not allow determinism and could consume infinite gas.

Should non-terminating code be detected or according ran against a maximum gas meter?

Kindly cc-ing @moul @petar-dambovaliev @jaekwon

@petar-dambovaliev
Copy link
Contributor

petar-dambovaliev commented Dec 28, 2024

The illustrated code is entirely deterministic. The problem is that the program will never terminate. These are two separate things. Code analysis can't solve this problem. This is a fundamental unsolvable problem in computer science called the halting problem. This problem is solved through gas consumption.

@notJoon
Copy link
Member

notJoon commented Dec 31, 2024

I agree with @petar-dambovaliev.

Simple infinite loops like in the example can be detected through static analysis. However, when complex conditionals or recursive functions are involved, it is impossible to determine at compile time whether a program will terminate or not.

Even if code enters an infinite loop, execution will eventually be halted due to the out of gas, so it seems sufficient without adding analysis functionality.

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
Status: Triage
Development

No branches or pull requests

3 participants