warp
warp copied to clipboard
InternalWrites should be fully transactional
Consider a case where we have 2 contracts
- a "token" contract
- a "staking" contracts - that can stake tokens on the token contract
After setting proper allowance for the "staking" contract on the "token" contract, a "stake" function is called on the "staking" contract.
Let's assume that:
- "stake" function performs internal-write and calls "transferFrom" function on the "token" contract
- the "transferFrom" on the "token" contracts succeeds
- After performing successful internal-write, the "stake" function throws exception.
In such scenario - the changes made on the "staking" contract would be rollbacked
BUT the changes made on the "token" contract (by the internal-write "transferFrom" function) would NOT be rollbacked - and this needs to be fixed.
The fix should be fairly simple - if for any given transaction index n, any contract in the call tree that takes part in evaluating the state for the "root" contract will throw an exception - the state for all these contracts for this transaction should be set to the state from transaction n-1 (or base state for n = 0).