Skip to content

Commit

Permalink
Added fix for error in StateTransitioner (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
smartcontracts authored Oct 16, 2020
1 parent e7196c1 commit a4340e5
Show file tree
Hide file tree
Showing 36 changed files with 416 additions and 105 deletions.
5 changes: 5 additions & 0 deletions packages/contracts/buidler.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

usePlugin('@nomiclabs/buidler-ethers')
usePlugin('@nomiclabs/buidler-waffle')
usePlugin('buidler-typechain')

import '@eth-optimism/smock/build/src/buidler-plugins/compiler-storage-layout'

Expand All @@ -24,6 +25,10 @@ const config: BuidlerConfig = {
version: '0.7.0',
optimizer: { enabled: true, runs: 200 },
},
typechain: {
outDir: 'build/types',
target: 'ethers-v5',
},
}

export default config
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof
)
internal
view
returns (
bool
)
Expand All @@ -162,6 +163,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof
)
internal
view
returns (
bool
)
Expand All @@ -187,6 +189,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
L2MessageInclusionProof memory _proof
)
internal
pure
returns (
bool
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
"Must append more than zero transactions."
);

(uint40 totalElements, uint32 nextQueueIndex) = _getLatestBatchContext();
(, uint32 nextQueueIndex) = _getLatestBatchContext();

bytes32[] memory leaves = new bytes32[](_numQueuedTransactions);
for (uint i = 0; i < _numQueuedTransactions; i++) {
Expand Down Expand Up @@ -424,7 +424,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
uint32 _nextQueueIndex
)
internal
view
pure
returns (
bytes28 _context
)
Expand Down Expand Up @@ -512,6 +512,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, OVM_Ba
uint32 _nextQueueIndex
)
internal
view
{
if (queue.getLength() == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
bytes memory _data
)
internal
view
returns (
bytes memory _revertdata
)
Expand Down Expand Up @@ -1362,6 +1363,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
bytes memory _revertdata
)
internal
pure
returns (
RevertFlag _flag,
uint256 _nuisanceGasLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract OVM_SafetyChecker is iOVM_SafetyChecker {
)
override
external
view
pure
returns (bool)
{
// autogenerated by gen_safety_checker_constants.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract OVM_L1MessageSender is iOVM_L1MessageSender {
function getL1MessageSender()
override
public
view
returns (
address _l1MessageSender
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,10 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
/**
* Allows a user to commit the final state of a contract.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _account Claimed account state.
* @param _stateTrieWitness Proof of the account state.
*/
function commitContractState(
address _ovmContractAddress,
Lib_OVMCodec.EVMAccount memory _account,
bytes memory _stateTrieWitness
)
override
Expand All @@ -349,9 +347,13 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
"Account was not changed or has already been committed."
);

Lib_OVMCodec.Account memory account = ovmStateManager.getAccount(_ovmContractAddress);

postStateRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_ovmContractAddress),
Lib_OVMCodec.encodeEVMAccount(_account),
Lib_OVMCodec.encodeEVMAccount(
Lib_OVMCodec.toEVMAccount(account)
),
_stateTrieWitness,
postStateRoot
);
Expand All @@ -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.
* @param _ovmContractAddress Address of the contract on the OVM.
* @param _key Claimed account slot key.
* @param _value Claimed account slot value.
* @param _stateTrieWitness Proof of the account state.
* @param _storageTrieWitness Proof of the storage slot.
*/
function commitStorageSlot(
address _ovmContractAddress,
bytes32 _key,
bytes32 _value,
bytes memory _stateTrieWitness,
bytes memory _storageTrieWitness
)
Expand All @@ -381,23 +381,26 @@ contract OVM_StateTransitioner is iOVM_StateTransitioner, Lib_AddressResolver {
"Storage slot was not changed or has already been committed."
);

Lib_OVMCodec.EVMAccount memory account = Lib_OVMCodec.toEVMAccount(
ovmStateManager.getAccount(_ovmContractAddress)
);
Lib_OVMCodec.Account memory account = ovmStateManager.getAccount(_ovmContractAddress);
bytes32 value = ovmStateManager.getContractStorage(_ovmContractAddress, _key);

account.storageRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_key),
abi.encodePacked(_value),
abi.encodePacked(value),
_storageTrieWitness,
account.storageRoot
);

postStateRoot = Lib_SecureMerkleTrie.update(
abi.encodePacked(_ovmContractAddress),
Lib_OVMCodec.encodeEVMAccount(account),
Lib_OVMCodec.encodeEVMAccount(
Lib_OVMCodec.toEVMAccount(account)
),
_stateTrieWitness,
postStateRoot
);

ovmStateManager.putAccount(_ovmContractAddress, account);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ interface iOVM_StateTransitioner {

function commitContractState(
address _ovmContractAddress,
Lib_OVMCodec.EVMAccount calldata _account,
bytes calldata _stateTrieWitness
) external;

function commitStorageSlot(
address _ovmContractAddress,
bytes32 _key,
bytes32 _value,
bytes calldata _stateTrieWitness,
bytes calldata _storageTrieWitness
) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ contract Lib_AddressResolver {
*/
constructor(
address _libAddressManager
)
public
{
) {
libAddressManager = Lib_AddressManager(_libAddressManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ abstract contract Ownable {
* Constructor *
***************/

constructor()
internal
{
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), owner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ library Lib_RLPReader {
{
(
uint256 listOffset,
uint256 listLength,
,
RLPItemType itemType
) = _decodeLength(_in);

Expand Down
Loading

0 comments on commit a4340e5

Please sign in to comment.