Commit fa3c557c authored by Alina's avatar Alina Committed by GitHub

Audit/oz co2 match transition indexing 187 (#79)

* match global indexes

* index fix

* invalid global index test cleanup
parent 6f4f7ea6
...@@ -26,7 +26,7 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr ...@@ -26,7 +26,7 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
*******************************************/ *******************************************/
mapping (bytes32 => iOVM_StateTransitioner) internal transitioners; mapping (bytes32 => iOVM_StateTransitioner) internal transitioners;
/*************** /***************
* Constructor * * Constructor *
...@@ -95,7 +95,7 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr ...@@ -95,7 +95,7 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
if (_hasStateTransitioner(_preStateRoot)) { if (_hasStateTransitioner(_preStateRoot)) {
return; return;
} }
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain")); iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
iOVM_CanonicalTransactionChain ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain")); iOVM_CanonicalTransactionChain ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
...@@ -118,6 +118,11 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr ...@@ -118,6 +118,11 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
"Invalid transaction inclusion proof." "Invalid transaction inclusion proof."
); );
require (
_preStateRootBatchHeader.prevTotalElements + _preStateRootProof.index == _transactionBatchHeader.prevTotalElements + _transactionProof.index,
"Pre-state root global index must equal to the transaction root global index."
);
transitioners[_preStateRoot] = iOVM_StateTransitionerFactory( transitioners[_preStateRoot] = iOVM_StateTransitionerFactory(
resolve("OVM_StateTransitionerFactory") resolve("OVM_StateTransitionerFactory")
).create( ).create(
......
...@@ -26,6 +26,13 @@ const DUMMY_TX_CHAIN_ELEMENTS = [...Array(10)].map(() => { ...@@ -26,6 +26,13 @@ const DUMMY_TX_CHAIN_ELEMENTS = [...Array(10)].map(() => {
} }
}) })
const DUMMY_BATCH_PROOFS_WITH_INDEX = [
{
index: 11,
siblings: [NULL_BYTES32],
},
]
describe('OVM_FraudVerifier', () => { describe('OVM_FraudVerifier', () => {
let AddressManager: Contract let AddressManager: Contract
before(async () => { before(async () => {
...@@ -177,6 +184,20 @@ describe('OVM_FraudVerifier', () => { ...@@ -177,6 +184,20 @@ describe('OVM_FraudVerifier', () => {
await OVM_FraudVerifier.getStateTransitioner(NULL_BYTES32) await OVM_FraudVerifier.getStateTransitioner(NULL_BYTES32)
).to.equal(Mock__OVM_StateTransitioner.address) ).to.equal(Mock__OVM_StateTransitioner.address)
}) })
it('should revert when provided with a incorrect transaction root global index', async () => {
await expect (
OVM_FraudVerifier.initializeFraudVerification(
NULL_BYTES32,
DUMMY_BATCH_HEADERS[0],
DUMMY_BATCH_PROOFS[0],
DUMMY_OVM_TRANSACTIONS[0],
DUMMY_TX_CHAIN_ELEMENTS[0],
DUMMY_BATCH_HEADERS[0],
DUMMY_BATCH_PROOFS_WITH_INDEX[0]
)
).to.be.revertedWith('Pre-state root global index must equal to the transaction root global index.')
})
}) })
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment