Commit 0125c1ec authored by Kevin Ho's avatar Kevin Ho Committed by GitHub

Update state commitment chain (#75)

* add configurable fraud proof window to stc

* fix state commitment chain, add event

* add required config field

* fix merkle utils bug
parent ea3785b1
......@@ -16,13 +16,17 @@ const MAX_GAS_PER_QUEUE_PER_EPOCH = env.MAX_GAS_PER_QUEUE_PER_EPOCH || 250000000
const SECONDS_PER_EPOCH = env.SECONDS_PER_EPOCH || 0;
let WHITELIST_OWNER = env.WHITELIST_OWNER;
const WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT = env.WHITELIST_ALLOW_ARBITRARY_CONTRACT_DEPLOYMENT || true;
const FORCE_INCLUSION_PERIOD_SECONDS = env.FORCE_INCLUSION_PERIOD_SECONDS || (300000 * 60);
const FORCE_INCLUSION_PERIOD_SECONDS = env.FORCE_INCLUSION_PERIOD_SECONDS || (60 * 300000); // 30 min
const FRAUD_PROOF_WINDOW_SECONDS = env.FRAUD_PROOF_WINDOW_SECONDS || (60 * 60 * 24 * 7); // 7 days
const SEQUENCER_PUBLISH_WINDOW_SECONDS = env.SEQUENCER_PUBLISH_WINDOW_SECONDS || (60 * 30); // 30 min
const CHAIN_ID = env.CHAIN_ID || 420; // layer 2 chainid
const USE_LEDGER = env.USE_LEDGER || false;
const HD_PATH = env.HD_PATH || utils.defaultPath;
const L2_CROSS_DOMAIN_MESSENGER_ADDRESS =
env.L2_CROSS_DOMAIN_MESSENGER_ADDRESS || '0x4200000000000000000000000000000000000007';
(async () => {
const provider = new JsonRpcProvider(web3Url);
let signer;
......@@ -54,6 +58,10 @@ const L2_CROSS_DOMAIN_MESSENGER_ADDRESS =
forceInclusionPeriodSeconds: FORCE_INCLUSION_PERIOD_SECONDS,
sequencer: SEQUENCER_ADDRESS,
},
stateChainConfig: {
fraudProofWindowSeconds: FRAUD_PROOF_WINDOW_SECONDS,
sequencerPublishWindowSeconds: SEQUENCER_PUBLISH_WINDOW_SECONDS,
},
ovmGlobalContext: {
ovmCHAINID: CHAIN_ID,
L2CrossDomainMessengerAddress: L2_CROSS_DOMAIN_MESSENGER_ADDRESS
......
......@@ -25,8 +25,8 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
* Constants *
*************/
uint256 constant public FRAUD_PROOF_WINDOW = 7 days;
uint256 constant public SEQUENCER_PUBLISH_WINDOW = 30 minutes;
uint256 public FRAUD_PROOF_WINDOW;
uint256 public SEQUENCER_PUBLISH_WINDOW;
/*************
......@@ -46,8 +46,13 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
* @param _libAddressManager Address of the Address Manager.
*/
constructor(
address _libAddressManager
) Lib_AddressResolver(_libAddressManager) {}
address _libAddressManager,
uint256 _fraudProofWindow,
uint256 _sequencerPublishWindow
) Lib_AddressResolver(_libAddressManager) {
FRAUD_PROOF_WINDOW = _fraudProofWindow;
SEQUENCER_PUBLISH_WINDOW = _sequencerPublishWindow;
}
/********************
......@@ -203,7 +208,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
require(
Lib_MerkleUtils.verify(
_batchHeader.batchRoot,
_element,
abi.encodePacked(_element),
_proof.index,
_proof.siblings
),
......@@ -402,6 +407,14 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
extraData: _extraData
});
emit StateBatchAppended(
batchHeader.batchIndex,
batchHeader.batchRoot,
batchHeader.batchSize,
batchHeader.prevTotalElements,
batchHeader.extraData
);
batches.push(
Lib_OVMCodec.hashBatchHeader(batchHeader),
_makeBatchExtraData(
......
......@@ -10,6 +10,18 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
*/
interface iOVM_StateCommitmentChain {
/**********
* Events *
**********/
event StateBatchAppended(
uint256 indexed _batchIndex,
bytes32 _batchRoot,
uint256 _batchSize,
uint256 _prevTotalElements,
bytes _extraData
);
/********************
* Public Functions *
********************/
......
......@@ -96,7 +96,7 @@ library Lib_MerkleUtils {
for (uint256 i = 0; i < _siblings.length; i++) {
bytes32 sibling = _siblings[i];
bool isRightSibling = uint8(_path >> i & 1) == 1;
bool isRightSibling = uint8(_path >> i & 1) == 0;
if (isRightSibling) {
computedRoot = _getParentHash(computedRoot, sibling);
......
......@@ -21,6 +21,10 @@ export interface RollupDeployConfig {
sequencer: string | Signer
forceInclusionPeriodSeconds: number
}
stateChainConfig: {
fraudProofWindowSeconds: number
sequencerPublishWindowSeconds: number
}
whitelistConfig: {
owner: string | Signer
allowArbitraryContractDeployment: boolean
......@@ -87,7 +91,11 @@ export const makeContractDeployConfig = async (
},
OVM_StateCommitmentChain: {
factory: getContractFactory('OVM_StateCommitmentChain'),
params: [AddressManager.address],
params: [
AddressManager.address,
config.stateChainConfig.fraudProofWindowSeconds,
config.stateChainConfig.sequencerPublishWindowSeconds,
],
afterDeploy: async (contracts): Promise<void> => {
await contracts.OVM_StateCommitmentChain.init()
},
......
......@@ -125,6 +125,10 @@ export const makeStateDump = async (): Promise<any> => {
sequencer: signer,
forceInclusionPeriodSeconds: 600,
},
stateChainConfig: {
fraudProofWindowSeconds: 600,
sequencerPublishWindowSeconds: 60_000,
},
whitelistConfig: {
owner: signer,
allowArbitraryContractDeployment: true,
......
......@@ -71,7 +71,9 @@ describe('OVM_StateCommitmentChain', () => {
let OVM_StateCommitmentChain: Contract
beforeEach(async () => {
OVM_StateCommitmentChain = await Factory__OVM_StateCommitmentChain.deploy(
AddressManager.address
AddressManager.address,
60 * 60 * 24 * 7, // 1 week fraud proof window
60 * 30 // 30 minute sequencer publish window
)
await OVM_StateCommitmentChain.init()
})
......
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