Commit 3273df8b authored by Kelvin Fichter's avatar Kelvin Fichter Committed by GitHub

Added changes to make state transitioner work (#91)

parent d824abcc
...@@ -7,6 +7,8 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol"; ...@@ -7,6 +7,8 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol"; import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import { Lib_EthUtils } from "../../libraries/utils/Lib_EthUtils.sol"; import { Lib_EthUtils } from "../../libraries/utils/Lib_EthUtils.sol";
import { Lib_SecureMerkleTrie } from "../../libraries/trie/Lib_SecureMerkleTrie.sol"; import { Lib_SecureMerkleTrie } from "../../libraries/trie/Lib_SecureMerkleTrie.sol";
import { Lib_RLPWriter } from "../../libraries/rlp/Lib_RLPWriter.sol";
import { Lib_RLPReader } from "../../libraries/rlp/Lib_RLPReader.sol";
/* Interface Imports */ /* Interface Imports */
import { iOVM_StateTransitioner } from "../../iOVM/verification/iOVM_StateTransitioner.sol"; import { iOVM_StateTransitioner } from "../../iOVM/verification/iOVM_StateTransitioner.sol";
...@@ -266,13 +268,15 @@ contract OVM_StateTransitioner is Lib_AddressResolver, OVM_FraudContributor, iOV ...@@ -266,13 +268,15 @@ contract OVM_StateTransitioner is Lib_AddressResolver, OVM_FraudContributor, iOV
( (
bool exists, bool exists,
bytes memory value bytes memory encodedValue
) = Lib_SecureMerkleTrie.get( ) = Lib_SecureMerkleTrie.get(
abi.encodePacked(_key), abi.encodePacked(_key),
_storageTrieWitness, _storageTrieWitness,
ovmStateManager.getAccountStorageRoot(_ovmContractAddress) ovmStateManager.getAccountStorageRoot(_ovmContractAddress)
); );
bytes memory value = Lib_RLPReader.readBytes(encodedValue);
if (exists == true) { if (exists == true) {
require( require(
keccak256(value) == keccak256(abi.encodePacked(_value)), keccak256(value) == keccak256(abi.encodePacked(_value)),
...@@ -393,7 +397,9 @@ contract OVM_StateTransitioner is Lib_AddressResolver, OVM_FraudContributor, iOV ...@@ -393,7 +397,9 @@ contract OVM_StateTransitioner is Lib_AddressResolver, OVM_FraudContributor, iOV
account.storageRoot = Lib_SecureMerkleTrie.update( account.storageRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_key), abi.encodePacked(_key),
abi.encodePacked(value), Lib_RLPWriter.writeBytes(
abi.encodePacked(value)
),
_storageTrieWitness, _storageTrieWitness,
account.storageRoot account.storageRoot
); );
......
...@@ -302,11 +302,7 @@ describe('BondManager', () => { ...@@ -302,11 +302,7 @@ describe('BondManager', () => {
// a dispute is created about a block that intersects // a dispute is created about a block that intersects
const disputeTimestamp = withdrawalTimestamp - 100 const disputeTimestamp = withdrawalTimestamp - 100
await fraudVerifier.finalize( await fraudVerifier.finalize(preStateRoot, sender, disputeTimestamp)
preStateRoot,
sender,
disputeTimestamp
)
await mineBlock(deployer.provider, timestamp) await mineBlock(deployer.provider, timestamp)
await expect(bondManager.finalizeWithdrawal()).to.be.revertedWith( await expect(bondManager.finalizeWithdrawal()).to.be.revertedWith(
...@@ -321,11 +317,7 @@ describe('BondManager', () => { ...@@ -321,11 +317,7 @@ describe('BondManager', () => {
// a dispute is created, but since the fraud period is already over // a dispute is created, but since the fraud period is already over
// it doesn't matter // it doesn't matter
const disputeTimestamp = withdrawalTimestamp - ONE_WEEK - 1 const disputeTimestamp = withdrawalTimestamp - ONE_WEEK - 1
await fraudVerifier.finalize( await fraudVerifier.finalize(preStateRoot, sender, disputeTimestamp)
preStateRoot,
sender,
disputeTimestamp
)
const finalizeWithdrawalTimestamp = withdrawalTimestamp + ONE_WEEK const finalizeWithdrawalTimestamp = withdrawalTimestamp + ONE_WEEK
await mineBlock(deployer.provider, finalizeWithdrawalTimestamp) await mineBlock(deployer.provider, finalizeWithdrawalTimestamp)
......
...@@ -214,7 +214,7 @@ describe('OVM_ECDSAContractAccount', () => { ...@@ -214,7 +214,7 @@ describe('OVM_ECDSAContractAccount', () => {
it(`should revert on incorrect chainId`, async () => { it(`should revert on incorrect chainId`, async () => {
const alteredChainIdTx = { const alteredChainIdTx = {
...DEFAULT_EIP155_TX, ...DEFAULT_EIP155_TX,
chainId : 421 chainId: 421,
} }
const message = serializeNativeTransaction(alteredChainIdTx) const message = serializeNativeTransaction(alteredChainIdTx)
const sig = await signNativeTransaction(wallet, alteredChainIdTx) const sig = await signNativeTransaction(wallet, alteredChainIdTx)
......
...@@ -6,9 +6,13 @@ import { Contract, ContractFactory, Signer, BigNumber } from 'ethers' ...@@ -6,9 +6,13 @@ import { Contract, ContractFactory, Signer, BigNumber } from 'ethers'
import _ from 'lodash' import _ from 'lodash'
/* Internal Imports */ /* Internal Imports */
import { DUMMY_ACCOUNTS, DUMMY_BYTES32, ZERO_ADDRESS, EMPTY_ACCOUNT_CODE_HASH, KECCAK_256_NULL } from '../../../helpers' import {
DUMMY_ACCOUNTS,
DUMMY_BYTES32,
ZERO_ADDRESS,
EMPTY_ACCOUNT_CODE_HASH,
KECCAK_256_NULL,
} from '../../../helpers'
describe('OVM_StateManager', () => { describe('OVM_StateManager', () => {
let signer1: Signer let signer1: Signer
......
...@@ -192,7 +192,7 @@ describe('OVM_FraudVerifier', () => { ...@@ -192,7 +192,7 @@ describe('OVM_FraudVerifier', () => {
}) })
it('should revert when provided with a incorrect transaction root global index', async () => { it('should revert when provided with a incorrect transaction root global index', async () => {
await expect ( await expect(
OVM_FraudVerifier.initializeFraudVerification( OVM_FraudVerifier.initializeFraudVerification(
NULL_BYTES32, NULL_BYTES32,
DUMMY_BATCH_HEADERS[0], DUMMY_BATCH_HEADERS[0],
...@@ -202,7 +202,9 @@ describe('OVM_FraudVerifier', () => { ...@@ -202,7 +202,9 @@ describe('OVM_FraudVerifier', () => {
DUMMY_BATCH_HEADERS[0], DUMMY_BATCH_HEADERS[0],
DUMMY_BATCH_PROOFS_WITH_INDEX[0] DUMMY_BATCH_PROOFS_WITH_INDEX[0]
) )
).to.be.revertedWith('Pre-state root global index must equal to the transaction root global index.') ).to.be.revertedWith(
'Pre-state root global index must equal to the transaction root global index.'
)
}) })
}) })
}) })
......
...@@ -4,6 +4,7 @@ import { expect } from '../../../setup' ...@@ -4,6 +4,7 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from '@nomiclabs/buidler' import { ethers } from '@nomiclabs/buidler'
import { BigNumber, Contract, ContractFactory } from 'ethers' import { BigNumber, Contract, ContractFactory } from 'ethers'
import * as rlp from 'rlp'
/* Internal Imports */ /* Internal Imports */
import { import {
...@@ -234,7 +235,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -234,7 +235,7 @@ describe('OVM_StateTransitioner', () => {
nodes: [ nodes: [
{ {
key, key,
val, val: '0x' + rlp.encode(val).toString('hex'),
}, },
], ],
secure: true, secure: true,
...@@ -268,7 +269,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -268,7 +269,7 @@ describe('OVM_StateTransitioner', () => {
nodes: [ nodes: [
{ {
key, key,
val, val: '0x' + rlp.encode(val).toString('hex'),
}, },
], ],
secure: true, secure: true,
...@@ -452,7 +453,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -452,7 +453,7 @@ describe('OVM_StateTransitioner', () => {
nodes: [ nodes: [
{ {
key, key,
val, val: '0x' + rlp.encode(val).toString('hex'),
}, },
], ],
secure: true, secure: true,
...@@ -460,7 +461,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -460,7 +461,7 @@ describe('OVM_StateTransitioner', () => {
const storageTest = await storageGenerator.makeNodeUpdateTest( const storageTest = await storageGenerator.makeNodeUpdateTest(
key, key,
newVal '0x' + rlp.encode(newVal).toString('hex')
) )
const generator = await TrieTestGenerator.fromAccounts({ const generator = await TrieTestGenerator.fromAccounts({
......
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