warp icon indicating copy to clipboard operation
warp copied to clipboard

InternalWrites should be fully transactional

Open ppedziwiatr opened this issue 2 years ago • 0 comments

Consider a case where we have 2 contracts

  1. a "token" contract
  2. 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:

  1. "stake" function performs internal-write and calls "transferFrom" function on the "token" contract
  2. the "transferFrom" on the "token" contracts succeeds
  3. 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).

ppedziwiatr avatar Jul 15 '22 10:07 ppedziwiatr