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
acb50b70
Commit
acb50b70
authored
Sep 18, 2020
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added proxy and fixed bugs in StateManager
parent
b1d71b87
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
665 additions
and
144 deletions
+665
-144
OVM_CanonicalTransactionChain.sol
...stic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
+12
-8
OVM_StateCommitmentChain.sol
...ptimistic-ethereum/OVM/chain/OVM_StateCommitmentChain.sol
+11
-8
OVM_FraudVerifier.sol
...s/optimistic-ethereum/OVM/execution/OVM_FraudVerifier.sol
+19
-24
OVM_StateManager.sol
...ts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol
+177
-7
OVM_StateManagerFactory.sol
...mistic-ethereum/OVM/execution/OVM_StateManagerFactory.sol
+9
-2
OVM_StateTransitioner.sol
...timistic-ethereum/OVM/execution/OVM_StateTransitioner.sol
+30
-30
OVM_StateTransitionerFactory.sol
...c-ethereum/OVM/execution/OVM_StateTransitionerFactory.sol
+10
-2
OVM_L1ToL2TransactionQueue.sol
...imistic-ethereum/OVM/queue/OVM_L1ToL2TransactionQueue.sol
+10
-5
iOVM_StateManager.sol
.../optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol
+13
-1
iOVM_StateManagerFactory.sol
...stic-ethereum/iOVM/execution/iOVM_StateManagerFactory.sol
+3
-1
iOVM_StateTransitioner.sol
...mistic-ethereum/iOVM/execution/iOVM_StateTransitioner.sol
+1
-1
iOVM_StateTransitionerFactory.sol
...ethereum/iOVM/execution/iOVM_StateTransitionerFactory.sol
+1
-1
Lib_OVMCodec.sol
...acts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol
+32
-0
Lib_EthMerkleTrie.sol
.../optimistic-ethereum/libraries/trie/Lib_EthMerkleTrie.sol
+18
-15
Lib_MerkleTrie.sol
...cts/optimistic-ethereum/libraries/trie/Lib_MerkleTrie.sol
+39
-39
Proxy_Forwarder.sol
...s/contracts/optimistic-ethereum/proxy/Proxy_Forwarder.sol
+72
-0
Proxy_Manager.sol
...cts/contracts/optimistic-ethereum/proxy/Proxy_Manager.sol
+166
-0
Proxy_Resolver.sol
...ts/contracts/optimistic-ethereum/proxy/Proxy_Resolver.sol
+42
-0
No files found.
packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
View file @
acb50b70
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Proxy Imports */
import { Proxy_Resolver } from "../../proxy/Proxy_Resolver.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
import { Lib_MerkleUtils } from "../../libraries/utils/Lib_MerkleUtils.sol";
...
@@ -16,7 +19,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
...
@@ -16,7 +19,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
/**
/**
* @title OVM_CanonicalTransactionChain
* @title OVM_CanonicalTransactionChain
*/
*/
contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_BaseChain {
contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_BaseChain
, Proxy_Resolver
{
/*******************************************
/*******************************************
* Contract Variables: Contract References *
* Contract Variables: Contract References *
...
@@ -39,17 +42,18 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
...
@@ -39,17 +42,18 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
***************/
***************/
/**
/**
* @param _ovmL1ToL2TransactionQueue Address of the OVM_L1ToL2TransactionQueue.
* @param _proxyManager Address of the Proxy_Manager.
* @param _sequencer Address of the current sequencer.
* @param _forceInclusionPeriodSeconds Period during which only the sequencer can submit.
* @param _forceInclusionPeriodSeconds Period during which only the sequencer can submit.
*/
*/
constructor(
constructor(
address _ovmL1ToL2TransactionQueue,
address _proxyManager,
address _sequencer,
uint256 _forceInclusionPeriodSeconds
uint256 _forceInclusionPeriodSeconds
) {
)
ovmL1ToL2TransactionQueue = iOVM_L1ToL2TransactionQueue(_ovmL1ToL2TransactionQueue);
Proxy_Resolver(_proxyManager)
sequencer = _sequencer;
{
ovmL1ToL2TransactionQueue = iOVM_L1ToL2TransactionQueue(resolve("OVM_L1ToL2TransactionQueue"));
sequencer = resolve("Sequencer");
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
}
}
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_StateCommitmentChain.sol
View file @
acb50b70
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Proxy Imports */
import { Proxy_Resolver } from "../../proxy/Proxy_Resolver.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
...
@@ -16,7 +19,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
...
@@ -16,7 +19,7 @@ import { OVM_BaseChain } from "./OVM_BaseChain.sol";
/**
/**
* @title OVM_StateCommitmentChain
* @title OVM_StateCommitmentChain
*/
*/
contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, OVM_BaseChain {
contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, OVM_BaseChain
, Proxy_Resolver
{
/*******************************************
/*******************************************
* Contract Variables: Contract References *
* Contract Variables: Contract References *
...
@@ -31,15 +34,15 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, OVM_BaseChain {
...
@@ -31,15 +34,15 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, OVM_BaseChain {
***************/
***************/
/**
/**
* @param _ovmCanonicalTransactionChain Address of the OVM_CanonicalTransactionChain.
* @param _proxyManager Address of the Proxy_Manager.
* @param _ovmFraudVerifier Address of the OVM_FraudVerifier.
*/
*/
constructor(
constructor(
address _ovmCanonicalTransactionChain,
address _proxyManager
address _ovmFraudVerifier
)
) {
Proxy_Resolver(_proxyManager)
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(_ovmCanonicalTransactionChain);
{
ovmFraudVerifier = iOVM_FraudVerifier(_ovmFraudVerifier);
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
ovmFraudVerifier = iOVM_FraudVerifier(resolve("OVM_FraudVerifier"));
}
}
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_FraudVerifier.sol
View file @
acb50b70
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Proxy Imports */
import { Proxy_Resolver } from "../../proxy/Proxy_Resolver.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
...
@@ -14,7 +17,7 @@ import { iOVM_StateManagerFactory } from "../../iOVM/execution/iOVM_StateManager
...
@@ -14,7 +17,7 @@ import { iOVM_StateManagerFactory } from "../../iOVM/execution/iOVM_StateManager
import { iOVM_StateCommitmentChain } from "../../iOVM/chain/iOVM_StateCommitmentChain.sol";
import { iOVM_StateCommitmentChain } from "../../iOVM/chain/iOVM_StateCommitmentChain.sol";
import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalTransactionChain.sol";
import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalTransactionChain.sol";
contract OVM_FraudVerifier is iOVM_FraudVerifier {
contract OVM_FraudVerifier is iOVM_FraudVerifier
, Proxy_Resolver
{
/*******************************************
/*******************************************
* Contract Variables: Contract References *
* Contract Variables: Contract References *
...
@@ -22,8 +25,6 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -22,8 +25,6 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
iOVM_StateCommitmentChain internal ovmStateCommitmentChain;
iOVM_StateCommitmentChain internal ovmStateCommitmentChain;
iOVM_CanonicalTransactionChain internal ovmCanonicalTransactionChain;
iOVM_CanonicalTransactionChain internal ovmCanonicalTransactionChain;
iOVM_ExecutionManager internal ovmExecutionManager;
iOVM_StateManagerFactory internal ovmStateManagerFactory;
/*******************************************
/*******************************************
...
@@ -38,21 +39,15 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -38,21 +39,15 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
***************/
***************/
/**
/**
* @param _ovmStateCommitmentChain Address of the OVM_StateCommitmentChain.
* @param _proxyManager Address of the Proxy_Manager.
* @param _ovmCanonicalTransactionChain Address of the OVM_CanonicalTransactionChain.
* @param _ovmExecutionManager Address of the OVM_ExecutionManager.
* @param _ovmStateManagerFactory Address of the OVM_StateManagerFactory.
*/
*/
constructor(
constructor(
address _ovmStateCommitmentChain,
address _proxyManager
address _ovmCanonicalTransactionChain,
)
address _ovmExecutionManager,
Proxy_Resolver(_proxyManager)
address _ovmStateManagerFactory,
{
) {
ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
ovmStateCommitmentChain = iOVM_StateCommitmentChain(_ovmStateCommitmentChain);
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(_ovmCanonicalTransactionChain);
ovmExecutionManager = iOVM_ExecutionManager(_ovmExecutionManager);
ovmStateManagerFactory = iOVM_StateManagerFactory(_ovmStateManagerFactory);
}
}
...
@@ -73,7 +68,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -73,7 +68,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
bytes32 _preStateRoot,
bytes32 _preStateRoot,
Lib_OVMCodec.ChainBatchHeader memory _preStateRootBatchHeader,
Lib_OVMCodec.ChainBatchHeader memory _preStateRootBatchHeader,
Lib_OVMCodec.ChainInclusionProof memory _preStateRootProof,
Lib_OVMCodec.ChainInclusionProof memory _preStateRootProof,
Lib_OVMCodec.Transaction
Data
memory _transaction,
Lib_OVMCodec.Transaction memory _transaction,
Lib_OVMCodec.ChainBatchHeader memory _transactionBatchHeader,
Lib_OVMCodec.ChainBatchHeader memory _transactionBatchHeader,
Lib_OVMCodec.ChainInclusionProof memory _transactionProof
Lib_OVMCodec.ChainInclusionProof memory _transactionProof
)
)
...
@@ -105,10 +100,10 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -105,10 +100,10 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
transitioners[_preStateRoot] = iOVM_StateTransitionerFactory(
transitioners[_preStateRoot] = iOVM_StateTransitionerFactory(
resolve("OVM_StateTransitionerFactory")
resolve("OVM_StateTransitionerFactory")
).create(
).create(
address(
libContractP
roxyManager),
address(
p
roxyManager),
_preStateRootProof.index,
_preStateRootProof.index,
_preStateRoot,
_preStateRoot,
Lib_OVMCodec.hash(_transaction)
Lib_OVMCodec.hash
Transaction
(_transaction)
);
);
}
}
...
@@ -163,7 +158,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -163,7 +158,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
);
);
require(
require(
_postStateRoot != transitioner.
p
ostStateRoot(),
_postStateRoot != transitioner.
getP
ostStateRoot(),
"State transition has not been proven fraudulent."
"State transition has not been proven fraudulent."
);
);
...
@@ -212,7 +207,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -212,7 +207,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
bool _verified
bool _verified
)
)
{
{
return ovmStateCommitmentChain.
ovmBaseChain().
verifyElement(
return ovmStateCommitmentChain.verifyElement(
abi.encodePacked(_stateRoot),
abi.encodePacked(_stateRoot),
_stateRootBatchHeader,
_stateRootBatchHeader,
_stateRootProof
_stateRootProof
...
@@ -227,7 +222,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -227,7 +222,7 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
* @return _verified Whether or not the transaction was included.
* @return _verified Whether or not the transaction was included.
*/
*/
function _verifyTransaction(
function _verifyTransaction(
Lib_OVMCodec.Transaction
Data
memory _transaction,
Lib_OVMCodec.Transaction memory _transaction,
Lib_OVMCodec.ChainBatchHeader memory _transactionBatchHeader,
Lib_OVMCodec.ChainBatchHeader memory _transactionBatchHeader,
Lib_OVMCodec.ChainInclusionProof memory _transactionProof
Lib_OVMCodec.ChainInclusionProof memory _transactionProof
)
)
...
@@ -237,8 +232,8 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
...
@@ -237,8 +232,8 @@ contract OVM_FraudVerifier is iOVM_FraudVerifier {
bool _verified
bool _verified
)
)
{
{
return ovmCanonicalTransactionChain.
ovmBaseChain().
verifyElement(
return ovmCanonicalTransactionChain.verifyElement(
Lib_OVMCodec.encode(_transaction),
Lib_OVMCodec.encode
Transaction
(_transaction),
_transactionBatchHeader,
_transactionBatchHeader,
_transactionProof
_transactionProof
);
);
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol
View file @
acb50b70
...
@@ -13,6 +13,14 @@ import { iOVM_StateManager } from "../../iOVM/execution/iOVM_StateManager.sol";
...
@@ -13,6 +13,14 @@ import { iOVM_StateManager } from "../../iOVM/execution/iOVM_StateManager.sol";
*/
*/
contract OVM_StateManager is iOVM_StateManager {
contract OVM_StateManager is iOVM_StateManager {
/*******************************************
* Contract Variables: Contract References *
*******************************************/
address internal owner;
address internal ovmExecutionManager;
/****************************************
/****************************************
* Contract Variables: Internal Storage *
* Contract Variables: Internal Storage *
****************************************/
****************************************/
...
@@ -21,6 +29,58 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -21,6 +29,58 @@ contract OVM_StateManager is iOVM_StateManager {
mapping (address => mapping (bytes32 => bytes32)) internal contractStorage;
mapping (address => mapping (bytes32 => bytes32)) internal contractStorage;
mapping (address => mapping (bytes32 => bool)) internal verifiedContractStorage;
mapping (address => mapping (bytes32 => bool)) internal verifiedContractStorage;
mapping (bytes32 => ItemState) internal itemStates;
mapping (bytes32 => ItemState) internal itemStates;
uint256 internal totalUncommittedAccounts;
uint256 internal totalUncommittedContractStorage;
/***************
* Constructor *
***************/
/**
* @param _owner Address of the owner of this contract.
*/
constructor(
address _owner
) {
owner = _owner;
}
/**********************
* Function Modifiers *
**********************/
/**
* Simple authentication, this contract should only be accessible to the owner or to the
* OVM_ExecutionManager during the transaction execution process.
*/
modifier authenticated() {
require(
msg.sender == owner || msg.sender == ovmExecutionManager,
"Function can only be called by authenticated addresses"
);
_;
}
/***************************
* Public Functions: Setup *
***************************/
/**
* Sets the address of the OVM_ExecutionManager.
* @param _ovmExecutionManager Address of the OVM_ExecutionManager.
*/
function setExecutionManager(
address _ovmExecutionManager
)
override
public
authenticated
{
ovmExecutionManager = _ovmExecutionManager;
}
/************************************
/************************************
...
@@ -38,6 +98,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -38,6 +98,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
{
{
accounts[_address] = _account;
accounts[_address] = _account;
}
}
...
@@ -50,6 +111,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -50,6 +111,7 @@ contract OVM_StateManager is iOVM_StateManager {
function getAccount(address _address)
function getAccount(address _address)
override
override
public
public
authenticated
returns (
returns (
Lib_OVMCodec.Account memory _account
Lib_OVMCodec.Account memory _account
)
)
...
@@ -67,6 +129,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -67,6 +129,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _exists
bool _exists
)
)
...
@@ -85,6 +148,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -85,6 +148,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
{
{
accounts[_address].nonce = _nonce;
accounts[_address].nonce = _nonce;
}
}
...
@@ -99,6 +163,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -99,6 +163,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
uint256 _nonce
uint256 _nonce
)
)
...
@@ -116,6 +181,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -116,6 +181,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
address _ethAddress
address _ethAddress
)
)
...
@@ -132,6 +198,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -132,6 +198,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
{
{
Lib_OVMCodec.Account storage account = accounts[_address];
Lib_OVMCodec.Account storage account = accounts[_address];
account.nonce = 1;
account.nonce = 1;
...
@@ -151,6 +218,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -151,6 +218,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
{
{
Lib_OVMCodec.Account storage account = accounts[_address];
Lib_OVMCodec.Account storage account = accounts[_address];
account.ethAddress = _ethAddress;
account.ethAddress = _ethAddress;
...
@@ -167,11 +235,12 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -167,11 +235,12 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _wasAccountAlreadyLoaded
bool _wasAccountAlreadyLoaded
)
)
{
{
return _testItemState(
return _test
AndSet
ItemState(
keccak256(abi.encodePacked(_address)),
keccak256(abi.encodePacked(_address)),
ItemState.ITEM_LOADED
ItemState.ITEM_LOADED
);
);
...
@@ -187,14 +256,62 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -187,14 +256,62 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _wasAccountAlreadyChanged
bool _wasAccountAlreadyChanged
)
)
{
{
return _tes
tItemState(
bool wasAccountAlreadyChanged = _testAndSe
tItemState(
keccak256(abi.encodePacked(_address)),
keccak256(abi.encodePacked(_address)),
ItemState.ITEM_CHANGED
ItemState.ITEM_CHANGED
);
);
if (!wasAccountAlreadyChanged) {
totalUncommittedAccounts += 1;
}
return wasAccountAlreadyChanged;
}
/**
* Attempts to mark an account as committed.
* @param _address Address of the account to commit.
* @return _wasAccountCommitted Whether or not the account was committed.
*/
function commitAccount(
address _address
)
override
public
authenticated
returns (
bool _wasAccountCommitted
)
{
bytes32 item = keccak256(abi.encodePacked(_address));
if (itemStates[item] != ItemState.ITEM_CHANGED) {
return false;
}
itemStates[item] = ItemState.ITEM_COMMITTED;
totalUncommittedAccounts -= 1;
return true;
}
/**
* Gets the total number of uncommitted accounts.
* @return _total Total uncommitted accounts.
*/
function getTotalUncommittedAccounts()
override
public
authenticated
returns (
uint256 _total
)
{
return totalUncommittedAccounts;
}
}
...
@@ -215,6 +332,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -215,6 +332,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
{
{
contractStorage[_contract][_key] = _value;
contractStorage[_contract][_key] = _value;
verifiedContractStorage[_contract][_key] = true;
verifiedContractStorage[_contract][_key] = true;
...
@@ -232,6 +350,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -232,6 +350,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bytes32 _value
bytes32 _value
)
)
...
@@ -251,6 +370,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -251,6 +370,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _exists
bool _exists
)
)
...
@@ -270,11 +390,12 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -270,11 +390,12 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _wasContractStorageAlreadyLoaded
bool _wasContractStorageAlreadyLoaded
)
)
{
{
return _testItemState(
return _test
AndSet
ItemState(
keccak256(abi.encodePacked(_contract, _key)),
keccak256(abi.encodePacked(_contract, _key)),
ItemState.ITEM_LOADED
ItemState.ITEM_LOADED
);
);
...
@@ -292,14 +413,64 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -292,14 +413,64 @@ contract OVM_StateManager is iOVM_StateManager {
)
)
override
override
public
public
authenticated
returns (
returns (
bool _wasContractStorageAlreadyChanged
bool _wasContractStorageAlreadyChanged
)
)
{
{
return _tes
tItemState(
bool wasContractStorageAlreadyChanged = _testAndSe
tItemState(
keccak256(abi.encodePacked(_contract, _key)),
keccak256(abi.encodePacked(_contract, _key)),
ItemState.ITEM_CHANGED
ItemState.ITEM_CHANGED
);
);
if (!wasContractStorageAlreadyChanged) {
totalUncommittedContractStorage += 1;
}
return wasContractStorageAlreadyChanged;
}
/**
* Attempts to mark a storage slot as committed.
* @param _contract Address of the account to commit.
* @param _key 32 byte slot key to commit.
* @return _wasContractStorageCommitted Whether or not the slot was committed.
*/
function commitContractStorage(
address _contract,
bytes32 _key
)
override
public
authenticated
returns (
bool _wasContractStorageCommitted
)
{
bytes32 item = keccak256(abi.encodePacked(_contract, _key));
if (itemStates[item] != ItemState.ITEM_CHANGED) {
return false;
}
itemStates[item] = ItemState.ITEM_COMMITTED;
totalUncommittedContractStorage -= 1;
return true;
}
/**
* Gets the total number of uncommitted storage slots.
* @return _total Total uncommitted storage slots.
*/
function getTotalUncommittedContractStorage()
override
public
authenticated
returns (
uint256 _total
)
{
return totalUncommittedContractStorage;
}
}
...
@@ -314,7 +485,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -314,7 +485,7 @@ contract OVM_StateManager is iOVM_StateManager {
* @param _minItemState Minumum state that must be satisfied by the item.
* @param _minItemState Minumum state that must be satisfied by the item.
* @return _wasItemState Whether or not the item was already in the state.
* @return _wasItemState Whether or not the item was already in the state.
*/
*/
function _testItemState(
function _test
AndSet
ItemState(
bytes32 _item,
bytes32 _item,
ItemState _minItemState
ItemState _minItemState
)
)
...
@@ -323,8 +494,7 @@ contract OVM_StateManager is iOVM_StateManager {
...
@@ -323,8 +494,7 @@ contract OVM_StateManager is iOVM_StateManager {
bool _wasItemState
bool _wasItemState
)
)
{
{
ItemState itemState = itemStates[_item];
bool wasItemState = itemStates[_item] >= _minItemState;
bool wasItemState = itemState >= _minItemState;
if (wasItemState == false) {
if (wasItemState == false) {
itemStates[_item] = _minItemState;
itemStates[_item] = _minItemState;
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_StateManagerFactory.sol
View file @
acb50b70
...
@@ -17,13 +17,20 @@ contract OVM_StateManagerFactory is iOVM_StateManagerFactory {
...
@@ -17,13 +17,20 @@ contract OVM_StateManagerFactory is iOVM_StateManagerFactory {
* Public Functions: Contract Creation *
* Public Functions: Contract Creation *
***************************************/
***************************************/
function create()
/**
* Creates a new OVM_StateManager
* @param _owner Owner of the created contract.
* @return _ovmStateManager New OVM_StateManager instance.
*/
function create(
address _owner
)
override
override
public
public
returns (
returns (
iOVM_StateManager _ovmStateManager
iOVM_StateManager _ovmStateManager
)
)
{
{
return new OVM_StateManager();
return new OVM_StateManager(
_owner
);
}
}
}
}
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_StateTransitioner.sol
View file @
acb50b70
...
@@ -2,10 +2,13 @@
...
@@ -2,10 +2,13 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Proxy Imports */
import { Proxy_Resolver } from "../../proxy/Proxy_Resolver.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../
../
libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_EthUtils } from "../../
../
libraries/utils/Lib_EthUtils.sol";
import { Lib_EthUtils } from "../../libraries/utils/Lib_EthUtils.sol";
import { Lib_EthMerkleTrie } from "../../
../
libraries/trie/Lib_EthMerkleTrie.sol";
import { Lib_EthMerkleTrie } from "../../libraries/trie/Lib_EthMerkleTrie.sol";
/* Interface Imports */
/* Interface Imports */
import { iOVM_ExecutionManager } from "../../iOVM/execution/iOVM_ExecutionManager.sol";
import { iOVM_ExecutionManager } from "../../iOVM/execution/iOVM_ExecutionManager.sol";
...
@@ -16,7 +19,7 @@ import { iOVM_StateTransitioner } from "../../iOVM/execution/iOVM_StateTransitio
...
@@ -16,7 +19,7 @@ import { iOVM_StateTransitioner } from "../../iOVM/execution/iOVM_StateTransitio
/**
/**
* @title OVM_StateTransitioner
* @title OVM_StateTransitioner
*/
*/
contract OVM_StateTransitioner is iOVM_StateTransitioner {
contract OVM_StateTransitioner is iOVM_StateTransitioner
, Proxy_Resolver
{
/*******************
/*******************
* Data Structures *
* Data Structures *
...
@@ -44,8 +47,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -44,8 +47,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
bytes32 internal preStateRoot;
bytes32 internal preStateRoot;
bytes32 internal postStateRoot;
bytes32 internal postStateRoot;
TransitionPhase internal phase;
TransitionPhase internal phase;
uint256
public
stateTransitionIndex;
uint256
internal
stateTransitionIndex;
bytes32
public
transactionHash;
bytes32
internal
transactionHash;
/***************
/***************
...
@@ -53,26 +56,26 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -53,26 +56,26 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
***************/
***************/
/**
/**
* @param _ovmExecutionManager Address of the OVM_ExecutionManager.
* @param _proxyManager Address of the Proxy_Manager.
* @param _ovmStateManagerFactory Address of the OVM_StateManagerFactory.
* @param _stateTransitionIndex Index of the state transition being verified.
* @param _stateTransitionIndex Index of the state transition being verified.
* @param _preStateRoot State root before the transition was executed.
* @param _preStateRoot State root before the transition was executed.
* @param _transactionHash Hash of the executed transaction.
* @param _transactionHash Hash of the executed transaction.
*/
*/
constructor(
constructor(
address _ovmExecutionManager,
address _proxyManager,
address _ovmStateManagerFactory,
uint256 _stateTransitionIndex,
uint256 _stateTransitionIndex,
bytes32 _preStateRoot,
bytes32 _preStateRoot,
bytes32 _transactionHash
bytes32 _transactionHash
) {
)
Proxy_Resolver(_proxyManager)
{
stateTransitionIndex = _stateTransitionIndex;
stateTransitionIndex = _stateTransitionIndex;
preStateRoot = _preStateRoot;
preStateRoot = _preStateRoot;
postStateRoot = _preStateRoot;
postStateRoot = _preStateRoot;
transactionHash = _transactionHash;
transactionHash = _transactionHash;
ovmExecutionManager = iOVM_ExecutionManager(
_ovmExecutionManager
);
ovmExecutionManager = iOVM_ExecutionManager(
resolve("OVM_ExecutionManager")
);
ovmStateManager = iOVM_StateManagerFactory(
_ovmStateManagerFactory).create(
);
ovmStateManager = iOVM_StateManagerFactory(
resolve("OVM_StateManagerFactory")).create(address(this)
);
}
}
...
@@ -116,7 +119,7 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -116,7 +119,7 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
/**
/**
* Retrieves the state root after execution.
* Retrieves the state root after execution.
* @return _p
re
StateRoot State root after execution.
* @return _p
ost
StateRoot State root after execution.
*/
*/
function getPostStateRoot()
function getPostStateRoot()
override
override
...
@@ -189,9 +192,9 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -189,9 +192,9 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
* Allows a user to prove the initial state of a contract storage slot.
* Allows a user to prove the initial state of a contract storage slot.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _key Claimed account slot key.
* @param _key Claimed account slot key.
* @param _
key
Claimed account slot value.
* @param _
value
Claimed account slot value.
* @param _stateTrieWitness Proof of the account state.
* @param _stateTrieWitness Proof of the account state.
* @param _st
at
eTrieWitness Proof of the storage slot.
* @param _st
orag
eTrieWitness Proof of the storage slot.
*/
*/
function proveStorageSlot(
function proveStorageSlot(
address _ovmContractAddress,
address _ovmContractAddress,
...
@@ -244,13 +247,14 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -244,13 +247,14 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
public
public
{
{
require(
require(
libOVMCodec.hash
(_transaction) == transactionHash,
Lib_OVMCodec.hashTransaction
(_transaction) == transactionHash,
"Invalid transaction provided."
"Invalid transaction provided."
);
);
// TODO: Set state manager for EM here.
// TODO: Set state manager for EM here.
ovmExecutionManager.run(_transaction);
ovmStateManager.setExecutionManager(resolveTarget("OVM_ExecutionManager"));
ovmExecutionManager.run(_transaction, address(ovmStateManager));
phase = TransitionPhase.POST_EXECUTION;
phase = TransitionPhase.POST_EXECUTION;
}
}
...
@@ -276,8 +280,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -276,8 +280,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
{
{
require(
require(
ovmStateManager.
isUncommitted
Account(_ovmContractAddress) == true,
ovmStateManager.
commit
Account(_ovmContractAddress) == true,
"
Provided account is not uncommitt
ed."
"
Cannot commit an account that has not been chang
ed."
);
);
postStateRoot = Lib_EthMerkleTrie.updateAccountState(
postStateRoot = Lib_EthMerkleTrie.updateAccountState(
...
@@ -286,17 +290,15 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -286,17 +290,15 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
_stateTrieWitness,
_stateTrieWitness,
postStateRoot
postStateRoot
);
);
ovmStateManager.commitAccount(_ovmContractAddress);
}
}
/**
/**
* Allows a user to commit the final state of a contract storage slot.
* Allows a user to commit the final state of a contract storage slot.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _key Claimed account slot key.
* @param _key Claimed account slot key.
* @param _
key
Claimed account slot value.
* @param _
value
Claimed account slot value.
* @param _stateTrieWitness Proof of the account state.
* @param _stateTrieWitness Proof of the account state.
* @param _st
at
eTrieWitness Proof of the storage slot.
* @param _st
orag
eTrieWitness Proof of the storage slot.
*/
*/
function commitStorageSlot(
function commitStorageSlot(
address _ovmContractAddress,
address _ovmContractAddress,
...
@@ -310,8 +312,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -310,8 +312,8 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
{
{
require(
require(
ovmStateManager.
isUncommittedStorage(_ovmContractAddress, _key, _value
) == true,
ovmStateManager.
commitContractStorage(_ovmContractAddress, _key
) == true,
"
Provided storage slot is not uncommitt
ed."
"
Cannot commit a storage slot that has not been chang
ed."
);
);
postStateRoot = Lib_EthMerkleTrie.updateAccountStorageSlotValue(
postStateRoot = Lib_EthMerkleTrie.updateAccountStorageSlotValue(
...
@@ -322,8 +324,6 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -322,8 +324,6 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
_storageTrieWitness,
_storageTrieWitness,
postStateRoot
postStateRoot
);
);
ovmStateManager.commitStorage(_ovmContractAddress, _key, _value);
}
}
...
@@ -340,12 +340,12 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
...
@@ -340,12 +340,12 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner {
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
onlyDuringPhase(TransitionPhase.POST_EXECUTION)
{
{
require(
require(
ovmStateManager.
t
otalUncommittedAccounts() == 0,
ovmStateManager.
getT
otalUncommittedAccounts() == 0,
"All accounts must be committed before completing a transition."
"All accounts must be committed before completing a transition."
);
);
require(
require(
ovmStateManager.
totalUncommitted
Storage() == 0,
ovmStateManager.
getTotalUncommittedContract
Storage() == 0,
"All storage must be committed before completing a transition."
"All storage must be committed before completing a transition."
);
);
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_StateTransitionerFactory.sol
View file @
acb50b70
...
@@ -17,8 +17,16 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
...
@@ -17,8 +17,16 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
* Public Functions: Contract Creation *
* Public Functions: Contract Creation *
***************************************/
***************************************/
/**
* Creates a new OVM_StateTransitioner
* @param _proxyManager Address of the Proxy_Manager.
* @param _stateTransitionIndex Index of the state transition being verified.
* @param _preStateRoot State root before the transition was executed.
* @param _transactionHash Hash of the executed transaction.
* @return _ovmStateTransitioner New OVM_StateTransitioner instance.
*/
function create(
function create(
address _
libContractP
roxyManager,
address _
p
roxyManager,
uint256 _stateTransitionIndex,
uint256 _stateTransitionIndex,
bytes32 _preStateRoot,
bytes32 _preStateRoot,
bytes32 _transactionHash
bytes32 _transactionHash
...
@@ -30,7 +38,7 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
...
@@ -30,7 +38,7 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
)
)
{
{
return new OVM_StateTransitioner(
return new OVM_StateTransitioner(
_
libContractP
roxyManager,
_
p
roxyManager,
_stateTransitionIndex,
_stateTransitionIndex,
_preStateRoot,
_preStateRoot,
_transactionHash
_transactionHash
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/queue/OVM_L1ToL2TransactionQueue.sol
View file @
acb50b70
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
pragma solidity ^0.7.0;
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
pragma experimental ABIEncoderV2;
/* Proxy Imports */
import { Proxy_Resolver } from "../../proxy/Proxy_Resolver.sol";
/* Library Imports */
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
...
@@ -15,7 +18,7 @@ import { OVM_BaseQueue } from "./OVM_BaseQueue.sol";
...
@@ -15,7 +18,7 @@ import { OVM_BaseQueue } from "./OVM_BaseQueue.sol";
/**
/**
* @title OVM_L1ToL2TransactionQueue
* @title OVM_L1ToL2TransactionQueue
*/
*/
contract OVM_L1ToL2TransactionQueue is iOVM_L1ToL2TransactionQueue, OVM_BaseQueue {
contract OVM_L1ToL2TransactionQueue is iOVM_L1ToL2TransactionQueue, OVM_BaseQueue
, Proxy_Resolver
{
/*******************************************
/*******************************************
* Contract Variables: Contract References *
* Contract Variables: Contract References *
...
@@ -29,12 +32,14 @@ contract OVM_L1ToL2TransactionQueue is iOVM_L1ToL2TransactionQueue, OVM_BaseQueu
...
@@ -29,12 +32,14 @@ contract OVM_L1ToL2TransactionQueue is iOVM_L1ToL2TransactionQueue, OVM_BaseQueu
***************/
***************/
/**
/**
* @param _
ovmCanonicalTransactionChain Address of the OVM_CanonicalTransactionChain
.
* @param _
proxyManager Address of the Proxy_Manager
.
*/
*/
constructor(
constructor(
address _ovmCanonicalTransactionChain
address _proxyManager
) {
)
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(_ovmCanonicalTransactionChain);
Proxy_Resolver(_proxyManager)
{
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
}
}
...
...
packages/contracts/contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol
View file @
acb50b70
...
@@ -17,10 +17,18 @@ interface iOVM_StateManager {
...
@@ -17,10 +17,18 @@ interface iOVM_StateManager {
enum ItemState {
enum ItemState {
ITEM_UNTOUCHED,
ITEM_UNTOUCHED,
ITEM_LOADED,
ITEM_LOADED,
ITEM_CHANGED
ITEM_CHANGED,
ITEM_COMMITTED
}
}
/***************************
* Public Functions: Setup *
***************************/
function setExecutionManager(address _ovmExecutionManager) external;
/************************************
/************************************
* Public Functions: Account Access *
* Public Functions: Account Access *
************************************/
************************************/
...
@@ -35,6 +43,8 @@ interface iOVM_StateManager {
...
@@ -35,6 +43,8 @@ interface iOVM_StateManager {
function commitPendingAccount(address _address, address _ethAddress, bytes32 _codeHash) external;
function commitPendingAccount(address _address, address _ethAddress, bytes32 _codeHash) external;
function testAndSetAccountLoaded(address _address) external returns (bool _wasAccountAlreadyLoaded);
function testAndSetAccountLoaded(address _address) external returns (bool _wasAccountAlreadyLoaded);
function testAndSetAccountChanged(address _address) external returns (bool _wasAccountAlreadyChanged);
function testAndSetAccountChanged(address _address) external returns (bool _wasAccountAlreadyChanged);
function commitAccount(address _address) external returns (bool _wasAccountCommitted);
function getTotalUncommittedAccounts() external returns (uint256 _total);
/************************************
/************************************
...
@@ -46,4 +56,6 @@ interface iOVM_StateManager {
...
@@ -46,4 +56,6 @@ interface iOVM_StateManager {
function hasContractStorage(address _contract, bytes32 _key) external returns (bool _exists);
function hasContractStorage(address _contract, bytes32 _key) external returns (bool _exists);
function testAndSetContractStorageLoaded(address _contract, bytes32 _key) external returns (bool _wasContractStorageAlreadyLoaded);
function testAndSetContractStorageLoaded(address _contract, bytes32 _key) external returns (bool _wasContractStorageAlreadyLoaded);
function testAndSetContractStorageChanged(address _contract, bytes32 _key) external returns (bool _wasContractStorageAlreadyChanged);
function testAndSetContractStorageChanged(address _contract, bytes32 _key) external returns (bool _wasContractStorageAlreadyChanged);
function commitContractStorage(address _contract, bytes32 _key) external returns (bool _wasContractStorageCommitted);
function getTotalUncommittedContractStorage() external returns (uint256 _total);
}
}
packages/contracts/contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManagerFactory.sol
View file @
acb50b70
...
@@ -13,7 +13,9 @@ interface iOVM_StateManagerFactory {
...
@@ -13,7 +13,9 @@ interface iOVM_StateManagerFactory {
* Public Functions: Contract Creation *
* Public Functions: Contract Creation *
***************************************/
***************************************/
function create()
function create(
address _owner
)
external
external
returns (
returns (
iOVM_StateManager _ovmStateManager
iOVM_StateManager _ovmStateManager
...
...
packages/contracts/contracts/optimistic-ethereum/iOVM/execution/iOVM_StateTransitioner.sol
View file @
acb50b70
...
@@ -43,7 +43,7 @@ interface iOVM_StateTransitioner {
...
@@ -43,7 +43,7 @@ interface iOVM_StateTransitioner {
*******************************/
*******************************/
function applyTransaction(
function applyTransaction(
Lib_OVMCodec.Transaction
Data
calldata _transaction
Lib_OVMCodec.Transaction calldata _transaction
) external;
) external;
...
...
packages/contracts/contracts/optimistic-ethereum/iOVM/execution/iOVM_StateTransitionerFactory.sol
View file @
acb50b70
...
@@ -14,7 +14,7 @@ interface iOVM_StateTransitionerFactory {
...
@@ -14,7 +14,7 @@ interface iOVM_StateTransitionerFactory {
***************************************/
***************************************/
function create(
function create(
address _
libContractP
roxyManager,
address _
p
roxyManager,
uint256 _stateTransitionIndex,
uint256 _stateTransitionIndex,
bytes32 _preStateRoot,
bytes32 _preStateRoot,
bytes32 _transactionHash
bytes32 _transactionHash
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol
View file @
acb50b70
...
@@ -105,4 +105,36 @@ library Lib_OVMCodec {
...
@@ -105,4 +105,36 @@ library Lib_OVMCodec {
data: Lib_RLPReader.toBytes(decoded[5])
data: Lib_RLPReader.toBytes(decoded[5])
});
});
}
}
function encodeTransaction(
Transaction memory _transaction
)
public
pure
returns (
bytes memory _encoded
)
{
return abi.encodePacked(
_transaction.timestamp,
_transaction.queueOrigin,
_transaction.entrypoint,
_transaction.origin,
_transaction.msgSender,
_transaction.gasLimit,
_transaction.data
);
}
function hashTransaction(
Transaction memory _transaction
)
public
pure
returns (
bytes32 _hash
)
{
return keccak256(encodeTransaction(_transaction));
}
}
}
packages/contracts/contracts/optimistic-ethereum/libraries/trie/Lib_EthMerkleTrie.sol
View file @
acb50b70
...
@@ -4,8 +4,10 @@ pragma experimental ABIEncoderV2;
...
@@ -4,8 +4,10 @@ pragma experimental ABIEncoderV2;
/* Library Imports */
/* Library Imports */
import { Lib_SecureMerkleTrie } from "./Lib_SecureMerkleTrie.sol";
import { Lib_SecureMerkleTrie } from "./Lib_SecureMerkleTrie.sol";
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
import { Lib_OVMCodec } from "../codec/Lib_OVMCodec.sol";
import { Lib_OVMCodec } from "../codec/Lib_OVMCodec.sol";
import { Lib_ByteUtils } from "../utils/Lib_ByteUtils.sol";
import { Lib_RLPWriter } from "../rlp/Lib_RLPWriter.sol";
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
/**
/**
* @title Lib_EthMerkleTrie
* @title Lib_EthMerkleTrie
...
@@ -16,6 +18,7 @@ library Lib_EthMerkleTrie {
...
@@ -16,6 +18,7 @@ library Lib_EthMerkleTrie {
* Contract Constants *
* Contract Constants *
**********************/
**********************/
bytes constant private RLP_NULL_BYTES = hex'80';
bytes32 constant private BYTES32_NULL = bytes32('');
bytes32 constant private BYTES32_NULL = bytes32('');
uint256 constant private UINT256_NULL = uint256(0);
uint256 constant private UINT256_NULL = uint256(0);
...
@@ -56,7 +59,7 @@ library Lib_EthMerkleTrie {
...
@@ -56,7 +59,7 @@ library Lib_EthMerkleTrie {
);
);
// Verify inclusion of the given k/v pair in the storage trie.
// Verify inclusion of the given k/v pair in the storage trie.
return verifyInclusionProof(
return
Lib_SecureMerkleTrie.
verifyInclusionProof(
abi.encodePacked(_key),
abi.encodePacked(_key),
abi.encodePacked(_value),
abi.encodePacked(_value),
_storageTrieWitness,
_storageTrieWitness,
...
@@ -96,7 +99,7 @@ library Lib_EthMerkleTrie {
...
@@ -96,7 +99,7 @@ library Lib_EthMerkleTrie {
);
);
// Generate a new storage root.
// Generate a new storage root.
accountState.storageRoot = update(
accountState.storageRoot =
Lib_SecureMerkleTrie.
update(
abi.encodePacked(_key),
abi.encodePacked(_key),
abi.encodePacked(_value),
abi.encodePacked(_value),
_storageTrieWitness,
_storageTrieWitness,
...
@@ -677,13 +680,13 @@ library Lib_EthMerkleTrie {
...
@@ -677,13 +680,13 @@ library Lib_EthMerkleTrie {
view
view
returns (Lib_OVMCodec.EVMAccount memory)
returns (Lib_OVMCodec.EVMAccount memory)
{
{
Lib_RLPReader.RLPItem[] memory accountState =
libRLPReader.toList(lib
RLPReader.toRlpItem(_encodedAccountState));
Lib_RLPReader.RLPItem[] memory accountState =
Lib_RLPReader.toList(Lib_
RLPReader.toRlpItem(_encodedAccountState));
return Lib_OVMCodec.EVMAccount({
return Lib_OVMCodec.EVMAccount({
nonce:
lib
RLPReader.toUint(accountState[0]),
nonce:
Lib_
RLPReader.toUint(accountState[0]),
balance:
lib
RLPReader.toUint(accountState[1]),
balance:
Lib_
RLPReader.toUint(accountState[1]),
storageRoot:
libByteUtils.toBytes32(lib
RLPReader.toBytes(accountState[2])),
storageRoot:
Lib_ByteUtils.toBytes32(Lib_
RLPReader.toBytes(accountState[2])),
codeHash:
libByteUtils.toBytes32(lib
RLPReader.toBytes(accountState[3]))
codeHash:
Lib_ByteUtils.toBytes32(Lib_
RLPReader.toBytes(accountState[3]))
});
});
}
}
...
@@ -704,12 +707,12 @@ library Lib_EthMerkleTrie {
...
@@ -704,12 +707,12 @@ library Lib_EthMerkleTrie {
// Unfortunately we can't create this array outright because
// Unfortunately we can't create this array outright because
// RLPWriter.encodeList will reject fixed-size arrays. Assigning
// RLPWriter.encodeList will reject fixed-size arrays. Assigning
// index-by-index circumvents this issue.
// index-by-index circumvents this issue.
raw[0] =
lib
RLPWriter.encodeUint(_accountState.nonce);
raw[0] =
Lib_
RLPWriter.encodeUint(_accountState.nonce);
raw[1] =
lib
RLPWriter.encodeUint(_accountState.balance);
raw[1] =
Lib_
RLPWriter.encodeUint(_accountState.balance);
raw[2] = _accountState.storageRoot == 0 ? RLP_NULL_BYTES :
lib
RLPWriter.encodeBytes(abi.encodePacked(_accountState.storageRoot));
raw[2] = _accountState.storageRoot == 0 ? RLP_NULL_BYTES :
Lib_
RLPWriter.encodeBytes(abi.encodePacked(_accountState.storageRoot));
raw[3] = _accountState.codeHash == 0 ? RLP_NULL_BYTES :
lib
RLPWriter.encodeBytes(abi.encodePacked(_accountState.codeHash));
raw[3] = _accountState.codeHash == 0 ? RLP_NULL_BYTES :
Lib_
RLPWriter.encodeBytes(abi.encodePacked(_accountState.codeHash));
return
lib
RLPWriter.encodeList(raw);
return
Lib_
RLPWriter.encodeList(raw);
}
}
/**
/**
...
@@ -738,7 +741,7 @@ library Lib_EthMerkleTrie {
...
@@ -738,7 +741,7 @@ library Lib_EthMerkleTrie {
(
(
bool exists,
bool exists,
bytes memory encodedAccountState
bytes memory encodedAccountState
) = get(
) =
Lib_SecureMerkleTrie.
get(
abi.encodePacked(_address),
abi.encodePacked(_address),
_stateTrieWitness,
_stateTrieWitness,
_stateTrieRoot
_stateTrieRoot
...
@@ -768,7 +771,7 @@ library Lib_EthMerkleTrie {
...
@@ -768,7 +771,7 @@ library Lib_EthMerkleTrie {
{
{
bytes memory encodedAccountState = encodeAccountState(_accountState);
bytes memory encodedAccountState = encodeAccountState(_accountState);
return update(
return
Lib_SecureMerkleTrie.
update(
abi.encodePacked(_address),
abi.encodePacked(_address),
encodedAccountState,
encodedAccountState,
_stateTrieWitness,
_stateTrieWitness,
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/trie/Lib_MerkleTrie.sol
View file @
acb50b70
This diff is collapsed.
Click to expand it.
packages/contracts/contracts/optimistic-ethereum/proxy/Proxy_Forwarder.sol
0 → 100644
View file @
acb50b70
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;
/* Proxy Imports */
import { Proxy_Manager } from "./Proxy_Manager.sol";
/**
* @title Proxy_Forwarder
*/
contract Proxy_Forwarder {
Proxy_Manager private proxyManager;
constructor(
address _proxyManager
) {
proxyManager = Proxy_Manager(_proxyManager);
}
fallback()
external
{
address target = _getTarget();
bytes memory data = msg.data;
require(
target != address(0),
"Proxy does not have a target."
);
assembly {
let success := call(
gas(),
target,
0,
add(data, 0x20),
mload(data),
0,
0
)
let size := returndatasize()
let returndata := mload(0x40)
mstore(0x40, add(returndata, add(size, 0x20)))
returndatacopy(add(returndata, 0x20), 0, size)
if iszero(success) {
revert(add(returndata, 0x20), size)
}
return(add(returndata, 0x20), size)
}
}
function _getTarget()
internal
view
returns (
address _target
)
{
address target;
if (proxyManager.isProxy(msg.sender)) {
target = proxyManager.getTarget(msg.sender);
} else if (proxyManager.hasProxy(msg.sender)) {
target = proxyManager.getProxy(msg.sender);
} else {
target = proxyManager.getTarget(address(this));
}
return target;
}
}
packages/contracts/contracts/optimistic-ethereum/proxy/Proxy_Manager.sol
0 → 100644
View file @
acb50b70
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;
/**
* @title Proxy_Manager
*/
contract Proxy_Manager {
mapping (bytes32 => address) private proxyByName;
mapping (bytes32 => address) private targetByName;
mapping (address => bytes32) private nameByProxy;
mapping (address => bytes32) private nameByTarget;
function setProxy(
string memory _name,
address _proxy
)
public
{
proxyByName[_getNameHash(_name)] = _proxy;
nameByProxy[_proxy] = _getNameHash(_name);
}
function getProxy(
string memory _name
)
public
view
returns (
address _proxy
)
{
return proxyByName[_getNameHash(_name)];
}
function getProxy(
address _target
)
public
view
returns (
address _proxy
)
{
return proxyByName[nameByTarget[_target]];
}
function hasProxy(
string memory _name
)
public
view
returns (
bool _hasProxy
)
{
return getProxy(_name) != address(0);
}
function hasProxy(
address _target
)
public
view
returns (
bool _hasProxy
)
{
return getProxy(_target) != address(0);
}
function isProxy(
address _proxy
)
public
view
returns (
bool _isProxy
)
{
return nameByProxy[_proxy] != bytes32('');
}
function setTarget(
string memory _name,
address _target
)
public
{
targetByName[_getNameHash(_name)] = _target;
nameByTarget[_target] = _getNameHash(_name);
}
function getTarget(
string memory _name
)
public
view
returns (
address _target
)
{
return targetByName[_getNameHash(_name)];
}
function getTarget(
address _proxy
)
public
view
returns (
address _target
)
{
return targetByName[nameByProxy[_proxy]];
}
function hasTarget(
string memory _name
)
public
view
returns (
bool _hasTarget
)
{
return getTarget(_name) != address(0);
}
function hasTarget(
address _proxy
)
public
view
returns (
bool _hasTarget
)
{
return getTarget(_proxy) != address(0);
}
function isTarget(
address _target
)
public
view
returns (
bool _isTarget
)
{
return nameByTarget[_target] != bytes32('');
}
function _getNameHash(
string memory _name
)
internal
pure
returns (
bytes32 _hash
)
{
return keccak256(abi.encodePacked(_name));
}
}
packages/contracts/contracts/optimistic-ethereum/proxy/Proxy_Resolver.sol
0 → 100644
View file @
acb50b70
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;
/* Proxy Imports */
import { Proxy_Manager } from "./Proxy_Manager.sol";
/**
* @title Proxy_Resolver
*/
contract Proxy_Resolver {
Proxy_Manager internal proxyManager;
constructor(
address _proxyManager
) {
proxyManager = Proxy_Manager(_proxyManager);
}
function resolve(
string memory _name
)
public
view
returns (
address _proxy
)
{
return proxyManager.getProxy(_name);
}
function resolveTarget(
string memory _name
)
public
view
returns (
address _target
)
{
return proxyManager.getTarget(_name);
}
}
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