Commit c2a65c98 authored by Kelvin Fichter's avatar Kelvin Fichter Committed by GitHub

Require height specification in SCC (#27)

* Require height specification in SCC

* Added tests for new functionality

* Removed console imports in contracts
parent 4c546a1f
...@@ -15,9 +15,6 @@ import { iOVM_StateCommitmentChain } from "../../iOVM/chain/iOVM_StateCommitment ...@@ -15,9 +15,6 @@ import { iOVM_StateCommitmentChain } from "../../iOVM/chain/iOVM_StateCommitment
/* Contract Imports */ /* Contract Imports */
import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol"; import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol";
/* Logging Imports */
import { console } from "@nomiclabs/buidler/console.sol";
/** /**
* @title OVM_L1CrossDomainMessenger * @title OVM_L1CrossDomainMessenger
*/ */
......
...@@ -13,9 +13,6 @@ import { iOVM_L2ToL1MessagePasser } from "../../iOVM/precompiles/iOVM_L2ToL1Mess ...@@ -13,9 +13,6 @@ import { iOVM_L2ToL1MessagePasser } from "../../iOVM/precompiles/iOVM_L2ToL1Mess
/* Contract Imports */ /* Contract Imports */
import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol"; import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol";
/* Logging Imports */
import { console } from "@nomiclabs/buidler/console.sol";
/** /**
* @title OVM_L2CrossDomainMessenger * @title OVM_L2CrossDomainMessenger
* @dev L2 CONTRACT (COMPILED) * @dev L2 CONTRACT (COMPILED)
......
...@@ -14,9 +14,6 @@ import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalT ...@@ -14,9 +14,6 @@ import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalT
/* Contract Imports */ /* Contract Imports */
import { OVM_ExecutionManager } from "../execution/OVM_ExecutionManager.sol"; import { OVM_ExecutionManager } from "../execution/OVM_ExecutionManager.sol";
/* Logging Imports */
import { console } from "@nomiclabs/buidler/console.sol";
/** /**
* @title OVM_CanonicalTransactionChain * @title OVM_CanonicalTransactionChain
*/ */
...@@ -267,7 +264,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad ...@@ -267,7 +264,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
} }
require( require(
shouldStartAtBatch == getTotalBatches(), shouldStartAtBatch == getTotalElements(),
"Actual batch start index does not match expected start index." "Actual batch start index does not match expected start index."
); );
......
...@@ -15,9 +15,6 @@ import { iOVM_SafetyChecker } from "../../iOVM/execution/iOVM_SafetyChecker.sol" ...@@ -15,9 +15,6 @@ import { iOVM_SafetyChecker } from "../../iOVM/execution/iOVM_SafetyChecker.sol"
/* Contract Imports */ /* Contract Imports */
import { OVM_ECDSAContractAccount } from "../accounts/OVM_ECDSAContractAccount.sol"; import { OVM_ECDSAContractAccount } from "../accounts/OVM_ECDSAContractAccount.sol";
/* Logging */
import { console } from "@nomiclabs/buidler/console.sol";
/** /**
* @title OVM_ExecutionManager * @title OVM_ExecutionManager
*/ */
......
...@@ -18,9 +18,6 @@ import { iOVM_StateManagerFactory } from "../../iOVM/execution/iOVM_StateManager ...@@ -18,9 +18,6 @@ import { iOVM_StateManagerFactory } from "../../iOVM/execution/iOVM_StateManager
/* Contract Imports */ /* Contract Imports */
import { OVM_FraudContributor } from "./OVM_FraudContributor.sol"; import { OVM_FraudContributor } from "./OVM_FraudContributor.sol";
/* Logging Imports */
import { console } from "@nomiclabs/buidler/console.sol";
/** /**
* @title OVM_StateTransitioner * @title OVM_StateTransitioner
*/ */
......
...@@ -36,12 +36,25 @@ interface iOVM_StateCommitmentChain { ...@@ -36,12 +36,25 @@ interface iOVM_StateCommitmentChain {
uint256 _totalBatches uint256 _totalBatches
); );
/**
* Retrieves the timestamp of the last batch submitted by the sequencer.
* @return _lastSequencerTimestamp Last sequencer batch timestamp.
*/
function getLastSequencerTimestamp()
external
view
returns (
uint256 _lastSequencerTimestamp
);
/** /**
* Appends a batch of state roots to the chain. * Appends a batch of state roots to the chain.
* @param _batch Batch of state roots. * @param _batch Batch of state roots.
* @param _shouldStartAtElement Index of the element at which this batch should start.
*/ */
function appendStateBatch( function appendStateBatch(
bytes32[] calldata _batch bytes32[] calldata _batch,
uint256 _shouldStartAtElement
) )
external; external;
...@@ -93,7 +106,7 @@ interface iOVM_StateCommitmentChain { ...@@ -93,7 +106,7 @@ interface iOVM_StateCommitmentChain {
* @param _txBatchHeader Header of the batch the transaction was included in. * @param _txBatchHeader Header of the batch the transaction was included in.
* @param _txInclusionProof Inclusion proof for the provided transaction chain element. * @param _txInclusionProof Inclusion proof for the provided transaction chain element.
*/ */
function setLastDeletableIndex( function setLastOverwritableIndex(
Lib_OVMCodec.ChainBatchHeader memory _stateBatchHeader, Lib_OVMCodec.ChainBatchHeader memory _stateBatchHeader,
Lib_OVMCodec.Transaction memory _transaction, Lib_OVMCodec.Transaction memory _transaction,
Lib_OVMCodec.TransactionChainElement memory _txChainElement, Lib_OVMCodec.TransactionChainElement memory _txChainElement,
......
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
/* Logging Imports */
import { console } from "@nomiclabs/buidler/console.sol";
interface iRingBufferOverwriter { interface iRingBufferOverwriter {
function canOverwrite(bytes32 _id, uint256 _index) external returns (bool); function canOverwrite(bytes32 _id, uint256 _index) external returns (bool);
} }
......
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
import { console } from "@nomiclabs/buidler/console.sol";
contract Helper_SimpleProxy { contract Helper_SimpleProxy {
address internal owner; address internal owner;
address internal target; address internal target;
......
...@@ -14,13 +14,15 @@ import { ...@@ -14,13 +14,15 @@ import {
toHexString32, toHexString32,
getEthTime, getEthTime,
NULL_BYTES32, NULL_BYTES32,
increaseEthTime,
} from '../../../helpers' } from '../../../helpers'
import { keccak256, defaultAbiCoder } from 'ethers/lib/utils' import { keccak256, defaultAbiCoder } from 'ethers/lib/utils'
describe('OVM_StateCommitmentChain', () => { describe('OVM_StateCommitmentChain', () => {
let signer: Signer let sequencer: Signer
let user: Signer
before(async () => { before(async () => {
;[signer] = await ethers.getSigners() ;[sequencer, user] = await ethers.getSigners()
}) })
let AddressManager: Contract let AddressManager: Contract
...@@ -52,6 +54,11 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -52,6 +54,11 @@ describe('OVM_StateCommitmentChain', () => {
) )
Mock__OVM_BondManager.smocked.isCollateralized.will.return.with(true) Mock__OVM_BondManager.smocked.isCollateralized.will.return.with(true)
await AddressManager.setAddress(
'OVM_Sequencer',
await sequencer.getAddress()
)
}) })
let Factory__OVM_StateCommitmentChain: ContractFactory let Factory__OVM_StateCommitmentChain: ContractFactory
...@@ -74,7 +81,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -74,7 +81,7 @@ describe('OVM_StateCommitmentChain', () => {
it('should revert', async () => { it('should revert', async () => {
await expect( await expect(
OVM_StateCommitmentChain.appendStateBatch(batch) OVM_StateCommitmentChain.appendStateBatch(batch, 0)
).to.be.revertedWith('Cannot submit an empty state batch.') ).to.be.revertedWith('Cannot submit an empty state batch.')
}) })
}) })
...@@ -82,6 +89,16 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -82,6 +89,16 @@ describe('OVM_StateCommitmentChain', () => {
describe('when the provided batch is not empty', () => { describe('when the provided batch is not empty', () => {
const batch = [NON_NULL_BYTES32] const batch = [NON_NULL_BYTES32]
describe('when start index does not match total elements', () => {
it('should revert', async () => {
await expect(
OVM_StateCommitmentChain.appendStateBatch(batch, 1)
).to.be.revertedWith(
'Actual batch start index does not match expected start index.'
)
})
})
describe('when submitting more elements than present in the OVM_CanonicalTransactionChain', () => { describe('when submitting more elements than present in the OVM_CanonicalTransactionChain', () => {
before(() => { before(() => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
...@@ -91,7 +108,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -91,7 +108,7 @@ describe('OVM_StateCommitmentChain', () => {
it('should revert', async () => { it('should revert', async () => {
await expect( await expect(
OVM_StateCommitmentChain.appendStateBatch(batch) OVM_StateCommitmentChain.appendStateBatch(batch, 0)
).to.be.revertedWith( ).to.be.revertedWith(
'Number of state roots cannot exceed the number of canonical transactions.' 'Number of state roots cannot exceed the number of canonical transactions.'
) )
...@@ -106,8 +123,47 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -106,8 +123,47 @@ describe('OVM_StateCommitmentChain', () => {
}) })
it('should append the state batch', async () => { it('should append the state batch', async () => {
await expect(OVM_StateCommitmentChain.appendStateBatch(batch)).to.not await expect(OVM_StateCommitmentChain.appendStateBatch(batch, 0)).to
.be.reverted .not.be.reverted
})
})
describe('when a sequencer submits ', () => {
beforeEach(async () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length * 2
)
await OVM_StateCommitmentChain.connect(sequencer).appendStateBatch(
batch,
0
)
})
describe('when inside sequencer publish window', () => {
it('should revert', async () => {
await expect(
OVM_StateCommitmentChain.connect(user).appendStateBatch(batch, 1)
).to.be.revertedWith(
'Cannot publish state roots within the sequencer publication window.'
)
})
})
describe('when outside sequencer publish window', () => {
beforeEach(async () => {
const SEQUENCER_PUBLISH_WINDOW = await OVM_StateCommitmentChain.SEQUENCER_PUBLISH_WINDOW()
await increaseEthTime(
ethers.provider,
SEQUENCER_PUBLISH_WINDOW.toNumber() + 1
)
})
it('should succeed', async () => {
await expect(
OVM_StateCommitmentChain.connect(user).appendStateBatch(batch, 1)
).to.not.be.reverted
})
}) })
}) })
}) })
...@@ -127,10 +183,10 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -127,10 +183,10 @@ describe('OVM_StateCommitmentChain', () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length batch.length
) )
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
batchHeader.extraData = defaultAbiCoder.encode( batchHeader.extraData = defaultAbiCoder.encode(
['uint256', 'address'], ['uint256', 'address'],
[await getEthTime(ethers.provider), await signer.getAddress()] [await getEthTime(ethers.provider), await sequencer.getAddress()]
) )
}) })
...@@ -152,7 +208,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -152,7 +208,7 @@ describe('OVM_StateCommitmentChain', () => {
before(async () => { before(async () => {
await AddressManager.setAddress( await AddressManager.setAddress(
'OVM_FraudVerifier', 'OVM_FraudVerifier',
await signer.getAddress() await sequencer.getAddress()
) )
}) })
...@@ -202,7 +258,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -202,7 +258,7 @@ describe('OVM_StateCommitmentChain', () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length batch.length
) )
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
}) })
it('should return the number of inserted batch elements', async () => { it('should return the number of inserted batch elements', async () => {
...@@ -216,7 +272,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -216,7 +272,7 @@ describe('OVM_StateCommitmentChain', () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length batch.length
) )
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
}) })
it('should return the number of inserted batch elements', async () => { it('should return the number of inserted batch elements', async () => {
...@@ -230,8 +286,8 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -230,8 +286,8 @@ describe('OVM_StateCommitmentChain', () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length * 2 batch.length * 2
) )
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 32)
}) })
it('should return the number of inserted batch elements', async () => { it('should return the number of inserted batch elements', async () => {
...@@ -253,7 +309,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -253,7 +309,7 @@ describe('OVM_StateCommitmentChain', () => {
Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__OVM_CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length batch.length
) )
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
}) })
it('should return the number of inserted batch elements', async () => { it('should return the number of inserted batch elements', async () => {
...@@ -269,7 +325,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -269,7 +325,7 @@ describe('OVM_StateCommitmentChain', () => {
) )
for (let i = 0; i < 8; i++) { for (let i = 0; i < 8; i++) {
await OVM_StateCommitmentChain.appendStateBatch(batch) await OVM_StateCommitmentChain.appendStateBatch(batch, i)
} }
}) })
......
...@@ -6,7 +6,6 @@ import { Lib_RLPReader_TEST_JSON } from '../../../data' ...@@ -6,7 +6,6 @@ import { Lib_RLPReader_TEST_JSON } from '../../../data'
import { runJsonTest, toHexString } from '../../../helpers' import { runJsonTest, toHexString } from '../../../helpers'
describe('Lib_RLPReader', () => { describe('Lib_RLPReader', () => {
//console.log(JSON.stringify(Lib_RLPReader_TEST_JSON2, null, 4))
describe('JSON tests', () => { describe('JSON tests', () => {
runJsonTest('TestLib_RLPReader', Lib_RLPReader_TEST_JSON) runJsonTest('TestLib_RLPReader', Lib_RLPReader_TEST_JSON)
}) })
......
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