Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3273df8b
Commit
3273df8b
authored
Dec 02, 2020
by
Kelvin Fichter
Committed by
GitHub
Dec 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added changes to make state transitioner work (#91)
parent
d824abcc
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
412 additions
and
485 deletions
+412
-485
OVM_StateTransitioner.sol
...istic-ethereum/OVM/verification/OVM_StateTransitioner.sol
+8
-2
bond.ts
packages/contracts/test/bond.ts
+2
-10
OVM_ECDSAContractAccount.spec.ts
...t/contracts/OVM/accounts/OVM_ECDSAContractAccount.spec.ts
+1
-1
OVM_StateManager.gas-spec.ts
...test/contracts/OVM/execution/OVM_StateManager.gas-spec.ts
+385
-463
OVM_StateManager.spec.ts
...cts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
+7
-3
OVM_FraudVerifier.spec.ts
...test/contracts/OVM/verification/OVM_FraudVerifier.spec.ts
+4
-2
OVM_StateTransitioner.spec.ts
.../contracts/OVM/verification/OVM_StateTransitioner.spec.ts
+5
-4
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/verification/OVM_StateTransitioner.sol
View file @
3273df8b
...
@@ -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
v
alue
bytes memory
encodedV
alue
) = 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
);
);
...
...
packages/contracts/test/bond.ts
View file @
3273df8b
...
@@ -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
)
...
...
packages/contracts/test/contracts/OVM/accounts/OVM_ECDSAContractAccount.spec.ts
View file @
3273df8b
...
@@ -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
)
...
...
packages/contracts/test/contracts/OVM/execution/OVM_StateManager.gas-spec.ts
View file @
3273df8b
...
@@ -6,7 +6,15 @@ import { Contract, ContractFactory, Signer, BigNumber } from 'ethers'
...
@@ -6,7 +6,15 @@ 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
,
NON_ZERO_ADDRESS
,
NON_NULL_BYTES32
,
STORAGE_XOR_VALUE
}
from
'
../../../helpers
'
import
{
DUMMY_ACCOUNTS
,
DUMMY_BYTES32
,
ZERO_ADDRESS
,
EMPTY_ACCOUNT_CODE_HASH
,
NON_ZERO_ADDRESS
,
NON_NULL_BYTES32
,
STORAGE_XOR_VALUE
,
}
from
'
../../../helpers
'
const
DUMMY_ACCOUNT
=
DUMMY_ACCOUNTS
[
0
]
const
DUMMY_ACCOUNT
=
DUMMY_ACCOUNTS
[
0
]
const
DUMMY_KEY
=
DUMMY_BYTES32
[
0
]
const
DUMMY_KEY
=
DUMMY_BYTES32
[
0
]
...
@@ -26,9 +34,9 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -26,9 +34,9 @@ describe('OVM_StateManager gas consumption', () => {
'
OVM_StateManager
'
'
OVM_StateManager
'
)
)
Helper_GasMeasurer
=
await
(
await
(
await
ethers
.
getContractFactory
(
Helper_GasMeasurer
=
await
(
'
Helper_GasMeasurer
'
await
(
await
ethers
.
getContractFactory
(
'
Helper_GasMeasurer
'
)).
deploy
()
)).
deploy
()
).
connect
(
owner
)
).
connect
(
owner
)
})
})
let
OVM_StateManager
:
Contract
let
OVM_StateManager
:
Contract
...
@@ -43,7 +51,9 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -43,7 +51,9 @@ describe('OVM_StateManager gas consumption', () => {
const
measure
=
(
const
measure
=
(
methodName
:
string
,
methodName
:
string
,
methodArgs
:
Array
<
any
>
=
[],
methodArgs
:
Array
<
any
>
=
[],
doFirst
:
()
=>
Promise
<
any
>
=
async
()
=>
{
return
}
doFirst
:
()
=>
Promise
<
any
>
=
async
()
=>
{
return
}
)
=>
{
)
=>
{
it
(
'
measured consumption!
'
,
async
()
=>
{
it
(
'
measured consumption!
'
,
async
()
=>
{
await
doFirst
()
await
doFirst
()
...
@@ -51,13 +61,13 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -51,13 +61,13 @@ describe('OVM_StateManager gas consumption', () => {
})
})
}
}
const
getSMGasCost
=
async
(
methodName
:
string
,
methodArgs
:
Array
<
any
>
=
[]):
Promise
<
number
>
=>
{
const
getSMGasCost
=
async
(
methodName
:
string
,
methodArgs
:
Array
<
any
>
=
[]
):
Promise
<
number
>
=>
{
const
gasCost
:
number
=
await
Helper_GasMeasurer
.
callStatic
.
measureCallGas
(
const
gasCost
:
number
=
await
Helper_GasMeasurer
.
callStatic
.
measureCallGas
(
OVM_StateManager
.
address
,
OVM_StateManager
.
address
,
OVM_StateManager
.
interface
.
encodeFunctionData
(
OVM_StateManager
.
interface
.
encodeFunctionData
(
methodName
,
methodArgs
)
methodName
,
methodArgs
)
)
)
console
.
log
(
` calculated gas cost of
${
gasCost
}
`
)
console
.
log
(
` calculated gas cost of
${
gasCost
}
`
)
...
@@ -71,10 +81,7 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -71,10 +81,7 @@ describe('OVM_StateManager gas consumption', () => {
})
})
}
}
const
setupNonFreshAccount
=
async
()
=>
{
const
setupNonFreshAccount
=
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
DUMMY_ACCOUNT
.
data
)
DUMMY_ACCOUNT
.
address
,
DUMMY_ACCOUNT
.
data
)
}
}
const
putSlot
=
async
(
value
:
string
)
=>
{
const
putSlot
=
async
(
value
:
string
)
=>
{
await
OVM_StateManager
.
putContractStorage
(
await
OVM_StateManager
.
putContractStorage
(
...
@@ -87,71 +94,52 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -87,71 +94,52 @@ describe('OVM_StateManager gas consumption', () => {
describe
(
'
ItemState testAndSetters
'
,
()
=>
{
describe
(
'
ItemState testAndSetters
'
,
()
=>
{
describe
(
'
testAndSetAccountLoaded
'
,
()
=>
{
describe
(
'
testAndSetAccountLoaded
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
])
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
]
)
})
})
describe
(
'
when account ItemState is ITEM_LOADED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_LOADED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
await
OVM_StateManager
.
testAndSetAccountLoaded
(
NON_ZERO_ADDRESS
)
await
OVM_StateManager
.
testAndSetAccountLoaded
(
NON_ZERO_ADDRESS
)
}
})
)
})
})
describe
(
'
when account ItemState is ITEM_CHANGED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_CHANGED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
'
testAndSetAccountLoaded
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
await
OVM_StateManager
.
testAndSetAccountChanged
(
NON_ZERO_ADDRESS
)
await
OVM_StateManager
.
testAndSetAccountChanged
(
NON_ZERO_ADDRESS
)
}
})
)
})
})
})
})
describe
(
'
testAndSetAccountChanged
'
,
()
=>
{
describe
(
'
testAndSetAccountChanged
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
])
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
]
)
})
})
describe
(
'
when account ItemState is ITEM_LOADED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_LOADED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
await
OVM_StateManager
.
testAndSetAccountLoaded
(
NON_ZERO_ADDRESS
)
await
OVM_StateManager
.
testAndSetAccountLoaded
(
NON_ZERO_ADDRESS
)
}
})
)
})
})
describe
(
'
when account ItemState is ITEM_CHANGED
'
,
()
=>
{
describe
(
'
when account ItemState is ITEM_CHANGED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
'
testAndSetAccountChanged
'
,
[
NON_ZERO_ADDRESS
],
async
()
=>
{
await
OVM_StateManager
.
testAndSetAccountChanged
(
NON_ZERO_ADDRESS
)
await
OVM_StateManager
.
testAndSetAccountChanged
(
NON_ZERO_ADDRESS
)
}
})
)
})
})
})
})
describe
(
'
testAndSetContractStorageLoaded
'
,
()
=>
{
describe
(
'
testAndSetContractStorageLoaded
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetContractStorageLoaded
'
,
[
'
testAndSetContractStorageLoaded
'
,
NON_ZERO_ADDRESS
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
]
DUMMY_KEY
,
)
]
)
})
})
describe
(
'
when storage ItemState is ITEM_LOADED
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_LOADED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetContractStorageLoaded
'
,
'
testAndSetContractStorageLoaded
'
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
async
()
=>
{
async
()
=>
{
await
OVM_StateManager
.
testAndSetContractStorageLoaded
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
await
OVM_StateManager
.
testAndSetContractStorageLoaded
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
}
}
)
)
})
})
...
@@ -160,7 +148,10 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -160,7 +148,10 @@ describe('OVM_StateManager gas consumption', () => {
'
testAndSetContractStorageLoaded
'
,
'
testAndSetContractStorageLoaded
'
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
async
()
=>
{
async
()
=>
{
await
OVM_StateManager
.
testAndSetContractStorageChanged
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
await
OVM_StateManager
.
testAndSetContractStorageChanged
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
}
}
)
)
})
})
...
@@ -168,17 +159,20 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -168,17 +159,20 @@ describe('OVM_StateManager gas consumption', () => {
describe
(
'
testAndSetContractStorageChanged
'
,
()
=>
{
describe
(
'
testAndSetContractStorageChanged
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_UNTOUCHED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetContractStorageChanged
'
,
[
'
testAndSetContractStorageChanged
'
,
NON_ZERO_ADDRESS
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
]
DUMMY_KEY
,
)
]
)
})
})
describe
(
'
when storage ItemState is ITEM_LOADED
'
,
()
=>
{
describe
(
'
when storage ItemState is ITEM_LOADED
'
,
()
=>
{
measure
(
measure
(
'
testAndSetContractStorageChanged
'
,
'
testAndSetContractStorageChanged
'
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
async
()
=>
{
async
()
=>
{
await
OVM_StateManager
.
testAndSetContractStorageLoaded
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
await
OVM_StateManager
.
testAndSetContractStorageLoaded
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
}
}
)
)
})
})
...
@@ -187,7 +181,10 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -187,7 +181,10 @@ describe('OVM_StateManager gas consumption', () => {
'
testAndSetContractStorageChanged
'
,
'
testAndSetContractStorageChanged
'
,
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
[
NON_ZERO_ADDRESS
,
DUMMY_KEY
],
async
()
=>
{
async
()
=>
{
await
OVM_StateManager
.
testAndSetContractStorageChanged
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
await
OVM_StateManager
.
testAndSetContractStorageChanged
(
NON_ZERO_ADDRESS
,
DUMMY_KEY
)
}
}
)
)
})
})
...
@@ -226,178 +223,107 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -226,178 +223,107 @@ describe('OVM_StateManager gas consumption', () => {
DUMMY_ACCOUNT
.
data
DUMMY_ACCOUNT
.
data
)
)
}
}
measure
(
measure
(
'
hasAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
doFirst
)
'
hasAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
doFirst
)
})
})
})
})
describe
(
'
hasEmptyAccount
'
,
()
=>
{
describe
(
'
hasEmptyAccount
'
,
()
=>
{
describe
(
'
when it does have an empty account
'
,
()
=>
{
describe
(
'
when it does have an empty account
'
,
()
=>
{
measure
(
measure
(
'
hasEmptyAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
'
hasEmptyAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
codeHash
:
EMPTY_ACCOUNT_CODE_HASH
,
codeHash
:
EMPTY_ACCOUNT_CODE_HASH
,
})
})
}
})
)
})
})
describe
(
'
when it has an account which is not emtpy
'
,
()
=>
{
describe
(
'
when it has an account which is not emtpy
'
,
()
=>
{
measure
(
measure
(
'
hasEmptyAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
'
hasEmptyAccount
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
DUMMY_ACCOUNT
.
address
,
DUMMY_ACCOUNT
.
data
DUMMY_ACCOUNT
.
data
)
)
}
})
)
})
})
})
})
describe
(
'
setAccountNonce
'
,
()
=>
{
describe
(
'
setAccountNonce
'
,
()
=>
{
describe
(
'
when the nonce is 0 and set to 0
'
,
()
=>
{
describe
(
'
when the nonce is 0 and set to 0
'
,
()
=>
{
measure
(
measure
(
'
setAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
,
0
],
async
()
=>
{
'
setAccountNonce
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
,
0
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
nonce
:
0
nonce
:
0
,
}
})
)
})
}
)
})
})
describe
(
'
when the nonce is 0 and set to nonzero
'
,
()
=>
{
describe
(
'
when the nonce is 0 and set to nonzero
'
,
()
=>
{
measure
(
measure
(
'
setAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
,
1
],
async
()
=>
{
'
setAccountNonce
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
,
1
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
nonce
:
0
nonce
:
0
,
}
})
)
})
}
)
})
})
describe
(
'
when the nonce is nonzero and set to 0
'
,
()
=>
{
describe
(
'
when the nonce is nonzero and set to 0
'
,
()
=>
{
measure
(
measure
(
'
setAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
,
0
],
async
()
=>
{
'
setAccountNonce
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
,
0
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
nonce
:
1
nonce
:
1
,
}
})
)
})
}
)
})
})
describe
(
'
when the nonce is nonzero and set to nonzero
'
,
()
=>
{
describe
(
'
when the nonce is nonzero and set to nonzero
'
,
()
=>
{
measure
(
measure
(
'
setAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
,
2
],
async
()
=>
{
'
setAccountNonce
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
,
2
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
nonce
:
1
nonce
:
1
,
}
})
)
})
}
)
})
})
})
})
describe
(
'
getAccountNonce
'
,
()
=>
{
describe
(
'
getAccountNonce
'
,
()
=>
{
describe
(
'
when the nonce is 0
'
,
()
=>
{
describe
(
'
when the nonce is 0
'
,
()
=>
{
measure
(
measure
(
'
getAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
])
'
getAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
]
)
})
})
describe
(
'
when the nonce is nonzero
'
,
()
=>
{
describe
(
'
when the nonce is nonzero
'
,
()
=>
{
measure
(
measure
(
'
getAccountNonce
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
'
getAccountNonce
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
nonce
:
1
nonce
:
1
,
}
})
)
})
}
)
})
})
})
})
describe
(
'
getAccountEthAddress
'
,
()
=>
{
describe
(
'
getAccountEthAddress
'
,
()
=>
{
describe
(
'
when the ethAddress is a random address
'
,
()
=>
{
describe
(
'
when the ethAddress is a random address
'
,
()
=>
{
measure
(
measure
(
'
getAccountEthAddress
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
'
getAccountEthAddress
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
ethAddress
:
NON_ZERO_ADDRESS
ethAddress
:
NON_ZERO_ADDRESS
,
}
})
)
})
}
)
})
})
describe
(
'
when the ethAddress is zero
'
,
()
=>
{
describe
(
'
when the ethAddress is zero
'
,
()
=>
{
measure
(
measure
(
'
getAccountEthAddress
'
,
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
'
getAccountEthAddress
'
,
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
[
DUMMY_ACCOUNT
.
address
],
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNT
.
address
,
{
...
DUMMY_ACCOUNT
.
data
,
...
DUMMY_ACCOUNT
.
data
,
ethAddress
:
ZERO_ADDRESS
ethAddress
:
ZERO_ADDRESS
,
}
})
)
})
}
)
})
})
})
})
describe
(
'
initPendingAccount
'
,
()
=>
{
describe
(
'
initPendingAccount
'
,
()
=>
{
// note: this method should only be accessibl if _hasEmptyAccount is true, so it should always be empty nonce etc
// note: this method should only be accessibl if _hasEmptyAccount is true, so it should always be empty nonce etc
measure
(
measure
(
'
initPendingAccount
'
,
[
NON_ZERO_ADDRESS
])
'
initPendingAccount
'
,
[
NON_ZERO_ADDRESS
]
)
})
})
describe
(
'
commitPendingAccount
'
,
()
=>
{
describe
(
'
commitPendingAccount
'
,
()
=>
{
// this should only set ethAddress and codeHash from ZERO to NONZERO, so one case should be sufficient
// this should only set ethAddress and codeHash from ZERO to NONZERO, so one case should be sufficient
measure
(
measure
(
'
commitPendingAccount
'
,
'
commitPendingAccount
'
,
[
[
NON_ZERO_ADDRESS
,
NON_ZERO_ADDRESS
,
NON_NULL_BYTES32
],
NON_ZERO_ADDRESS
,
NON_ZERO_ADDRESS
,
NON_NULL_BYTES32
],
async
()
=>
{
async
()
=>
{
await
OVM_StateManager
.
initPendingAccount
(
NON_ZERO_ADDRESS
)
await
OVM_StateManager
.
initPendingAccount
(
NON_ZERO_ADDRESS
)
}
}
...
@@ -462,11 +388,7 @@ describe('OVM_StateManager gas consumption', () => {
...
@@ -462,11 +388,7 @@ describe('OVM_StateManager gas consumption', () => {
})
})
describe
(
'
putContractStorage
'
,
()
=>
{
describe
(
'
putContractStorage
'
,
()
=>
{
const
relevantValues
=
[
const
relevantValues
=
[
DUMMY_VALUE_1
,
DUMMY_VALUE_2
,
STORAGE_XOR_VALUE
]
DUMMY_VALUE_1
,
DUMMY_VALUE_2
,
STORAGE_XOR_VALUE
]
for
(
let
preValue
of
relevantValues
)
{
for
(
let
preValue
of
relevantValues
)
{
for
(
let
postValue
of
relevantValues
)
{
for
(
let
postValue
of
relevantValues
)
{
describe
(
`when overwriting
${
preValue
}
with
${
postValue
}
`
,
()
=>
{
describe
(
`when overwriting
${
preValue
}
with
${
postValue
}
`
,
()
=>
{
...
...
packages/contracts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
View file @
3273df8b
...
@@ -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
...
...
packages/contracts/test/contracts/OVM/verification/OVM_FraudVerifier.spec.ts
View file @
3273df8b
...
@@ -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.
'
)
})
})
})
})
})
})
...
...
packages/contracts/test/contracts/OVM/verification/OVM_StateTransitioner.spec.ts
View file @
3273df8b
...
@@ -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
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment