require( ovmCanonicalTransactionChain.verifyTransaction( _transaction, _txChainElement, _transactionBatchHeader, _transactionProof ), "Invalid transaction inclusion proof." ); 在确定了交易以及状态都合法后,创建 StateTransitioner 准备执行交易。 transitioners[_preStateRoot] = iOVM_StateTransitionerFactory( resolve("OVM_StateTransitionerFactory") ).create( address(libAddressManager), _preStateRootProof.index, _preStateRoot, Lib_OVMCodec.hashTransaction(_transaction) ); 执行交易的逻辑,直接忽略,感兴趣的小伙伴可以看 OVM_StateTransitioner.sol 的 applyTransaction 函数。交易执行完,通过 finalizeFraudVerification 函数检查执行后的世界状态的结果。 function finalizeFraudVerification( bytes32_preStateRoot, Lib_OVMCodec.ChainBatchHeader memory_preStateRootBatchHeader, Lib_OVMCodec.ChainInclusionProof memory_preStateRootProof, bytes32_postStateRoot, Lib_OVMCodec.ChainBatchHeader memory_postStateRootBatchHeader, Lib_OVMCodec.ChainInclusionProof memory_postStateRootProof ) 先检查提供的两个世界状态是否在 StateCommitmentChain 上存在: require( ovmStateCommitmentChain.verifyStateCommitment( _preStateRoot, _preStateRootBatchHeader, _preStateRootProof ), "Invalid pre-state root inclusion proof." ); require( ovmStateCommitmentChain.verifyStateCommitment( _postStateRoot, _postStateRootBatchHeader, _postStateRootProof ), "Invalid post-state root inclusion proof." ); 并且,保证两个状态是连续的: require( _postStateRootProof.index ==_preStateRootProof.index + 1, "Invalid post-state root index." ); 查看 OVM 执行的世界状态是否和提交的状态一致: require( _postStateRoot != transitioner.getPostStateRoot(), "State transition has not been proven fraudulent." ); 如果不一致,需要回滚世界状态: ovmStateCommitmentChain.deleteStateBatch( _postStateRootBatchHeader ); (责任编辑:admin) |