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