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
e596f566
Commit
e596f566
authored
Dec 10, 2020
by
Alina
Committed by
GitHub
Dec 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unused stateTransitionIndex (#108)
* rm unused stateTransitionIndex
parent
1e438d4b
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
253 additions
and
494 deletions
+253
-494
.gitignore
packages/contracts/.gitignore
+0
-1
OVM_CanonicalTransactionChain.sol
...stic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
+0
-1
OVM_ExecutionManager.sol
...ptimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol
+34
-53
OVM_StateManager.sol
...ts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol
+12
-138
OVM_SequencerEntrypoint.sol
...stic-ethereum/OVM/precompiles/OVM_SequencerEntrypoint.sol
+1
-1
OVM_FraudVerifier.sol
...ptimistic-ethereum/OVM/verification/OVM_FraudVerifier.sol
+37
-59
OVM_StateTransitioner.sol
...istic-ethereum/OVM/verification/OVM_StateTransitioner.sol
+93
-106
OVM_StateTransitionerFactory.sol
...thereum/OVM/verification/OVM_StateTransitionerFactory.sol
+0
-3
iOVM_StateManager.sol
.../optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol
+0
-4
iOVM_StateTransitioner.sol
...tic-ethereum/iOVM/verification/iOVM_StateTransitioner.sol
+8
-14
iOVM_StateTransitionerFactory.sol
...ereum/iOVM/verification/iOVM_StateTransitionerFactory.sol
+0
-1
Lib_OVMCodec.sol
...acts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol
+2
-11
Lib_MerkleTrie.sol
...cts/optimistic-ethereum/libraries/trie/Lib_MerkleTrie.sol
+4
-2
Lib_Bytes32Utils.sol
.../optimistic-ethereum/libraries/utils/Lib_Bytes32Utils.sol
+0
-32
Lib_BytesUtils.sol
...ts/optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol
+0
-15
package.json
packages/contracts/package.json
+0
-1
OVM_ECDSAContractAccount.spec.ts
...t/contracts/OVM/accounts/OVM_ECDSAContractAccount.spec.ts
+5
-8
OVM_StateManager.spec.ts
...cts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
+0
-1
OVM_FraudVerifier.spec.ts
...test/contracts/OVM/verification/OVM_FraudVerifier.spec.ts
+5
-20
OVM_StateTransitioner.spec.ts
.../contracts/OVM/verification/OVM_StateTransitioner.spec.ts
+48
-16
Lib_RLPWriter.spec.ts
...tracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
+2
-5
constants.ts
packages/contracts/test/helpers/constants.ts
+2
-2
No files found.
packages/contracts/.gitignore
View file @
e596f566
...
...
@@ -3,4 +3,3 @@ artifacts/
cache/
yarn-error.log
build/
.DS_STORE
packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol
View file @
e596f566
...
...
@@ -434,7 +434,6 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
}
}
/**********************
* Internal Functions *
**********************/
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol
View file @
e596f566
...
...
@@ -155,13 +155,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
"Only authenticated addresses in ovmStateManager can call this function"
);
// Initialize the execution context, must be initialized before we perform any gas metering
// or we'll throw a nuisance gas error.
_initContext(_transaction);
// TEMPORARY: Gas metering is disabled for minnet.
// // Check whether we need to start a new epoch, do so if necessary.
// _checkNeedsNewEpoch(_transaction.timestamp);
// Check whether we need to start a new epoch, do so if necessary.
_checkNeedsNewEpoch(_transaction.timestamp);
// Make sure the transaction's gas limit is valid. We don't revert here because we reserve
// reverts for INVALID_STATE_ACCESS.
...
...
@@ -169,6 +164,9 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
return;
}
// Initialize the execution context.
_initContext(_transaction);
// Run the transaction, make sure to meter the gas usage.
uint256 gasProvided = gasleft();
ovmCALL(
...
...
@@ -178,9 +176,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
);
uint256 gasUsed = gasProvided - gasleft();
// TEMPORARY: Gas metering is disabled for minnet.
// // Update the cumulative gas based on the amount of gas used.
// _updateCumulativeGas(gasUsed, _transaction.l1QueueOrigin);
// Update the cumulative gas based on the amount of gas used.
_updateCumulativeGas(gasUsed, _transaction.l1QueueOrigin);
// Wipe the execution context.
_resetContext();
...
...
@@ -501,8 +498,6 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
address(proxyEOA),
keccak256(Lib_EthUtils.getCode(address(proxyEOA)))
);
// TODO: Set account nonce to zero here (changing in a different PR for auditor convenience).
}
...
...
@@ -828,7 +823,6 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
);
}
/***************************************
* Public Functions: Execution Context *
***************************************/
...
...
@@ -1191,15 +1185,6 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
)
internal
{
// We don't set storage if the value didn't change. Although this acts as a convenient
// optimization, it's also necessary to avoid the case in which a contract with no storage
// attempts to store the value "0" at any key. Putting this value (and therefore requiring
// that the value be committed into the storage trie after execution) would incorrectly
// modify the storage root.
if (_getContractStorage(_contract, _key) == _value) {
return;
}
_checkContractStorageChange(_contract, _key);
ovmStateManager.putContractStorage(_contract, _key, _value);
}
...
...
@@ -1249,17 +1234,13 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
)
internal
{
// Start by checking for a load as we only want to charge nuisance gas proportional to
// contract size once.
_checkAccountLoad(_address);
// Check whether the account has been changed before and mark it as changed if not. We need
// this because "nuisance gas" only applies to the first time that an account is changed.
(
bool _wasAccountAlreadyChanged
) = ovmStateManager.testAndSetAccountChanged(_address);
// If we hadn't already
load
ed the account, then we'll need to charge "nuisance gas" based
// If we hadn't already
chang
ed the account, then we'll need to charge "nuisance gas" based
// on the size of the contract code.
if (_wasAccountAlreadyChanged == false) {
ovmStateManager.incrementTotalUncommittedAccounts();
...
...
@@ -1323,9 +1304,15 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
)
internal
{
// Start by checking for load to make sure we have the storage slot and that we charge the
// "nuisance gas" necessary to prove the storage slot state.
_checkContractStorageLoad(_contract, _key);
// See `_checkContractStorageLoad` for more information.
if (gasleft() < MIN_GAS_FOR_INVALID_STATE_ACCESS) {
_revertWithFlag(RevertFlag.OUT_OF_GAS);
}
// See `_checkContractStorageLoad` for more information.
if (ovmStateManager.hasContractStorage(_contract, _key) == false) {
_revertWithFlag(RevertFlag.INVALID_STATE_ACCESS);
}
// Check whether the slot has been changed before and mark it as changed if not. We need
// this because "nuisance gas" only applies to the first time that a slot is changed.
...
...
@@ -1336,10 +1323,6 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
// If we hadn't already changed the account, then we'll need to charge some fixed amount of
// "nuisance gas".
if (_wasContractStorageAlreadyChanged == false) {
// Changing a storage slot means that we're also going to have to change the
// corresponding account, so do an account change check.
_checkAccountChange(_contract);
ovmStateManager.incrementTotalUncommittedContractStorage();
_useNuisanceGas(NUISANCE_GAS_SSTORE);
}
...
...
@@ -1589,25 +1572,23 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
return false;
}
// TEMPORARY: Gas metering is disabled for minnet.
return true;
// GasMetadataKey cumulativeGasKey;
// GasMetadataKey prevEpochGasKey;
// if (_queueOrigin == Lib_OVMCodec.QueueOrigin.SEQUENCER_QUEUE) {
// cumulativeGasKey = GasMetadataKey.CUMULATIVE_SEQUENCER_QUEUE_GAS;
// prevEpochGasKey = GasMetadataKey.PREV_EPOCH_SEQUENCER_QUEUE_GAS;
// } else {
// cumulativeGasKey = GasMetadataKey.CUMULATIVE_L1TOL2_QUEUE_GAS;
// prevEpochGasKey = GasMetadataKey.PREV_EPOCH_L1TOL2_QUEUE_GAS;
// }
// return (
// (
// _getGasMetadata(cumulativeGasKey)
// - _getGasMetadata(prevEpochGasKey)
// + _gasLimit
// ) < gasMeterConfig.maxGasPerQueuePerEpoch
// );
GasMetadataKey cumulativeGasKey;
GasMetadataKey prevEpochGasKey;
if (_queueOrigin == Lib_OVMCodec.QueueOrigin.SEQUENCER_QUEUE) {
cumulativeGasKey = GasMetadataKey.CUMULATIVE_SEQUENCER_QUEUE_GAS;
prevEpochGasKey = GasMetadataKey.PREV_EPOCH_SEQUENCER_QUEUE_GAS;
} else {
cumulativeGasKey = GasMetadataKey.CUMULATIVE_L1TOL2_QUEUE_GAS;
prevEpochGasKey = GasMetadataKey.PREV_EPOCH_L1TOL2_QUEUE_GAS;
}
return (
(
_getGasMetadata(cumulativeGasKey)
- _getGasMetadata(prevEpochGasKey)
+ _gasLimit
) < gasMeterConfig.maxGasPerQueuePerEpoch
);
}
/**
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol
View file @
e596f566
...
...
@@ -17,9 +17,8 @@ contract OVM_StateManager is iOVM_StateManager {
* Contract Constants *
**********************/
bytes32 constant internal EMPTY_ACCOUNT_STORAGE_ROOT = 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421;
bytes32 constant internal EMPTY_ACCOUNT_CODE_HASH = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
bytes32 constant internal STORAGE_XOR_VALUE = 0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF;
bytes32 constant internal EMPTY_ACCOUNT_CODE_HASH = 0x00004B1DC0DE000000004B1DC0DE000000004B1DC0DE000000004B1DC0DE0000;
bytes32 constant internal STORAGE_XOR_VALUE = 0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF;
/*******************************************
...
...
@@ -138,9 +137,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
authenticated
{
Lib_OVMCodec.Account storage account = accounts[_address];
account.storageRoot = EMPTY_ACCOUNT_STORAGE_ROOT;
account.codeHash = EMPTY_ACCOUNT_CODE_HASH;
accounts[_address].codeHash = EMPTY_ACCOUNT_CODE_HASH;
}
/**
...
...
@@ -192,10 +189,7 @@ contract OVM_StateManager is iOVM_StateManager {
bool _exists
)
{
return (
accounts[_address].codeHash == EMPTY_ACCOUNT_CODE_HASH
&& accounts[_address].nonce == 0
);
return accounts[_address].codeHash == EMPTY_ACCOUNT_CODE_HASH;
}
/**
...
...
@@ -281,8 +275,7 @@ contract OVM_StateManager is iOVM_StateManager {
{
Lib_OVMCodec.Account storage account = accounts[_address];
account.nonce = 1;
account.storageRoot = EMPTY_ACCOUNT_STORAGE_ROOT;
account.codeHash = EMPTY_ACCOUNT_CODE_HASH;
account.codeHash = keccak256(hex'');
account.isFresh = true;
}
...
...
@@ -322,7 +315,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
{
return _testAndSetItemState(
_getItemHash(_address
),
keccak256(abi.encodePacked(_address)
),
ItemState.ITEM_LOADED
);
}
...
...
@@ -343,7 +336,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
{
return _testAndSetItemState(
_getItemHash(_address
),
keccak256(abi.encodePacked(_address)
),
ItemState.ITEM_CHANGED
);
}
...
...
@@ -363,7 +356,7 @@ contract OVM_StateManager is iOVM_StateManager {
bool _wasAccountCommitted
)
{
bytes32 item =
_getItemHash(_address
);
bytes32 item =
keccak256(abi.encodePacked(_address)
);
if (itemStates[item] != ItemState.ITEM_CHANGED) {
return false;
}
...
...
@@ -399,45 +392,7 @@ contract OVM_StateManager is iOVM_StateManager {
{
return totalUncommittedAccounts;
}
/**
* Checks whether a given account was changed during execution.
* @param _address Address to check.
* @return Whether or not the account was changed.
*/
function wasAccountChanged(
address _address
)
override
public
view
returns (
bool
)
{
bytes32 item = _getItemHash(_address);
return itemStates[item] >= ItemState.ITEM_CHANGED;
}
/**
* Checks whether a given account was committed after execution.
* @param _address Address to check.
* @return Whether or not the account was committed.
*/
function wasAccountCommitted(
address _address
)
override
public
view
returns (
bool
)
{
bytes32 item = _getItemHash(_address);
return itemStates[item] >= ItemState.ITEM_COMMITTED;
}
/************************************
* Public Functions: Storage Access *
...
...
@@ -541,7 +496,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
{
return _testAndSetItemState(
_getItemHash(_contract, _key
),
keccak256(abi.encodePacked(_contract, _key)
),
ItemState.ITEM_LOADED
);
}
...
...
@@ -564,7 +519,7 @@ contract OVM_StateManager is iOVM_StateManager {
)
{
return _testAndSetItemState(
_getItemHash(_contract, _key
),
keccak256(abi.encodePacked(_contract, _key)
),
ItemState.ITEM_CHANGED
);
}
...
...
@@ -586,7 +541,7 @@ contract OVM_StateManager is iOVM_StateManager {
bool _wasContractStorageCommitted
)
{
bytes32 item =
_getItemHash(_contract, _key
);
bytes32 item =
keccak256(abi.encodePacked(_contract, _key)
);
if (itemStates[item] != ItemState.ITEM_CHANGED) {
return false;
}
...
...
@@ -623,92 +578,11 @@ contract OVM_StateManager is iOVM_StateManager {
return totalUncommittedContractStorage;
}
/**
* Checks whether a given storage slot was changed during execution.
* @param _contract Address to check.
* @param _key Key of the storage slot to check.
* @return Whether or not the storage slot was changed.
*/
function wasContractStorageChanged(
address _contract,
bytes32 _key
)
override
public
view
returns (
bool
)
{
bytes32 item = _getItemHash(_contract, _key);
return itemStates[item] >= ItemState.ITEM_CHANGED;
}
/**
* Checks whether a given storage slot was committed after execution.
* @param _contract Address to check.
* @param _key Key of the storage slot to check.
* @return Whether or not the storage slot was committed.
*/
function wasContractStorageCommitted(
address _contract,
bytes32 _key
)
override
public
view
returns (
bool
)
{
bytes32 item = _getItemHash(_contract, _key);
return itemStates[item] >= ItemState.ITEM_COMMITTED;
}
/**********************
* Internal Functions *
**********************/
/**
* Generates a unique hash for an address.
* @param _address Address to generate a hash for.
* @return Unique hash for the given address.
*/
function _getItemHash(
address _address
)
internal
pure
returns (
bytes32
)
{
return keccak256(abi.encodePacked(_address));
}
/**
* Generates a unique hash for an address/key pair.
* @param _contract Address to generate a hash for.
* @param _key Key to generate a hash for.
* @return Unique hash for the given pair.
*/
function _getItemHash(
address _contract,
bytes32 _key
)
internal
pure
returns (
bytes32
)
{
return keccak256(abi.encodePacked(
_contract,
_key
));
}
/**
* Checks whether an item is in a particular state (ITEM_LOADED or ITEM_CHANGED) and sets the
* item to the provided state if not.
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/precompiles/OVM_SequencerEntrypoint.sol
View file @
e596f566
...
...
@@ -44,7 +44,7 @@ contract OVM_SequencerEntrypoint {
bytes32 r = Lib_BytesUtils.toBytes32(Lib_BytesUtils.slice(msg.data, 1, 32));
bytes32 s = Lib_BytesUtils.toBytes32(Lib_BytesUtils.slice(msg.data, 33, 32));
uint8 v = Lib_BytesUtils.toUint8(msg.data, 65);
// Remainder is the transaction to execute.
bytes memory compressedTx = Lib_BytesUtils.slice(msg.data, 66);
bool isEthSignedMessage = transactionType == TransactionType.ETH_SIGNED_MESSAGE;
...
...
packages/contracts/contracts/optimistic-ethereum/OVM/verification/OVM_FraudVerifier.sol
View file @
e596f566
...
...
@@ -122,11 +122,22 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
);
require (
_preStateRootBatchHeader.prevTotalElements + _preStateRootProof.index
+ 1
== _transactionBatchHeader.prevTotalElements + _transactionProof.index,
_preStateRootBatchHeader.prevTotalElements + _preStateRootProof.index == _transactionBatchHeader.prevTotalElements + _transactionProof.index,
"Pre-state root global index must equal to the transaction root global index."
);
_deployTransitioner(_preStateRoot, _txHash, _preStateRootProof.index);
deployTransitioner(_preStateRoot, _txHash);
}
// NB: Stack too deep :/
function deployTransitioner(bytes32 _preStateRoot, bytes32 _txHash) private {
transitioners[keccak256(abi.encodePacked(_preStateRoot, _txHash))] = iOVM_StateTransitionerFactory(
resolve("OVM_StateTransitionerFactory")
).create(
address(libAddressManager),
_preStateRoot,
_txHash
);
}
/**
...
...
@@ -189,11 +200,31 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
_postStateRoot != transitioner.getPostStateRoot(),
"State transition has not been proven fraudulent."
);
_cancelStateTransition(_postStateRootBatchHeader, _preStateRoot);
// TEMPORARY: Remove the transitioner; for minnet.
transitioners[keccak256(abi.encodePacked(_preStateRoot, _txHash))] = iOVM_StateTransitioner(0x0000000000000000000000000000000000000000);
cancelStateTransition(_postStateRootBatchHeader, _preStateRoot);
}
// NB: Stack too deep :/
function cancelStateTransition(
Lib_OVMCodec.ChainBatchHeader memory _postStateRootBatchHeader,
bytes32 _preStateRoot
) private {
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
iOVM_BondManager ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
// delete the state batch
ovmStateCommitmentChain.deleteStateBatch(
_postStateRootBatchHeader
);
// Get the timestamp and publisher for that block
(uint256 timestamp, address publisher) = abi.decode(_postStateRootBatchHeader.extraData, (uint256, address));
// slash the bonds at the bond manager
ovmBondManager.finalize(
_preStateRoot,
publisher,
timestamp
);
}
...
...
@@ -218,57 +249,4 @@ contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_Fr
{
return address(getStateTransitioner(_preStateRoot, _txHash)) != address(0);
}
/**
* Deploys a new state transitioner.
* @param _preStateRoot Pre-state root to initialize the transitioner with.
* @param _txHash Hash of the transaction this transitioner will execute.
* @param _stateTransitionIndex Index of the transaction in the chain.
*/
function _deployTransitioner(
bytes32 _preStateRoot,
bytes32 _txHash,
uint256 _stateTransitionIndex
)
internal
{
transitioners[keccak256(abi.encodePacked(_preStateRoot, _txHash))] = iOVM_StateTransitionerFactory(
resolve("OVM_StateTransitionerFactory")
).create(
address(libAddressManager),
_stateTransitionIndex,
_preStateRoot,
_txHash
);
}
/**
* Removes a state transition from the state commitment chain.
* @param _postStateRootBatchHeader Header for the post-state root.
* @param _preStateRoot Pre-state root hash.
*/
function _cancelStateTransition(
Lib_OVMCodec.ChainBatchHeader memory _postStateRootBatchHeader,
bytes32 _preStateRoot
)
internal
{
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
iOVM_BondManager ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
// Delete the state batch.
ovmStateCommitmentChain.deleteStateBatch(
_postStateRootBatchHeader
);
// Get the timestamp and publisher for that block.
(uint256 timestamp, address publisher) = abi.decode(_postStateRootBatchHeader.extraData, (uint256, address));
// Slash the bonds at the bond manager.
ovmBondManager.finalize(
_preStateRoot,
publisher,
timestamp
);
}
}
packages/contracts/contracts/optimistic-ethereum/OVM/verification/OVM_StateTransitioner.sol
View file @
e596f566
This diff is collapsed.
Click to expand it.
packages/contracts/contracts/optimistic-ethereum/OVM/verification/OVM_StateTransitionerFactory.sol
View file @
e596f566
...
...
@@ -20,14 +20,12 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
/**
* Creates a new OVM_StateTransitioner
* @param _libAddressManager Address of the Address 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(
address _libAddressManager,
uint256 _stateTransitionIndex,
bytes32 _preStateRoot,
bytes32 _transactionHash
)
...
...
@@ -39,7 +37,6 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory {
{
return new OVM_StateTransitioner(
_libAddressManager,
_stateTransitionIndex,
_preStateRoot,
_transactionHash
);
...
...
packages/contracts/contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol
View file @
e596f566
...
...
@@ -56,8 +56,6 @@ interface iOVM_StateManager {
function commitAccount(address _address) external returns (bool _wasAccountCommitted);
function incrementTotalUncommittedAccounts() external;
function getTotalUncommittedAccounts() external view returns (uint256 _total);
function wasAccountChanged(address _address) external view returns (bool);
function wasAccountCommitted(address _address) external view returns (bool);
/************************************
...
...
@@ -72,6 +70,4 @@ interface iOVM_StateManager {
function commitContractStorage(address _contract, bytes32 _key) external returns (bool _wasContractStorageCommitted);
function incrementTotalUncommittedContractStorage() external;
function getTotalUncommittedContractStorage() external view returns (uint256 _total);
function wasContractStorageChanged(address _contract, bytes32 _key) external view returns (bool);
function wasContractStorageCommitted(address _contract, bytes32 _key) external view returns (bool);
}
packages/contracts/contracts/optimistic-ethereum/iOVM/verification/iOVM_StateTransitioner.sol
View file @
e596f566
...
...
@@ -10,20 +10,6 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
*/
interface iOVM_StateTransitioner {
/**********
* Events *
**********/
event AccountCommitted(
address _address
);
event ContractStorageCommitted(
address _address,
bytes32 _key
);
/**********************************
* Public Functions: State Access *
**********************************/
...
...
@@ -40,12 +26,19 @@ interface iOVM_StateTransitioner {
function proveContractState(
address _ovmContractAddress,
address _ethContractAddress,
Lib_OVMCodec.EVMAccount calldata _account,
bytes calldata _stateTrieWitness
) external;
function proveEmptyContractState(
address _ovmContractAddress,
bytes calldata _stateTrieWitness
) external;
function proveStorageSlot(
address _ovmContractAddress,
bytes32 _key,
bytes32 _value,
bytes calldata _storageTrieWitness
) external;
...
...
@@ -71,6 +64,7 @@ interface iOVM_StateTransitioner {
function commitStorageSlot(
address _ovmContractAddress,
bytes32 _key,
bytes calldata _stateTrieWitness,
bytes calldata _storageTrieWitness
) external;
...
...
packages/contracts/contracts/optimistic-ethereum/iOVM/verification/iOVM_StateTransitionerFactory.sol
View file @
e596f566
...
...
@@ -15,7 +15,6 @@ interface iOVM_StateTransitionerFactory {
function create(
address _proxyManager,
uint256 _stateTransitionIndex,
bytes32 _preStateRoot,
bytes32 _transactionHash
)
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol
View file @
e596f566
...
...
@@ -6,7 +6,6 @@ pragma experimental ABIEncoderV2;
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
import { Lib_RLPWriter } from "../rlp/Lib_RLPWriter.sol";
import { Lib_BytesUtils } from "../utils/Lib_BytesUtils.sol";
import { Lib_Bytes32Utils } from "../utils/Lib_Bytes32Utils.sol";
/**
* @title Lib_OVMCodec
...
...
@@ -316,16 +315,8 @@ library Lib_OVMCodec {
// Unfortunately we can't create this array outright because
// RLPWriter.encodeList will reject fixed-size arrays. Assigning
// index-by-index circumvents this issue.
raw[0] = Lib_RLPWriter.writeBytes(
Lib_Bytes32Utils.removeLeadingZeros(
bytes32(_account.nonce)
)
);
raw[1] = Lib_RLPWriter.writeBytes(
Lib_Bytes32Utils.removeLeadingZeros(
bytes32(_account.balance)
)
);
raw[0] = Lib_RLPWriter.writeUint(_account.nonce);
raw[1] = Lib_RLPWriter.writeUint(_account.balance);
raw[2] = Lib_RLPWriter.writeBytes(abi.encodePacked(_account.storageRoot));
raw[3] = Lib_RLPWriter.writeBytes(abi.encodePacked(_account.codeHash));
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/trie/Lib_MerkleTrie.sol
View file @
e596f566
...
...
@@ -145,7 +145,9 @@ library Lib_MerkleTrie {
{
// Special case when inserting the very first node.
if (_root == KECCAK256_RLP_NULL_BYTES) {
return getSingleNodeRootHash(_key, _value);
return keccak256(
_makeLeafNode(_key, _value).encoded
);
}
TrieNode[] memory proof = _parseProof(_proof);
...
...
@@ -210,7 +212,7 @@ library Lib_MerkleTrie {
)
{
return keccak256(_makeLeafNode(
Lib_BytesUtils.toNibbles(_key)
,
_key
,
_value
).encoded);
}
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/utils/Lib_Bytes32Utils.sol
View file @
e596f566
...
...
@@ -57,36 +57,4 @@ library Lib_Bytes32Utils {
{
return bytes32(uint256(_in));
}
function removeLeadingZeros(
bytes32 _in
)
internal
pure
returns (
bytes memory _out
)
{
bytes memory out;
assembly {
// Figure out how many leading zero bytes to remove.
let shift := 0
for { let i := 0 } and(lt(i, 32), eq(byte(i, _in), 0)) { i := add(i, 1) } {
shift := add(shift, 1)
}
// Reserve some space for our output and fix the free memory pointer.
out := mload(0x40)
mstore(0x40, add(out, 0x40))
// Shift the value and store it into the output bytes.
mstore(add(out, 0x20), shl(mul(shift, 8), _in))
// Store the new size (with leading zero bytes removed) in the output byte size.
mstore(out, sub(32, shift))
}
return out;
}
}
packages/contracts/contracts/optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol
View file @
e596f566
...
...
@@ -170,21 +170,6 @@ library Lib_BytesUtils {
return slice(_bytes, _start, _bytes.length - _start);
}
function toBytes32PadLeft(
bytes memory _bytes
)
internal
pure
returns (bytes32)
{
bytes32 ret;
uint256 len = _bytes.length <= 32 ? _bytes.length : 32;
assembly {
ret := shr(mul(sub(32, len), 8), mload(add(_bytes, 32)))
}
return ret;
}
function toBytes32(
bytes memory _bytes
)
...
...
packages/contracts/package.json
View file @
e596f566
...
...
@@ -22,7 +22,6 @@
"test:gas"
:
"buidler test
\"
test/contracts/OVM/execution/OVM_StateManager.gas-spec.ts
\"
--no-compile --show-stack-traces"
,
"lint"
:
"yarn run lint:typescript"
,
"lint:typescript"
:
"tslint --format stylish --project ."
,
"lint:fix"
:
"yarn run lint:fix:typescript"
,
"lint:fix:typescript"
:
"prettier --config prettier-config.json --write
\"
buidler.config.ts
\"
\"
{src,test}/**/*.ts
\"
"
,
"clean"
:
"rm -rf ./artifacts ./build ./cache"
,
"deploy"
:
"./bin/deploy.js"
...
...
packages/contracts/test/contracts/OVM/accounts/OVM_ECDSAContractAccount.spec.ts
View file @
e596f566
...
...
@@ -25,11 +25,8 @@ const callPrecompile = async (
if
(
gasLimit
)
{
return
Helper_PrecompileCaller
.
callPrecompile
(
precompile
.
address
,
precompile
.
interface
.
encodeFunctionData
(
functionName
,
functionParams
||
[]
),
{
gasLimit
}
precompile
.
interface
.
encodeFunctionData
(
functionName
,
functionParams
||
[]),
{
gasLimit
}
)
}
return
Helper_PrecompileCaller
.
callPrecompile
(
...
...
@@ -190,7 +187,7 @@ describe('OVM_ECDSAContractAccount', () => {
it
(
`should revert on incorrect nonce`
,
async
()
=>
{
const
alteredNonceTx
=
{
...
DEFAULT_EIP155_TX
,
nonce
:
99
,
nonce
:
99
}
const
message
=
serializeNativeTransaction
(
alteredNonceTx
)
const
sig
=
await
signNativeTransaction
(
wallet
,
alteredNonceTx
)
...
...
@@ -244,7 +241,7 @@ describe('OVM_ECDSAContractAccount', () => {
it
(
`should revert on insufficient gas`
,
async
()
=>
{
const
alteredInsufficientGasTx
=
{
...
DEFAULT_EIP155_TX
,
gasLimit
:
200000000
,
gasLimit
:
200000000
}
const
message
=
serializeNativeTransaction
(
alteredInsufficientGasTx
)
const
sig
=
await
signNativeTransaction
(
wallet
,
alteredInsufficientGasTx
)
...
...
@@ -260,7 +257,7 @@ describe('OVM_ECDSAContractAccount', () => {
`0x
${
sig
.
r
}
`
,
//r
`0x
${
sig
.
s
}
`
,
//s
],
40000000
40000000
,
)
const
ovmREVERT
:
any
=
...
...
packages/contracts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
View file @
e596f566
...
...
@@ -188,7 +188,6 @@ describe('OVM_StateManager', () => {
beforeEach
(
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
{
...
DUMMY_ACCOUNTS
[
0
].
data
,
nonce
:
0
,
codeHash
:
EMPTY_ACCOUNT_CODE_HASH
,
})
})
...
...
packages/contracts/test/contracts/OVM/verification/OVM_FraudVerifier.spec.ts
View file @
e596f566
...
...
@@ -179,10 +179,7 @@ describe('OVM_FraudVerifier', () => {
DUMMY_OVM_TRANSACTIONS
[
0
],
DUMMY_TX_CHAIN_ELEMENTS
[
0
],
DUMMY_BATCH_HEADERS
[
0
],
{
...
DUMMY_BATCH_PROOFS
[
0
],
index
:
DUMMY_BATCH_PROOFS
[
0
].
index
+
1
,
}
DUMMY_BATCH_PROOFS
[
0
]
)
).
to
.
not
.
be
.
reverted
...
...
@@ -229,10 +226,7 @@ describe('OVM_FraudVerifier', () => {
DUMMY_OVM_TRANSACTIONS
[
0
],
DUMMY_TX_CHAIN_ELEMENTS
[
0
],
DUMMY_BATCH_HEADERS
[
0
],
{
...
DUMMY_BATCH_PROOFS
[
0
],
index
:
DUMMY_BATCH_PROOFS
[
0
].
index
+
1
,
}
DUMMY_BATCH_PROOFS
[
0
]
)
})
...
...
@@ -436,10 +430,7 @@ describe('OVM_FraudVerifier', () => {
DUMMY_OVM_TRANSACTIONS
[
1
],
DUMMY_TX_CHAIN_ELEMENTS
[
0
],
DUMMY_BATCH_HEADERS
[
0
],
{
...
DUMMY_BATCH_PROOFS
[
0
],
index
:
DUMMY_BATCH_PROOFS
[
0
].
index
+
1
,
}
DUMMY_BATCH_PROOFS
[
0
]
)
).
to
.
not
.
be
.
reverted
...
...
@@ -482,10 +473,7 @@ describe('OVM_FraudVerifier', () => {
DUMMY_OVM_TRANSACTIONS
[
1
],
DUMMY_TX_CHAIN_ELEMENTS
[
1
],
DUMMY_BATCH_HEADERS
[
1
],
{
...
DUMMY_BATCH_PROOFS
[
0
],
index
:
DUMMY_BATCH_PROOFS
[
0
].
index
+
1
,
}
DUMMY_BATCH_PROOFS
[
0
]
)
// finalize it as well
...
...
@@ -518,10 +506,7 @@ describe('OVM_FraudVerifier', () => {
DUMMY_OVM_TRANSACTIONS
[
1
],
DUMMY_TX_CHAIN_ELEMENTS
[
1
],
DUMMY_BATCH_HEADERS
[
1
],
{
...
DUMMY_BATCH_PROOFS
[
0
],
index
:
DUMMY_BATCH_PROOFS
[
0
].
index
+
1
,
}
DUMMY_BATCH_PROOFS
[
0
]
)
// finalize the new fraud first
...
...
packages/contracts/test/contracts/OVM/verification/OVM_StateTransitioner.spec.ts
View file @
e596f566
...
...
@@ -84,7 +84,6 @@ describe('OVM_StateTransitioner', () => {
beforeEach
(
async
()
=>
{
OVM_StateTransitioner
=
await
Factory__OVM_StateTransitioner
.
deploy
(
AddressManager
.
address
,
0
,
NULL_BYTES32
,
NULL_BYTES32
)
...
...
@@ -96,7 +95,6 @@ describe('OVM_StateTransitioner', () => {
let
account
:
any
beforeEach
(()
=>
{
Mock__OVM_StateManager
.
smocked
.
hasAccount
.
will
.
return
.
with
(
false
)
Mock__OVM_StateManager
.
smocked
.
hasEmptyAccount
.
will
.
return
.
with
(
false
)
account
=
{
nonce
:
0
,
balance
:
0
,
...
...
@@ -105,6 +103,23 @@ describe('OVM_StateTransitioner', () => {
}
})
describe
(
'
when provided an invalid code hash
'
,
()
=>
{
beforeEach
(()
=>
{
account
.
codeHash
=
NON_NULL_BYTES32
})
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
OVM_StateTransitioner
.
proveContractState
(
ovmContractAddress
,
ethContractAddress
,
account
,
'
0x
'
)
).
to
.
be
.
revertedWith
(
'
Invalid code hash provided.
'
)
})
})
describe
(
'
when provided a valid code hash
'
,
()
=>
{
beforeEach
(
async
()
=>
{
ethContractAddress
=
OVM_StateTransitioner
.
address
...
...
@@ -121,6 +136,7 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner
.
proveContractState
(
ovmContractAddress
,
ethContractAddress
,
account
,
proof
)
).
to
.
be
.
reverted
...
...
@@ -146,18 +162,20 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner
=
await
Factory__OVM_StateTransitioner
.
deploy
(
AddressManager
.
address
,
0
,
test
.
accountTrieRoot
,
NULL_BYTES32
)
})
it
(
'
should put the account in the state manager
'
,
async
()
=>
{
await
OVM_StateTransitioner
.
proveContractState
(
ovmContractAddress
,
ethContractAddress
,
proof
)
await
expect
(
OVM_StateTransitioner
.
proveContractState
(
ovmContractAddress
,
ethContractAddress
,
account
,
proof
)
).
to
.
not
.
be
.
reverted
expect
(
Mock__OVM_StateManager
.
smocked
.
putAccount
.
calls
[
0
]
...
...
@@ -192,6 +210,7 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner
.
proveStorageSlot
(
NON_ZERO_ADDRESS
,
NON_NULL_BYTES32
,
NON_NULL_BYTES32
,
'
0x
'
)
).
to
.
be
.
revertedWith
(
...
...
@@ -229,7 +248,12 @@ describe('OVM_StateTransitioner', () => {
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
OVM_StateTransitioner
.
proveStorageSlot
(
ZERO_ADDRESS
,
key
,
proof
)
OVM_StateTransitioner
.
proveStorageSlot
(
ZERO_ADDRESS
,
key
,
val
,
proof
)
).
to
.
be
.
reverted
})
})
...
...
@@ -259,7 +283,12 @@ describe('OVM_StateTransitioner', () => {
it
(
'
should insert the storage slot
'
,
async
()
=>
{
await
expect
(
OVM_StateTransitioner
.
proveStorageSlot
(
ZERO_ADDRESS
,
key
,
proof
)
OVM_StateTransitioner
.
proveStorageSlot
(
ZERO_ADDRESS
,
key
,
val
,
proof
)
).
to
.
not
.
be
.
reverted
expect
(
...
...
@@ -298,9 +327,6 @@ describe('OVM_StateTransitioner', () => {
describe
(
'
when the account was not changed or has already been committed
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
smocked
.
getTotalUncommittedContractStorage
.
will
.
return
.
with
(
0
)
Mock__OVM_StateManager
.
smocked
.
commitAccount
.
will
.
return
.
with
(
false
)
})
...
...
@@ -308,7 +334,7 @@ describe('OVM_StateTransitioner', () => {
await
expect
(
OVM_StateTransitioner
.
commitContractState
(
ovmContractAddress
,
'
0x
'
)
).
to
.
be
.
revertedWith
(
`Account state wasn't changed or has already been committed`
'
Account was not changed or has already been committed.
'
)
})
})
...
...
@@ -397,9 +423,14 @@ describe('OVM_StateTransitioner', () => {
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
OVM_StateTransitioner
.
commitStorageSlot
(
ovmContractAddress
,
key
,
'
0x
'
)
OVM_StateTransitioner
.
commitStorageSlot
(
ovmContractAddress
,
key
,
'
0x
'
,
'
0x
'
)
).
to
.
be
.
revertedWith
(
`Storage slot value wasn't changed or has already been committed.`
'
Storage slot was not changed or has already been committed.
'
)
})
})
...
...
@@ -472,6 +503,7 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner
.
commitStorageSlot
(
ovmContractAddress
,
key
,
accountTrieProof
,
storageTrieProof
)
).
to
.
not
.
be
.
reverted
...
...
packages/contracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
View file @
e596f566
...
...
@@ -45,11 +45,8 @@ describe('Lib_RLPWriter', () => {
describe
(
'
Use of library with other memory-modifying operations
'
,
()
=>
{
it
(
'
should allow creation of a contract beforehand and still work
'
,
async
()
=>
{
const
randomAddress
=
'
0x1234123412341234123412341234123412341234
'
const
rlpEncodedRandomAddress
=
'
0x941234123412341234123412341234123412341234
'
const
encoded
=
await
Lib_RLPWriter
.
callStatic
.
writeAddressWithOtherMemory
(
randomAddress
)
const
rlpEncodedRandomAddress
=
'
0x941234123412341234123412341234123412341234
'
const
encoded
=
await
Lib_RLPWriter
.
callStatic
.
writeAddressWithOtherMemory
(
randomAddress
)
expect
(
encoded
).
to
.
eq
(
rlpEncodedRandomAddress
)
})
})
...
...
packages/contracts/test/helpers/constants.ts
View file @
e596f566
...
...
@@ -24,7 +24,7 @@ export const ZERO_ADDRESS = makeAddress('00')
export
const
NON_ZERO_ADDRESS
=
makeAddress
(
'
11
'
)
export
const
VERIFIED_EMPTY_CONTRACT_HASH
=
'
0x
c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47
0
'
'
0x
00004B1DC0DE000000004B1DC0DE000000004B1DC0DE000000004B1DC0DE000
0
'
export
const
STORAGE_XOR_VALUE
=
'
0xFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEFFEEDFACECAFEBEEF
'
...
...
@@ -47,6 +47,6 @@ export const getStorageXOR = (key: string): string => {
}
export
const
EMPTY_ACCOUNT_CODE_HASH
=
'
0x
c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47
0
'
'
0x
00004B1DC0DE000000004B1DC0DE000000004B1DC0DE000000004B1DC0DE000
0
'
export
const
KECCAK_256_NULL
=
'
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
'
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