Submitted by 0x007
When a precompile is invoked, the context (ctx) is cached, and the state database (statedb) commits to this cache, ensuring that precompiles operate with the most up-to-date context and data. During the execution of the precompile, the context can be modified, but these changes are not fully reflected in the state database, except for bank-related modifications.
The snippet above shows that at the end of the transaction, the evmTxCtx is updated to the cached context (cachedCtx) before the state changes are committed by the statedb.commitCtx. However, the issue arises because EvmState and Account modifications made within cachedCtx can be overwritten when statedb.commitCtx commits the state changes. This creates a situation where certain state changes, particularly those made by precompiles like FunToken, can be lost or corrupted.
For example, the FunToken precompile may call CallContract and modify EvmStates AccState after the account state object has been added to the statedb and dirtied.
The transfer to add object to statedb can also be done after precompile is called because statedb would get account and object from evmTxCtx which is lagging cachedCtx.
Make sure EthereumTx.statedb knows what CallContracts in precompile have done, and it has to work well when reverts occur.
k-yang (Nibiru) disputed and commented:
0x007 (warden) commented:
berndartmueller (judge) commented:
k-yang (Nibiru) confirmed and commented:
Nibiru mitigated:
Status: Mitigation confirmed. 
