aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

BlockchainRuntime instance is incorrect for dapp calls to self #337

Closed aionick closed 5 years ago

aionick commented 5 years ago

Let's say deployer A invokes dapp B, which invokes itself, dapp B

on the first invocation of B we should have... origin address for B: A (this is correct) caller address for B: A (incorrect: we get B) contract address for B: B(this is correct)

the second invocation is correct.

Note that the address fetching occurs AFTER the recursion. So what's happening here is the BlockchainRuntime pertaining to the second invocation is overwriting the first BlockchainRuntime, so that the parent is calling into its child's "context".

This bug is happening because DAppExecutor does an attachBlockchainRuntime() call, which overwrites the old reference with a new one. The old reference is not held on to and never restored, so when the calling dApp returns from the call and goes to use its BlockchainRuntime, it is actually using its child's.

aionick commented 5 years ago

This bug is fixed. It is still on a local branch of mine because I would like to test the solution a bit more exhaustively.