Commit 5676bf45 authored by Kelvin Fichter's avatar Kelvin Fichter Committed by GitHub

cleanup: Minor cleanup to state manager (#289)

parent 7a3bd1e2
...@@ -20,27 +20,21 @@ import { iOVM_StateManager } from "../../iOVM/execution/iOVM_StateManager.sol"; ...@@ -20,27 +20,21 @@ import { iOVM_StateManager } from "../../iOVM/execution/iOVM_StateManager.sol";
*/ */
contract OVM_StateManager is iOVM_StateManager { contract OVM_StateManager is iOVM_StateManager {
/********************** /*************
* Contract Constants * * Constants *
**********************/ *************/
bytes32 constant internal EMPTY_ACCOUNT_STORAGE_ROOT = 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421; bytes32 constant internal EMPTY_ACCOUNT_STORAGE_ROOT = 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421;
bytes32 constant internal EMPTY_ACCOUNT_CODE_HASH = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; bytes32 constant internal EMPTY_ACCOUNT_CODE_HASH = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
bytes32 constant internal STORAGE_XOR_VALUE = 0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF; bytes32 constant internal STORAGE_XOR_VALUE = 0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF;
/******************************************* /*************
* Contract Variables: Contract References * * Variables *
*******************************************/ *************/
address override public owner; address override public owner;
address override public ovmExecutionManager; address override public ovmExecutionManager;
/****************************************
* Contract Variables: Internal Storage *
****************************************/
mapping (address => Lib_OVMCodec.Account) internal accounts; mapping (address => Lib_OVMCodec.Account) internal accounts;
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;
...@@ -82,26 +76,28 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -82,26 +76,28 @@ contract OVM_StateManager is iOVM_StateManager {
_; _;
} }
/*************************** /********************
* Public Functions: Misc * * Public Functions *
***************************/ ********************/
/**
* Checks whether a given address is allowed to modify this contract.
* @param _address Address to check.
* @return Whether or not the address can modify this contract.
*/
function isAuthenticated( function isAuthenticated(
address _address address _address
) )
override override
public public
view view
returns (bool) returns (
bool
)
{ {
return (_address == owner || _address == ovmExecutionManager); return (_address == owner || _address == ovmExecutionManager);
} }
/***************************
* Public Functions: Setup *
***************************/
/** /**
* Sets the address of the OVM_ExecutionManager. * Sets the address of the OVM_ExecutionManager.
* @param _ovmExecutionManager Address of the OVM_ExecutionManager. * @param _ovmExecutionManager Address of the OVM_ExecutionManager.
...@@ -116,11 +112,6 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -116,11 +112,6 @@ contract OVM_StateManager is iOVM_StateManager {
ovmExecutionManager = _ovmExecutionManager; ovmExecutionManager = _ovmExecutionManager;
} }
/************************************
* Public Functions: Account Access *
************************************/
/** /**
* Inserts an account into the state. * Inserts an account into the state.
* @param _address Address of the account to insert. * @param _address Address of the account to insert.
...@@ -156,14 +147,16 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -156,14 +147,16 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Retrieves an account from the state. * Retrieves an account from the state.
* @param _address Address of the account to retrieve. * @param _address Address of the account to retrieve.
* @return _account Account for the given address. * @return Account for the given address.
*/ */
function getAccount(address _address) function getAccount(
address _address
)
override override
public public
view view
returns ( returns (
Lib_OVMCodec.Account memory _account Lib_OVMCodec.Account memory
) )
{ {
return accounts[_address]; return accounts[_address];
...@@ -172,7 +165,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -172,7 +165,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Checks whether the state has a given account. * Checks whether the state has a given account.
* @param _address Address of the account to check. * @param _address Address of the account to check.
* @return _exists Whether or not the state has the account. * @return Whether or not the state has the account.
*/ */
function hasAccount( function hasAccount(
address _address address _address
...@@ -181,7 +174,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -181,7 +174,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
bool _exists bool
) )
{ {
return accounts[_address].codeHash != bytes32(0); return accounts[_address].codeHash != bytes32(0);
...@@ -190,7 +183,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -190,7 +183,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Checks whether the state has a given known empty account. * Checks whether the state has a given known empty account.
* @param _address Address of the account to check. * @param _address Address of the account to check.
* @return _exists Whether or not the state has the empty account. * @return Whether or not the state has the empty account.
*/ */
function hasEmptyAccount( function hasEmptyAccount(
address _address address _address
...@@ -199,7 +192,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -199,7 +192,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
bool _exists bool
) )
{ {
return ( return (
...@@ -227,7 +220,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -227,7 +220,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Gets the nonce of an account. * Gets the nonce of an account.
* @param _address Address of the account to access. * @param _address Address of the account to access.
* @return _nonce Nonce of the account. * @return Nonce of the account.
*/ */
function getAccountNonce( function getAccountNonce(
address _address address _address
...@@ -236,7 +229,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -236,7 +229,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
uint256 _nonce uint256
) )
{ {
return accounts[_address].nonce; return accounts[_address].nonce;
...@@ -245,7 +238,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -245,7 +238,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Retrieves the Ethereum address of an account. * Retrieves the Ethereum address of an account.
* @param _address Address of the account to access. * @param _address Address of the account to access.
* @return _ethAddress Corresponding Ethereum address. * @return Corresponding Ethereum address.
*/ */
function getAccountEthAddress( function getAccountEthAddress(
address _address address _address
...@@ -254,7 +247,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -254,7 +247,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
address _ethAddress address
) )
{ {
return accounts[_address].ethAddress; return accounts[_address].ethAddress;
...@@ -263,7 +256,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -263,7 +256,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Retrieves the storage root of an account. * Retrieves the storage root of an account.
* @param _address Address of the account to access. * @param _address Address of the account to access.
* @return _storageRoot Corresponding storage root. * @return Corresponding storage root.
*/ */
function getAccountStorageRoot( function getAccountStorageRoot(
address _address address _address
...@@ -272,7 +265,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -272,7 +265,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
bytes32 _storageRoot bytes32
) )
{ {
return accounts[_address].storageRoot; return accounts[_address].storageRoot;
...@@ -319,7 +312,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -319,7 +312,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Checks whether an account has already been retrieved, and marks it as retrieved if not. * Checks whether an account has already been retrieved, and marks it as retrieved if not.
* @param _address Address of the account to check. * @param _address Address of the account to check.
* @return _wasAccountAlreadyLoaded Whether or not the account was already loaded. * @return Whether or not the account was already loaded.
*/ */
function testAndSetAccountLoaded( function testAndSetAccountLoaded(
address _address address _address
...@@ -328,7 +321,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -328,7 +321,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasAccountAlreadyLoaded bool
) )
{ {
return _testAndSetItemState( return _testAndSetItemState(
...@@ -340,7 +333,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -340,7 +333,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Checks whether an account has already been modified, and marks it as modified if not. * Checks whether an account has already been modified, and marks it as modified if not.
* @param _address Address of the account to check. * @param _address Address of the account to check.
* @return _wasAccountAlreadyChanged Whether or not the account was already modified. * @return Whether or not the account was already modified.
*/ */
function testAndSetAccountChanged( function testAndSetAccountChanged(
address _address address _address
...@@ -349,7 +342,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -349,7 +342,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasAccountAlreadyChanged bool
) )
{ {
return _testAndSetItemState( return _testAndSetItemState(
...@@ -361,7 +354,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -361,7 +354,7 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Attempts to mark an account as committed. * Attempts to mark an account as committed.
* @param _address Address of the account to commit. * @param _address Address of the account to commit.
* @return _wasAccountCommitted Whether or not the account was committed. * @return Whether or not the account was committed.
*/ */
function commitAccount( function commitAccount(
address _address address _address
...@@ -370,7 +363,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -370,7 +363,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasAccountCommitted bool
) )
{ {
bytes32 item = _getItemHash(_address); bytes32 item = _getItemHash(_address);
...@@ -397,14 +390,14 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -397,14 +390,14 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Gets the total number of uncommitted accounts. * Gets the total number of uncommitted accounts.
* @return _total Total uncommitted accounts. * @return Total uncommitted accounts.
*/ */
function getTotalUncommittedAccounts() function getTotalUncommittedAccounts()
override override
public public
view view
returns ( returns (
uint256 _total uint256
) )
{ {
return totalUncommittedAccounts; return totalUncommittedAccounts;
...@@ -487,7 +480,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -487,7 +480,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Retrieves a contract storage slot value. * Retrieves a contract storage slot value.
* @param _contract Address of the contract to access. * @param _contract Address of the contract to access.
* @param _key 32 byte storage slot key. * @param _key 32 byte storage slot key.
* @return _value 32 byte storage slot value. * @return 32 byte storage slot value.
*/ */
function getContractStorage( function getContractStorage(
address _contract, address _contract,
...@@ -497,7 +490,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -497,7 +490,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
bytes32 _value bytes32
) )
{ {
// Storage XOR system doesn't work for newly created contracts that haven't set this // Storage XOR system doesn't work for newly created contracts that haven't set this
...@@ -517,7 +510,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -517,7 +510,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Checks whether a contract storage slot exists in the state. * Checks whether a contract storage slot exists in the state.
* @param _contract Address of the contract to access. * @param _contract Address of the contract to access.
* @param _key 32 byte storage slot key. * @param _key 32 byte storage slot key.
* @return _exists Whether or not the key was set in the state. * @return Whether or not the key was set in the state.
*/ */
function hasContractStorage( function hasContractStorage(
address _contract, address _contract,
...@@ -527,7 +520,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -527,7 +520,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
view view
returns ( returns (
bool _exists bool
) )
{ {
return verifiedContractStorage[_contract][_key] || accounts[_contract].isFresh; return verifiedContractStorage[_contract][_key] || accounts[_contract].isFresh;
...@@ -537,7 +530,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -537,7 +530,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Checks whether a storage slot has already been retrieved, and marks it as retrieved if not. * Checks whether a storage slot has already been retrieved, and marks it as retrieved if not.
* @param _contract Address of the contract to check. * @param _contract Address of the contract to check.
* @param _key 32 byte storage slot key. * @param _key 32 byte storage slot key.
* @return _wasContractStorageAlreadyLoaded Whether or not the slot was already loaded. * @return Whether or not the slot was already loaded.
*/ */
function testAndSetContractStorageLoaded( function testAndSetContractStorageLoaded(
address _contract, address _contract,
...@@ -547,7 +540,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -547,7 +540,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasContractStorageAlreadyLoaded bool
) )
{ {
return _testAndSetItemState( return _testAndSetItemState(
...@@ -560,7 +553,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -560,7 +553,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Checks whether a storage slot has already been modified, and marks it as modified if not. * Checks whether a storage slot has already been modified, and marks it as modified if not.
* @param _contract Address of the contract to check. * @param _contract Address of the contract to check.
* @param _key 32 byte storage slot key. * @param _key 32 byte storage slot key.
* @return _wasContractStorageAlreadyChanged Whether or not the slot was already modified. * @return Whether or not the slot was already modified.
*/ */
function testAndSetContractStorageChanged( function testAndSetContractStorageChanged(
address _contract, address _contract,
...@@ -570,7 +563,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -570,7 +563,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasContractStorageAlreadyChanged bool
) )
{ {
return _testAndSetItemState( return _testAndSetItemState(
...@@ -583,7 +576,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -583,7 +576,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Attempts to mark a storage slot as committed. * Attempts to mark a storage slot as committed.
* @param _contract Address of the account to commit. * @param _contract Address of the account to commit.
* @param _key 32 byte slot key to commit. * @param _key 32 byte slot key to commit.
* @return _wasContractStorageCommitted Whether or not the slot was committed. * @return Whether or not the slot was committed.
*/ */
function commitContractStorage( function commitContractStorage(
address _contract, address _contract,
...@@ -593,7 +586,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -593,7 +586,7 @@ contract OVM_StateManager is iOVM_StateManager {
public public
authenticated authenticated
returns ( returns (
bool _wasContractStorageCommitted bool
) )
{ {
bytes32 item = _getItemHash(_contract, _key); bytes32 item = _getItemHash(_contract, _key);
...@@ -620,14 +613,14 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -620,14 +613,14 @@ contract OVM_StateManager is iOVM_StateManager {
/** /**
* Gets the total number of uncommitted storage slots. * Gets the total number of uncommitted storage slots.
* @return _total Total uncommitted storage slots. * @return Total uncommitted storage slots.
*/ */
function getTotalUncommittedContractStorage() function getTotalUncommittedContractStorage()
override override
public public
view view
returns ( returns (
uint256 _total uint256
) )
{ {
return totalUncommittedContractStorage; return totalUncommittedContractStorage;
...@@ -724,7 +717,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -724,7 +717,7 @@ contract OVM_StateManager is iOVM_StateManager {
* item to the provided state if not. * item to the provided state if not.
* @param _item 32 byte item ID to check. * @param _item 32 byte item ID to check.
* @param _minItemState Minimum state that must be satisfied by the item. * @param _minItemState Minimum state that must be satisfied by the item.
* @return _wasItemState Whether or not the item was already in the state. * @return Whether or not the item was already in the state.
*/ */
function _testAndSetItemState( function _testAndSetItemState(
bytes32 _item, bytes32 _item,
...@@ -732,7 +725,7 @@ contract OVM_StateManager is iOVM_StateManager { ...@@ -732,7 +725,7 @@ contract OVM_StateManager is iOVM_StateManager {
) )
internal internal
returns ( returns (
bool _wasItemState bool
) )
{ {
bool wasItemState = itemStates[_item] >= _minItemState; bool wasItemState = itemStates[_item] >= _minItemState;
......
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