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";
*/
contract OVM_StateManager is iOVM_StateManager {
/**********************
* Contract Constants *
**********************/
/*************
* Constants *
*************/
bytes32 constant internal EMPTY_ACCOUNT_STORAGE_ROOT = 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421;
bytes32 constant internal EMPTY_ACCOUNT_CODE_HASH = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
bytes32 constant internal STORAGE_XOR_VALUE = 0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF;
/*******************************************
* Contract Variables: Contract References *
*******************************************/
/*************
* Variables *
*************/
address override public owner;
address override public ovmExecutionManager;
/****************************************
* Contract Variables: Internal Storage *
****************************************/
mapping (address => Lib_OVMCodec.Account) internal accounts;
mapping (address => mapping (bytes32 => bytes32)) internal contractStorage;
mapping (address => mapping (bytes32 => bool)) internal verifiedContractStorage;
......@@ -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(
address _address
)
override
public
view
returns (bool)
returns (
bool
)
{
return (_address == owner || _address == ovmExecutionManager);
}
/***************************
* Public Functions: Setup *
***************************/
/**
* Sets the address of the OVM_ExecutionManager.
* @param _ovmExecutionManager Address of the OVM_ExecutionManager.
......@@ -116,11 +112,6 @@ contract OVM_StateManager is iOVM_StateManager {
ovmExecutionManager = _ovmExecutionManager;
}
/************************************
* Public Functions: Account Access *
************************************/
/**
* Inserts an account into the state.
* @param _address Address of the account to insert.
......@@ -156,14 +147,16 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Retrieves an account from the state.
* @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
public
view
returns (
Lib_OVMCodec.Account memory _account
Lib_OVMCodec.Account memory
)
{
return accounts[_address];
......@@ -172,7 +165,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Checks whether the state has a given account.
* @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(
address _address
......@@ -181,7 +174,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
bool _exists
bool
)
{
return accounts[_address].codeHash != bytes32(0);
......@@ -190,7 +183,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Checks whether the state has a given known empty account.
* @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(
address _address
......@@ -199,7 +192,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
bool _exists
bool
)
{
return (
......@@ -227,7 +220,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Gets the nonce of an account.
* @param _address Address of the account to access.
* @return _nonce Nonce of the account.
* @return Nonce of the account.
*/
function getAccountNonce(
address _address
......@@ -236,7 +229,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
uint256 _nonce
uint256
)
{
return accounts[_address].nonce;
......@@ -245,7 +238,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Retrieves the Ethereum address of an account.
* @param _address Address of the account to access.
* @return _ethAddress Corresponding Ethereum address.
* @return Corresponding Ethereum address.
*/
function getAccountEthAddress(
address _address
......@@ -254,7 +247,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
address _ethAddress
address
)
{
return accounts[_address].ethAddress;
......@@ -263,7 +256,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Retrieves the storage root of an account.
* @param _address Address of the account to access.
* @return _storageRoot Corresponding storage root.
* @return Corresponding storage root.
*/
function getAccountStorageRoot(
address _address
......@@ -272,7 +265,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
bytes32 _storageRoot
bytes32
)
{
return accounts[_address].storageRoot;
......@@ -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.
* @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(
address _address
......@@ -328,7 +321,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasAccountAlreadyLoaded
bool
)
{
return _testAndSetItemState(
......@@ -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.
* @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(
address _address
......@@ -349,7 +342,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasAccountAlreadyChanged
bool
)
{
return _testAndSetItemState(
......@@ -361,7 +354,7 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Attempts to mark an account as committed.
* @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(
address _address
......@@ -370,7 +363,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasAccountCommitted
bool
)
{
bytes32 item = _getItemHash(_address);
......@@ -397,14 +390,14 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Gets the total number of uncommitted accounts.
* @return _total Total uncommitted accounts.
* @return Total uncommitted accounts.
*/
function getTotalUncommittedAccounts()
override
public
view
returns (
uint256 _total
uint256
)
{
return totalUncommittedAccounts;
......@@ -487,7 +480,7 @@ contract OVM_StateManager is iOVM_StateManager {
* Retrieves a contract storage slot value.
* @param _contract Address of the contract to access.
* @param _key 32 byte storage slot key.
* @return _value 32 byte storage slot value.
* @return 32 byte storage slot value.
*/
function getContractStorage(
address _contract,
......@@ -497,7 +490,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
bytes32 _value
bytes32
)
{
// 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 {
* Checks whether a contract storage slot exists in the state.
* @param _contract Address of the contract to access.
* @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(
address _contract,
......@@ -527,7 +520,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
bool _exists
bool
)
{
return verifiedContractStorage[_contract][_key] || accounts[_contract].isFresh;
......@@ -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.
* @param _contract Address of the contract to check.
* @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(
address _contract,
......@@ -547,7 +540,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasContractStorageAlreadyLoaded
bool
)
{
return _testAndSetItemState(
......@@ -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.
* @param _contract Address of the contract to check.
* @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(
address _contract,
......@@ -570,7 +563,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasContractStorageAlreadyChanged
bool
)
{
return _testAndSetItemState(
......@@ -583,7 +576,7 @@ contract OVM_StateManager is iOVM_StateManager {
* 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.
* @return Whether or not the slot was committed.
*/
function commitContractStorage(
address _contract,
......@@ -593,7 +586,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
returns (
bool _wasContractStorageCommitted
bool
)
{
bytes32 item = _getItemHash(_contract, _key);
......@@ -620,14 +613,14 @@ contract OVM_StateManager is iOVM_StateManager {
/**
* Gets the total number of uncommitted storage slots.
* @return _total Total uncommitted storage slots.
* @return Total uncommitted storage slots.
*/
function getTotalUncommittedContractStorage()
override
public
view
returns (
uint256 _total
uint256
)
{
return totalUncommittedContractStorage;
......@@ -724,7 +717,7 @@ contract OVM_StateManager is iOVM_StateManager {
* item to the provided state if not.
* @param _item 32 byte item ID to check.
* @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(
bytes32 _item,
......@@ -732,7 +725,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
internal
returns (
bool _wasItemState
bool
)
{
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