Commit a4340e51 authored by Kelvin Fichter's avatar Kelvin Fichter Committed by GitHub

Added fix for error in StateTransitioner (#13)

* Added fix for error in StateTransitioner

* Added tests for some precompiles (#14)

* Added tests for some precompiles

* Cleanup build process (#15)

* Cleaned build and added typechain

* Linted files
parent e7196c18
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
usePlugin('@nomiclabs/buidler-ethers') usePlugin('@nomiclabs/buidler-ethers')
usePlugin('@nomiclabs/buidler-waffle') usePlugin('@nomiclabs/buidler-waffle')
usePlugin('buidler-typechain')
import '@eth-optimism/smock/build/src/buidler-plugins/compiler-storage-layout' import '@eth-optimism/smock/build/src/buidler-plugins/compiler-storage-layout'
...@@ -24,6 +25,10 @@ const config: BuidlerConfig = { ...@@ -24,6 +25,10 @@ const config: BuidlerConfig = {
version: '0.7.0', version: '0.7.0',
optimizer: { enabled: true, runs: 200 }, optimizer: { enabled: true, runs: 200 },
}, },
typechain: {
outDir: 'build/types',
target: 'ethers-v5',
},
} }
export default config export default config
...@@ -143,6 +143,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ...@@ -143,6 +143,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof L2MessageInclusionProof memory _proof
) )
internal internal
view
returns ( returns (
bool bool
) )
...@@ -162,6 +163,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ...@@ -162,6 +163,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof L2MessageInclusionProof memory _proof
) )
internal internal
view
returns ( returns (
bool bool
) )
...@@ -187,6 +189,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ...@@ -187,6 +189,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof L2MessageInclusionProof memory _proof
) )
internal internal
pure
returns ( returns (
bool bool
) )
......
...@@ -204,7 +204,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba ...@@ -204,7 +204,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
"Must append more than zero transactions." "Must append more than zero transactions."
); );
(uint40 totalElements, uint32 nextQueueIndex) = _getLatestBatchContext(); (, uint32 nextQueueIndex) = _getLatestBatchContext();
bytes32[] memory leaves = new bytes32[](_numQueuedTransactions); bytes32[] memory leaves = new bytes32[](_numQueuedTransactions);
for (uint i = 0; i < _numQueuedTransactions; i++) { for (uint i = 0; i < _numQueuedTransactions; i++) {
...@@ -424,7 +424,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba ...@@ -424,7 +424,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
uint32 _nextQueueIndex uint32 _nextQueueIndex
) )
internal internal
view pure
returns ( returns (
bytes28 _context bytes28 _context
) )
...@@ -512,6 +512,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba ...@@ -512,6 +512,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
uint32 _nextQueueIndex uint32 _nextQueueIndex
) )
internal internal
view
{ {
if (queue.getLength() == 0) { if (queue.getLength() == 0) {
return; return;
......
...@@ -1319,6 +1319,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -1319,6 +1319,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
bytes memory _data bytes memory _data
) )
internal internal
view
returns ( returns (
bytes memory _revertdata bytes memory _revertdata
) )
...@@ -1362,6 +1363,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -1362,6 +1363,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
bytes memory _revertdata bytes memory _revertdata
) )
internal internal
pure
returns ( returns (
RevertFlag _flag, RevertFlag _flag,
uint256 _nuisanceGasLeft, uint256 _nuisanceGasLeft,
......
...@@ -22,7 +22,7 @@ contract OVM_SafetyChecker is iOVM_SafetyChecker { ...@@ -22,7 +22,7 @@ contract OVM_SafetyChecker is iOVM_SafetyChecker {
) )
override override
external external
view pure
returns (bool) returns (bool)
{ {
// autogenerated by gen_safety_checker_constants.py // autogenerated by gen_safety_checker_constants.py
......
...@@ -20,6 +20,7 @@ contract OVM_L1MessageSender is iOVM_L1MessageSender { ...@@ -20,6 +20,7 @@ contract OVM_L1MessageSender is iOVM_L1MessageSender {
function getL1MessageSender() function getL1MessageSender()
override override
public public
view
returns ( returns (
address _l1MessageSender address _l1MessageSender
) )
......
...@@ -332,12 +332,10 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver { ...@@ -332,12 +332,10 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
/** /**
* Allows a user to commit the final state of a contract. * Allows a user to commit the final state of a contract.
* @param _ovmContractAddress Address of the contract on the OVM. * @param _ovmContractAddress Address of the contract on the OVM.
* @param _account Claimed account state.
* @param _stateTrieWitness Proof of the account state. * @param _stateTrieWitness Proof of the account state.
*/ */
function commitContractState( function commitContractState(
address _ovmContractAddress, address _ovmContractAddress,
Lib_OVMCodec.EVMAccount memory _account,
bytes memory _stateTrieWitness bytes memory _stateTrieWitness
) )
override override
...@@ -349,9 +347,13 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver { ...@@ -349,9 +347,13 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
"Account was not changed or has already been committed." "Account was not changed or has already been committed."
); );
Lib_OVMCodec.Account memory account = ovmStateManager.getAccount(_ovmContractAddress);
postStateRoot = Lib_SecureMerkleTrie.update( postStateRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_ovmContractAddress), abi.encodePacked(_ovmContractAddress),
Lib_OVMCodec.encodeEVMAccount(_account), Lib_OVMCodec.encodeEVMAccount(
Lib_OVMCodec.toEVMAccount(account)
),
_stateTrieWitness, _stateTrieWitness,
postStateRoot postStateRoot
); );
...@@ -361,14 +363,12 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver { ...@@ -361,14 +363,12 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
* 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 _value Claimed account slot value.
* @param _stateTrieWitness Proof of the account state. * @param _stateTrieWitness Proof of the account state.
* @param _storageTrieWitness Proof of the storage slot. * @param _storageTrieWitness Proof of the storage slot.
*/ */
function commitStorageSlot( function commitStorageSlot(
address _ovmContractAddress, address _ovmContractAddress,
bytes32 _key, bytes32 _key,
bytes32 _value,
bytes memory _stateTrieWitness, bytes memory _stateTrieWitness,
bytes memory _storageTrieWitness bytes memory _storageTrieWitness
) )
...@@ -381,23 +381,26 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver { ...@@ -381,23 +381,26 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
"Storage slot was not changed or has already been committed." "Storage slot was not changed or has already been committed."
); );
Lib_OVMCodec.EVMAccount memory account = Lib_OVMCodec.toEVMAccount( Lib_OVMCodec.Account memory account = ovmStateManager.getAccount(_ovmContractAddress);
ovmStateManager.getAccount(_ovmContractAddress) bytes32 value = ovmStateManager.getContractStorage(_ovmContractAddress, _key);
);
account.storageRoot = Lib_SecureMerkleTrie.update( account.storageRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_key), abi.encodePacked(_key),
abi.encodePacked(_value), abi.encodePacked(value),
_storageTrieWitness, _storageTrieWitness,
account.storageRoot account.storageRoot
); );
postStateRoot = Lib_SecureMerkleTrie.update( postStateRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_ovmContractAddress), abi.encodePacked(_ovmContractAddress),
Lib_OVMCodec.encodeEVMAccount(account), Lib_OVMCodec.encodeEVMAccount(
Lib_OVMCodec.toEVMAccount(account)
),
_stateTrieWitness, _stateTrieWitness,
postStateRoot postStateRoot
); );
ovmStateManager.putAccount(_ovmContractAddress, account);
} }
......
...@@ -58,14 +58,12 @@ interface iOVM_StateTransitioner { ...@@ -58,14 +58,12 @@ interface iOVM_StateTransitioner {
function commitContractState( function commitContractState(
address _ovmContractAddress, address _ovmContractAddress,
Lib_OVMCodec.EVMAccount calldata _account,
bytes calldata _stateTrieWitness bytes calldata _stateTrieWitness
) external; ) external;
function commitStorageSlot( function commitStorageSlot(
address _ovmContractAddress, address _ovmContractAddress,
bytes32 _key, bytes32 _key,
bytes32 _value,
bytes calldata _stateTrieWitness, bytes calldata _stateTrieWitness,
bytes calldata _storageTrieWitness bytes calldata _storageTrieWitness
) external; ) external;
......
...@@ -25,9 +25,7 @@ contract Lib_AddressResolver { ...@@ -25,9 +25,7 @@ contract Lib_AddressResolver {
*/ */
constructor( constructor(
address _libAddressManager address _libAddressManager
) ) {
public
{
libAddressManager = Lib_AddressManager(_libAddressManager); libAddressManager = Lib_AddressManager(_libAddressManager);
} }
......
...@@ -28,9 +28,7 @@ abstract contract Ownable { ...@@ -28,9 +28,7 @@ abstract contract Ownable {
* Constructor * * Constructor *
***************/ ***************/
constructor() constructor() {
internal
{
owner = msg.sender; owner = msg.sender;
emit OwnershipTransferred(address(0), owner); emit OwnershipTransferred(address(0), owner);
} }
......
...@@ -79,7 +79,7 @@ library Lib_RLPReader { ...@@ -79,7 +79,7 @@ library Lib_RLPReader {
{ {
( (
uint256 listOffset, uint256 listOffset,
uint256 listLength, ,
RLPItemType itemType RLPItemType itemType
) = _decodeLength(_in); ) = _decodeLength(_in);
......
...@@ -77,7 +77,7 @@ library Lib_MerkleTrie { ...@@ -77,7 +77,7 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _verified bool _verified
) )
...@@ -108,7 +108,7 @@ library Lib_MerkleTrie { ...@@ -108,7 +108,7 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _verified bool _verified
) )
...@@ -138,7 +138,7 @@ library Lib_MerkleTrie { ...@@ -138,7 +138,7 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -171,7 +171,7 @@ library Lib_MerkleTrie { ...@@ -171,7 +171,7 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _exists, bool _exists,
bytes memory _value bytes memory _value
...@@ -206,7 +206,7 @@ library Lib_MerkleTrie { ...@@ -206,7 +206,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
internal internal
view pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -237,7 +237,7 @@ library Lib_MerkleTrie { ...@@ -237,7 +237,7 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
private private
view pure
returns ( returns (
uint256 _pathLength, uint256 _pathLength,
bytes memory _keyRemainder, bytes memory _keyRemainder,
...@@ -358,7 +358,7 @@ library Lib_MerkleTrie { ...@@ -358,7 +358,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
private private
view pure
returns ( returns (
TrieNode[] memory _newPath TrieNode[] memory _newPath
) )
...@@ -484,7 +484,7 @@ library Lib_MerkleTrie { ...@@ -484,7 +484,7 @@ library Lib_MerkleTrie {
bytes memory _key bytes memory _key
) )
private private
view pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -547,7 +547,7 @@ library Lib_MerkleTrie { ...@@ -547,7 +547,7 @@ library Lib_MerkleTrie {
bytes memory _proof bytes memory _proof
) )
private private
view pure
returns ( returns (
TrieNode[] memory _parsed TrieNode[] memory _parsed
) )
...@@ -577,7 +577,7 @@ library Lib_MerkleTrie { ...@@ -577,7 +577,7 @@ library Lib_MerkleTrie {
Lib_RLPReader.RLPItem memory _node Lib_RLPReader.RLPItem memory _node
) )
private private
view pure
returns ( returns (
bytes32 _nodeID bytes32 _nodeID
) )
...@@ -604,7 +604,7 @@ library Lib_MerkleTrie { ...@@ -604,7 +604,7 @@ library Lib_MerkleTrie {
TrieNode memory _node TrieNode memory _node
) )
private private
view pure
returns ( returns (
bytes memory _path bytes memory _path
) )
...@@ -622,7 +622,7 @@ library Lib_MerkleTrie { ...@@ -622,7 +622,7 @@ library Lib_MerkleTrie {
TrieNode memory _node TrieNode memory _node
) )
private private
view pure
returns ( returns (
bytes memory _key bytes memory _key
) )
...@@ -639,7 +639,7 @@ library Lib_MerkleTrie { ...@@ -639,7 +639,7 @@ library Lib_MerkleTrie {
TrieNode memory _node TrieNode memory _node
) )
private private
view pure
returns ( returns (
bytes memory _value bytes memory _value
) )
...@@ -678,7 +678,7 @@ library Lib_MerkleTrie { ...@@ -678,7 +678,7 @@ library Lib_MerkleTrie {
TrieNode memory _node TrieNode memory _node
) )
private private
view pure
returns ( returns (
NodeType _type NodeType _type
) )
...@@ -711,7 +711,7 @@ library Lib_MerkleTrie { ...@@ -711,7 +711,7 @@ library Lib_MerkleTrie {
bytes memory _b bytes memory _b
) )
private private
view pure
returns ( returns (
uint256 _shared uint256 _shared
) )
...@@ -732,7 +732,7 @@ library Lib_MerkleTrie { ...@@ -732,7 +732,7 @@ library Lib_MerkleTrie {
bytes[] memory _raw bytes[] memory _raw
) )
private private
view pure
returns ( returns (
TrieNode memory _node TrieNode memory _node
) )
...@@ -754,7 +754,7 @@ library Lib_MerkleTrie { ...@@ -754,7 +754,7 @@ library Lib_MerkleTrie {
Lib_RLPReader.RLPItem[] memory _items Lib_RLPReader.RLPItem[] memory _items
) )
private private
view pure
returns ( returns (
TrieNode memory _node TrieNode memory _node
) )
...@@ -777,7 +777,7 @@ library Lib_MerkleTrie { ...@@ -777,7 +777,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
private private
view pure
returns ( returns (
TrieNode memory _node TrieNode memory _node
) )
...@@ -803,7 +803,7 @@ library Lib_MerkleTrie { ...@@ -803,7 +803,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
private private
view pure
returns ( returns (
TrieNode memory _node TrieNode memory _node
) )
...@@ -821,7 +821,7 @@ library Lib_MerkleTrie { ...@@ -821,7 +821,7 @@ library Lib_MerkleTrie {
*/ */
function _makeEmptyBranchNode() function _makeEmptyBranchNode()
private private
view pure
returns ( returns (
TrieNode memory _node TrieNode memory _node
) )
...@@ -844,7 +844,7 @@ library Lib_MerkleTrie { ...@@ -844,7 +844,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
private private
view pure
returns ( returns (
TrieNode memory _updatedNode TrieNode memory _updatedNode
) )
...@@ -867,7 +867,7 @@ library Lib_MerkleTrie { ...@@ -867,7 +867,7 @@ library Lib_MerkleTrie {
bytes memory _value bytes memory _value
) )
private private
view pure
returns ( returns (
TrieNode memory _updatedNode TrieNode memory _updatedNode
) )
...@@ -888,7 +888,7 @@ library Lib_MerkleTrie { ...@@ -888,7 +888,7 @@ library Lib_MerkleTrie {
bool _isLeaf bool _isLeaf
) )
private private
view pure
returns ( returns (
bytes memory _prefixedKey bytes memory _prefixedKey
) )
...@@ -909,7 +909,7 @@ library Lib_MerkleTrie { ...@@ -909,7 +909,7 @@ library Lib_MerkleTrie {
bytes memory _path bytes memory _path
) )
private private
view pure
returns ( returns (
bytes memory _unprefixedKey bytes memory _unprefixedKey
) )
......
...@@ -33,7 +33,7 @@ library Lib_SecureMerkleTrie { ...@@ -33,7 +33,7 @@ library Lib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _verified bool _verified
) )
...@@ -58,7 +58,7 @@ library Lib_SecureMerkleTrie { ...@@ -58,7 +58,7 @@ library Lib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _verified bool _verified
) )
...@@ -85,7 +85,7 @@ library Lib_SecureMerkleTrie { ...@@ -85,7 +85,7 @@ library Lib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -108,7 +108,7 @@ library Lib_SecureMerkleTrie { ...@@ -108,7 +108,7 @@ library Lib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view pure
returns ( returns (
bool _exists, bool _exists,
bytes memory _value bytes memory _value
...@@ -129,7 +129,7 @@ library Lib_SecureMerkleTrie { ...@@ -129,7 +129,7 @@ library Lib_SecureMerkleTrie {
bytes memory _value bytes memory _value
) )
internal internal
view pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
......
...@@ -145,7 +145,7 @@ library Lib_EthUtils { ...@@ -145,7 +145,7 @@ library Lib_EthUtils {
uint256 _nonce uint256 _nonce
) )
internal internal
view pure
returns ( returns (
address _address address _address
) )
...@@ -171,7 +171,7 @@ library Lib_EthUtils { ...@@ -171,7 +171,7 @@ library Lib_EthUtils {
bytes32 _salt bytes32 _salt
) )
internal internal
view pure
returns (address _address) returns (address _address)
{ {
bytes32 hashedData = keccak256(abi.encodePacked( bytes32 hashedData = keccak256(abi.encodePacked(
......
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
// author: cobaltedge // author: cobaltedge
......
...@@ -10,7 +10,7 @@ library Lib_MerkleUtils { ...@@ -10,7 +10,7 @@ library Lib_MerkleUtils {
bytes32[] memory _hashes bytes32[] memory _hashes
) )
internal internal
view pure
returns ( returns (
bytes32 _root bytes32 _root
) )
......
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;
import { Helper_SimpleProxy } from "./Helper_SimpleProxy.sol";
contract Helper_PrecompileCaller is Helper_SimpleProxy {
function callPrecompile(
address _precompile,
bytes memory _data
)
public
{
if (msg.sender == owner) {
makeExternalCall(_precompile, _data);
} else {
makeExternalCall(target, msg.data);
}
}
function getL1MessageSender(
address _precompile,
bytes memory _data
)
public
returns (
address
)
{
callPrecompile(_precompile, _data);
}
}
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
import { console } from "@nomiclabs/buidler/console.sol";
contract Helper_SimpleProxy { contract Helper_SimpleProxy {
address private owner; address internal owner;
address private target; address internal target;
constructor() { constructor() {
owner = msg.sender; owner = msg.sender;
...@@ -31,7 +33,7 @@ contract Helper_SimpleProxy { ...@@ -31,7 +33,7 @@ contract Helper_SimpleProxy {
address _target, address _target,
bytes memory _calldata bytes memory _calldata
) )
private internal
{ {
(bool success, bytes memory returndata) = _target.call(_calldata); (bool success, bytes memory returndata) = _target.call(_calldata);
......
...@@ -137,6 +137,7 @@ contract Helper_TestRunner { ...@@ -137,6 +137,7 @@ contract Helper_TestRunner {
bytes memory _revertdata bytes memory _revertdata
) )
internal internal
pure
returns ( returns (
uint256 _flag, uint256 _flag,
uint256 _nuisanceGasLeft, uint256 _nuisanceGasLeft,
......
...@@ -14,7 +14,7 @@ contract TestLib_RLPReader { ...@@ -14,7 +14,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
bytes[] memory bytes[] memory
) )
...@@ -31,7 +31,7 @@ contract TestLib_RLPReader { ...@@ -31,7 +31,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
string memory string memory
) )
...@@ -43,7 +43,7 @@ contract TestLib_RLPReader { ...@@ -43,7 +43,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
bytes memory bytes memory
) )
...@@ -55,7 +55,7 @@ contract TestLib_RLPReader { ...@@ -55,7 +55,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
bytes32 bytes32
) )
...@@ -67,7 +67,7 @@ contract TestLib_RLPReader { ...@@ -67,7 +67,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
uint256 uint256
) )
...@@ -79,7 +79,7 @@ contract TestLib_RLPReader { ...@@ -79,7 +79,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
bool bool
) )
...@@ -91,7 +91,7 @@ contract TestLib_RLPReader { ...@@ -91,7 +91,7 @@ contract TestLib_RLPReader {
bytes memory _in bytes memory _in
) )
public public
view pure
returns ( returns (
address address
) )
......
...@@ -16,7 +16,7 @@ contract TestLib_MerkleTrie { ...@@ -16,7 +16,7 @@ contract TestLib_MerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool bool
) )
...@@ -35,7 +35,7 @@ contract TestLib_MerkleTrie { ...@@ -35,7 +35,7 @@ contract TestLib_MerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool bool
) )
...@@ -54,7 +54,7 @@ contract TestLib_MerkleTrie { ...@@ -54,7 +54,7 @@ contract TestLib_MerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bytes32 bytes32
) )
...@@ -73,7 +73,7 @@ contract TestLib_MerkleTrie { ...@@ -73,7 +73,7 @@ contract TestLib_MerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool, bool,
bytes memory bytes memory
...@@ -91,7 +91,7 @@ contract TestLib_MerkleTrie { ...@@ -91,7 +91,7 @@ contract TestLib_MerkleTrie {
bytes memory _value bytes memory _value
) )
public public
view pure
returns ( returns (
bytes32 bytes32
) )
......
...@@ -17,7 +17,7 @@ contract TestLib_SecureMerkleTrie { ...@@ -17,7 +17,7 @@ contract TestLib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool bool
) )
...@@ -36,7 +36,7 @@ contract TestLib_SecureMerkleTrie { ...@@ -36,7 +36,7 @@ contract TestLib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool bool
) )
...@@ -55,7 +55,7 @@ contract TestLib_SecureMerkleTrie { ...@@ -55,7 +55,7 @@ contract TestLib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bytes32 bytes32
) )
...@@ -74,7 +74,7 @@ contract TestLib_SecureMerkleTrie { ...@@ -74,7 +74,7 @@ contract TestLib_SecureMerkleTrie {
bytes32 _root bytes32 _root
) )
public public
view pure
returns ( returns (
bool, bool,
bytes memory bytes memory
...@@ -92,7 +92,7 @@ contract TestLib_SecureMerkleTrie { ...@@ -92,7 +92,7 @@ contract TestLib_SecureMerkleTrie {
bytes memory _value bytes memory _value
) )
public public
view pure
returns ( returns (
bytes32 bytes32
) )
......
...@@ -88,7 +88,7 @@ contract TestLib_EthUtils { ...@@ -88,7 +88,7 @@ contract TestLib_EthUtils {
uint256 _nonce uint256 _nonce
) )
public public
view pure
returns ( returns (
address _address address _address
) )
...@@ -105,7 +105,7 @@ contract TestLib_EthUtils { ...@@ -105,7 +105,7 @@ contract TestLib_EthUtils {
bytes32 _salt bytes32 _salt
) )
public public
view pure
returns (address _address) returns (address _address)
{ {
return Lib_EthUtils.getAddressForCREATE2( return Lib_EthUtils.getAddressForCREATE2(
......
...@@ -17,9 +17,7 @@ contract TestLib_TimeboundRingBuffer { ...@@ -17,9 +17,7 @@ contract TestLib_TimeboundRingBuffer {
uint32 _startingSize, uint32 _startingSize,
uint32 _maxSizeIncrementAmount, uint32 _maxSizeIncrementAmount,
uint _timeout uint _timeout
) ) {
public
{
list.init(_startingSize, _maxSizeIncrementAmount, _timeout); list.init(_startingSize, _maxSizeIncrementAmount, _timeout);
} }
......
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
], ],
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "yarn run build:contracts && yarn run build:typescript && yarn run build:copy && yarn run build:dump", "build": "yarn run build:contracts && yarn run build:typescript && yarn run build:copy && yarn run build:dump && yarn run build:typechain",
"build:typescript": "tsc -p .", "build:typescript": "tsc -p tsconfig.prod.json",
"build:contracts": "buidler compile", "build:contracts": "buidler compile",
"build:dump": "ts-node \"bin/take-dump.ts\"", "build:dump": "ts-node \"bin/take-dump.ts\"",
"build:copy": "copyfiles -u 2 \"contracts/optimistic-ethereum/**/*.sol\" \"build/contracts\"", "build:copy": "copyfiles -u 2 \"contracts/optimistic-ethereum/**/*.sol\" \"build/contracts\"",
"build:typechain": "buidler typechain",
"test": "yarn run test:contracts", "test": "yarn run test:contracts",
"test:contracts": "buidler test --show-stack-traces", "test:contracts": "buidler test --show-stack-traces",
"lint": "yarn run lint:typescript", "lint": "yarn run lint:typescript",
...@@ -31,12 +32,14 @@ ...@@ -31,12 +32,14 @@
"@nomiclabs/buidler": "^1.4.4", "@nomiclabs/buidler": "^1.4.4",
"@nomiclabs/buidler-ethers": "^2.0.0", "@nomiclabs/buidler-ethers": "^2.0.0",
"@nomiclabs/buidler-waffle": "^2.0.0", "@nomiclabs/buidler-waffle": "^2.0.0",
"@typechain/ethers-v5": "1.0.0",
"@types/chai": "^4.2.12", "@types/chai": "^4.2.12",
"@types/lodash": "^4.14.161", "@types/lodash": "^4.14.161",
"@types/mocha": "^8.0.3", "@types/mocha": "^8.0.3",
"@types/node": "^14.6.0", "@types/node": "^14.6.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"buffer-xor": "^2.0.2", "buffer-xor": "^2.0.2",
"buidler-typechain": "^0.2.1",
"chai": "^4.2.0", "chai": "^4.2.0",
"copyfiles": "^2.3.0", "copyfiles": "^2.3.0",
"ethereum-waffle": "3.0.0", "ethereum-waffle": "3.0.0",
...@@ -50,11 +53,13 @@ ...@@ -50,11 +53,13 @@
"random-bytes-seed": "^1.0.3", "random-bytes-seed": "^1.0.3",
"rlp": "^2.2.6", "rlp": "^2.2.6",
"seedrandom": "^3.0.5", "seedrandom": "^3.0.5",
"ts-generator": "0.0.8",
"ts-node": "^9.0.0", "ts-node": "^9.0.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0", "tslint-config-prettier": "^1.18.0",
"tslint-no-focused-test": "^0.5.0", "tslint-no-focused-test": "^0.5.0",
"tslint-plugin-prettier": "^2.3.0", "tslint-plugin-prettier": "^2.3.0",
"typechain": "2.0.0",
"typescript": "^4.0.2" "typescript": "^4.0.2"
} }
} }
...@@ -6,7 +6,7 @@ import { keccak256 } from 'ethers/lib/utils' ...@@ -6,7 +6,7 @@ import { keccak256 } from 'ethers/lib/utils'
/* Internal Imports */ /* Internal Imports */
import { deploy, RollupDeployConfig } from './contract-deployment' import { deploy, RollupDeployConfig } from './contract-deployment'
import { fromHexString, toHexString, remove0x } from '../test/helpers/utils' import { fromHexString, toHexString, remove0x } from './utils'
import { getContractDefinition } from './contract-defs' import { getContractDefinition } from './contract-defs'
interface StorageDump { interface StorageDump {
......
export * from './buffer-utils'
export * from './byte-utils'
import { expect } from '../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { ContractFactory, Contract } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock'
import { NON_ZERO_ADDRESS } from '../../../helpers/constants'
const callPrecompileStatic = async (
Helper_PrecompileCaller: Contract,
precompile: Contract,
functionName: string,
functionParams?: any[]
): Promise<any> => {
return Helper_PrecompileCaller.callStatic[functionName](
precompile.address,
precompile.interface.encodeFunctionData(functionName, functionParams || [])
)
}
describe('OVM_L1MessageSender', () => {
let Mock__OVM_ExecutionManager: MockContract
before(async () => {
Mock__OVM_ExecutionManager = smockit(
await ethers.getContractFactory('OVM_ExecutionManager')
)
})
let Helper_PrecompileCaller: Contract
before(async () => {
Helper_PrecompileCaller = await (
await ethers.getContractFactory('Helper_PrecompileCaller')
).deploy()
Helper_PrecompileCaller.setTarget(Mock__OVM_ExecutionManager.address)
})
let Factory__OVM_L1MessageSender: ContractFactory
before(async () => {
Factory__OVM_L1MessageSender = await ethers.getContractFactory(
'OVM_L1MessageSender'
)
})
let OVM_L1MessageSender: Contract
beforeEach(async () => {
OVM_L1MessageSender = await Factory__OVM_L1MessageSender.deploy()
})
describe('getL1MessageSender', () => {
before(async () => {
Mock__OVM_ExecutionManager.smocked.ovmL1TXORIGIN.will.return.with(
NON_ZERO_ADDRESS
)
})
it('should return the L1 message sender', async () => {
expect(
await callPrecompileStatic(
Helper_PrecompileCaller,
OVM_L1MessageSender,
'getL1MessageSender'
)
).to.equal(NON_ZERO_ADDRESS)
})
})
})
import { expect } from '../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { ContractFactory, Contract } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock'
import { NON_ZERO_ADDRESS } from '../../../helpers/constants'
const ELEMENT_TEST_SIZES = [1, 2, 4, 8, 16]
const callPrecompile = async (
Helper_PrecompileCaller: Contract,
precompile: Contract,
functionName: string,
functionParams?: any[]
): Promise<any> => {
return Helper_PrecompileCaller.callPrecompile(
precompile.address,
precompile.interface.encodeFunctionData(functionName, functionParams || [])
)
}
describe('OVM_L2ToL1MessagePasser', () => {
let Mock__OVM_ExecutionManager: MockContract
before(async () => {
Mock__OVM_ExecutionManager = smockit(
await ethers.getContractFactory('OVM_ExecutionManager')
)
})
let Helper_PrecompileCaller: Contract
before(async () => {
Helper_PrecompileCaller = await (
await ethers.getContractFactory('Helper_PrecompileCaller')
).deploy()
Helper_PrecompileCaller.setTarget(Mock__OVM_ExecutionManager.address)
})
let Factory__OVM_L2ToL1MessagePasser: ContractFactory
before(async () => {
Factory__OVM_L2ToL1MessagePasser = await ethers.getContractFactory(
'OVM_L2ToL1MessagePasser'
)
})
let OVM_L2ToL1MessagePasser: Contract
beforeEach(async () => {
OVM_L2ToL1MessagePasser = await Factory__OVM_L2ToL1MessagePasser.deploy()
})
describe('passMessageToL1', () => {
before(async () => {
Mock__OVM_ExecutionManager.smocked.ovmCALLER.will.return.with(
NON_ZERO_ADDRESS
)
})
for (const size of ELEMENT_TEST_SIZES) {
it(`should be able to pass ${size} messages`, async () => {
for (let i = 0; i < size; i++) {
const message = '0x' + '12' + '34'.repeat(i)
await expect(
callPrecompile(
Helper_PrecompileCaller,
OVM_L2ToL1MessagePasser,
'passMessageToL1',
[message]
)
)
.to.emit(OVM_L2ToL1MessagePasser, 'L2ToL1Message')
.withArgs(i, NON_ZERO_ADDRESS, message)
}
})
}
})
})
...@@ -303,13 +303,16 @@ describe('OVM_StateTransitioner', () => { ...@@ -303,13 +303,16 @@ describe('OVM_StateTransitioner', () => {
let ovmContractAddress = NON_ZERO_ADDRESS let ovmContractAddress = NON_ZERO_ADDRESS
let account: any let account: any
beforeEach(() => { beforeEach(() => {
Mock__OVM_StateManager.smocked.hasAccount.will.return.with(false)
account = { account = {
nonce: 0, nonce: 0,
balance: 0, balance: 0,
storageRoot: NULL_BYTES32, storageRoot: NULL_BYTES32,
codeHash: NULL_BYTES32, codeHash: NULL_BYTES32,
ethAddress: ZERO_ADDRESS,
isFresh: false,
} }
Mock__OVM_StateManager.smocked.hasAccount.will.return.with(false)
Mock__OVM_StateManager.smocked.getAccount.will.return.with(account)
}) })
describe('when the account was not changed or has already been committed', () => { describe('when the account was not changed or has already been committed', () => {
...@@ -319,11 +322,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -319,11 +322,7 @@ describe('OVM_StateTransitioner', () => {
it('should revert', async () => { it('should revert', async () => {
await expect( await expect(
OVM_StateTransitioner.commitContractState( OVM_StateTransitioner.commitContractState(ovmContractAddress, '0x')
ovmContractAddress,
account,
'0x'
)
).to.be.revertedWith( ).to.be.revertedWith(
'Account was not changed or has already been committed.' 'Account was not changed or has already been committed.'
) )
...@@ -365,11 +364,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -365,11 +364,7 @@ describe('OVM_StateTransitioner', () => {
it('should update the post state root', async () => { it('should update the post state root', async () => {
await expect( await expect(
OVM_StateTransitioner.commitContractState( OVM_StateTransitioner.commitContractState(ovmContractAddress, proof)
ovmContractAddress,
account,
proof
)
).to.not.be.reverted ).to.not.be.reverted
expect(await OVM_StateTransitioner.getPostStateRoot()).to.equal( expect(await OVM_StateTransitioner.getPostStateRoot()).to.equal(
...@@ -405,6 +400,8 @@ describe('OVM_StateTransitioner', () => { ...@@ -405,6 +400,8 @@ describe('OVM_StateTransitioner', () => {
ethAddress: ZERO_ADDRESS, ethAddress: ZERO_ADDRESS,
isFresh: false, isFresh: false,
}) })
Mock__OVM_StateManager.smocked.getContractStorage.will.return.with(val)
}) })
describe('when the slot was not changed or was already committed', () => { describe('when the slot was not changed or was already committed', () => {
...@@ -419,7 +416,6 @@ describe('OVM_StateTransitioner', () => { ...@@ -419,7 +416,6 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner.commitStorageSlot( OVM_StateTransitioner.commitStorageSlot(
ovmContractAddress, ovmContractAddress,
key, key,
val,
'0x', '0x',
'0x' '0x'
) )
...@@ -497,7 +493,6 @@ describe('OVM_StateTransitioner', () => { ...@@ -497,7 +493,6 @@ describe('OVM_StateTransitioner', () => {
OVM_StateTransitioner.commitStorageSlot( OVM_StateTransitioner.commitStorageSlot(
ovmContractAddress, ovmContractAddress,
key, key,
newVal,
accountTrieProof, accountTrieProof,
storageTrieProof storageTrieProof
) )
......
export * from './buffer-utils' export * from '../../../src/utils'
export * from './byte-utils'
export * from './eth-time' export * from './eth-time'
...@@ -20,11 +20,13 @@ ...@@ -20,11 +20,13 @@
"node_modules/@types" "node_modules/@types"
] ]
}, },
"include": ["src/**/*.ts", "artifacts/*.json"], "include": [
"files": [ "src/**/*.ts",
"artifacts/*.json",
"./buidler.config.ts", "./buidler.config.ts",
"./buidler-env.d.ts", "./buidler-env.d.ts",
"./node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts", "./node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts",
"./node_modules/@nomiclabs/buidler-waffle/src/type-extensions.d.ts" "./node_modules/@nomiclabs/buidler-waffle/src/type-extensions.d.ts",
"./node_modules/buidler-typechain/src/type-extensions.d.ts"
] ]
} }
\ No newline at end of file
{
"extends": "./tsconfig",
"exclude": [
"./buidler.config.ts",
"./buidler-env.d.ts",
"./node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts",
"./node_modules/@nomiclabs/buidler-waffle/src/type-extensions.d.ts",
"./node_modules/buidler-typechain/src/type-extensions.d.ts"
]
}
This diff is collapsed.
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