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

Consider native re-entrancy guard #82

Closed
adlerjohn opened this issue Feb 13, 2021 · 2 comments
Closed

Consider native re-entrancy guard #82

adlerjohn opened this issue Feb 13, 2021 · 2 comments
Assignees
Labels
comp:FVM Component: FuelVM question Further information is requested

Comments

@adlerjohn
Copy link
Contributor

Re-entrancy has historically been a significant issue for smart contracts on Ethereum. We should consider a native re-entrancy guard that panics when a contract is called but already has a call frame on the stack. There are some issues with supporting this however: since we define call frames recursively, without an addition table of "which contract is currently on the stack," proving that a contract is on the stack would require going through every single call frame.

Two alternatives:

  1. Add additional metadata to each contract output, a one-bit flag of whether it is on the stack or not. Then, every time a contract is called, it can check this flag. Problems:
    • This is at the granularity of contracts, not functions. This coarse granularity may not be good enough, but introduce extra complexity and overhead to the VM.
  2. Make the high-level language compiler check for the check-effects-interaction pattern and enforce it with an (optional, but on-by-default) compiler flag. This solves the issue entirely with no additional complexity or cost in the VM or the generated bytecode.

My recommendation is simply to do (2).

@adlerjohn adlerjohn added the question Further information is requested label Feb 13, 2021
@Arachnid
Copy link

Oh, please don't. Reentrancy itself is not a bug. #2 sounds better if you can do it - but in many cases you can be reentrancy-safe without it, and in others it's not possible to structure your code in that way.

If you make your shared memory model a little more flexible, people can implement low-cost mutexes in memory, much more efficiently than the EVM's storage.

@adlerjohn
Copy link
Contributor Author

Closing in favor of (2) at FuelLabs/sway#10.

@adlerjohn adlerjohn added the comp:FVM Component: FuelVM label Feb 18, 2021
@adlerjohn adlerjohn self-assigned this Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:FVM Component: FuelVM question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants