Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
lower nonce size
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-chain committed Mar 15, 2021
1 parent 58c4c8c commit 3784afc
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
override
public
returns (
uint256 _nonce
uint64 _nonce
)
{
return _getAccountNonce(ovmADDRESS());
Expand All @@ -464,7 +464,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
* @param _nonce New nonce for the current contract.
*/
function ovmSETNONCE(
uint256 _nonce
uint64 _nonce
)
override
public
Expand Down Expand Up @@ -1161,7 +1161,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
*/
function _setAccountNonce(
address _address,
uint256 _nonce
uint64 _nonce
)
internal
{
Expand All @@ -1179,7 +1179,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
)
internal
returns (
uint256 _nonce
uint64 _nonce
)
{
_checkAccountLoad(_address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ contract OVM_StateManager is iOVM_StateManager {
*/
function setAccountNonce(
address _address,
uint256 _nonce
uint64 _nonce
)
override
public
Expand All @@ -228,7 +228,7 @@ contract OVM_StateManager is iOVM_StateManager {
public
view
returns (
uint256
uint64
)
{
return accounts[_address].nonce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ interface iOVM_ExecutionManager {
* Account Abstraction Opcodes *
******************************/

function ovmGETNONCE() external returns (uint256 _nonce);
function ovmSETNONCE(uint256 _nonce) external;
function ovmGETNONCE() external returns (uint64 _nonce);
function ovmSETNONCE(uint64 _nonce) external;
function ovmCREATEEOA(bytes32 _messageHash, uint8 _v, bytes32 _r, bytes32 _s) external;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ interface iOVM_StateManager {
function getAccount(address _address) external view returns (Lib_OVMCodec.Account memory _account);
function hasAccount(address _address) external view returns (bool _exists);
function hasEmptyAccount(address _address) external view returns (bool _exists);
function setAccountNonce(address _address, uint256 _nonce) external;
function getAccountNonce(address _address) external view returns (uint256 _nonce);
function setAccountNonce(address _address, uint64 _nonce) external;
function getAccountNonce(address _address) external view returns (uint64 _nonce);
function getAccountEthAddress(address _address) external view returns (address _ethAddress);
function getAccountStorageRoot(address _address) external view returns (bytes32 _storageRoot);
function initPendingAccount(address _address) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library Lib_EIP155Tx {
// Struct representing an EIP155 transaction. See EIP link above for more information.
struct EIP155Tx {
// These fields correspond to the actual RLP-encoded fields specified by EIP155.
uint256 nonce;
uint64 nonce;
uint256 gasPrice;
uint256 gasLimit;
address to;
Expand Down Expand Up @@ -91,7 +91,7 @@ library Lib_EIP155Tx {
bool isCreate = Lib_RLPReader.readBytes(decoded[3]).length == 0;

return EIP155Tx({
nonce: Lib_RLPReader.readUint256(decoded[0]),
nonce: Lib_RLPReader.readUint64(decoded[0]),
gasPrice: Lib_RLPReader.readUint256(decoded[1]),
gasLimit: Lib_RLPReader.readUint256(decoded[2]),
to: Lib_RLPReader.readAddress(decoded[3]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library Lib_OVMCodec {
***********/

struct Account {
uint256 nonce;
uint64 nonce;
uint256 balance;
bytes32 storageRoot;
bytes32 codeHash;
Expand All @@ -38,7 +38,7 @@ library Lib_OVMCodec {
}

struct EVMAccount {
uint256 nonce;
uint64 nonce;
uint256 balance;
bytes32 storageRoot;
bytes32 codeHash;
Expand Down Expand Up @@ -170,7 +170,7 @@ library Lib_OVMCodec {
// index-by-index circumvents this issue.
raw[0] = Lib_RLPWriter.writeBytes(
Lib_Bytes32Utils.removeLeadingZeros(
bytes32(_account.nonce)
bytes32(uint256(_account.nonce))
)
);
raw[1] = Lib_RLPWriter.writeBytes(
Expand Down Expand Up @@ -201,7 +201,7 @@ library Lib_OVMCodec {
Lib_RLPReader.RLPItem[] memory accountState = Lib_RLPReader.readList(_encoded);

return EVMAccount({
nonce: Lib_RLPReader.readUint256(accountState[0]),
nonce: uint64(Lib_RLPReader.readUint256(accountState[0])),
balance: Lib_RLPReader.readUint256(accountState[1]),
storageRoot: Lib_RLPReader.readBytes32(accountState[2]),
codeHash: Lib_RLPReader.readBytes32(accountState[3])
Expand Down
22 changes: 22 additions & 0 deletions contracts/optimistic-ethereum/libraries/rlp/Lib_RLPReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,28 @@ library Lib_RLPReader {
);
}

/**
* Reads an RLP Uint64 value into a uint64.
* @param _in RLP uint64 value.
* @return Decoded uint64.
*/
function readUint64(
RLPItem memory _in
)
internal
pure
returns (
uint64
)
{
require(
_in.length <= 9,
"Invalid RLP uint64 value."
);

return uint64(readUint256(_in));
}

/**
* Reads the raw bytes of an RLP item.
* @param _in RLP item to read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ library Lib_SafeExecutionManagerWrapper {
function safeGETNONCE()
internal
returns (
uint256 _nonce
uint64 _nonce
)
{
bytes memory returndata = _safeExecutionManagerInteraction(
Expand All @@ -204,21 +204,21 @@ library Lib_SafeExecutionManagerWrapper {
)
);

return abi.decode(returndata, (uint256));
return abi.decode(returndata, (uint64));
}

/**
* Performs a safe ovmSETNONCE call.
* @param _nonce New account nonce.
*/
function safeSETNONCE(
uint256 _nonce
uint64 _nonce
)
internal
{
_safeExecutionManagerInteraction(
abi.encodeWithSignature(
"ovmSETNONCE(uint256)",
"ovmSETNONCE(uint64)",
_nonce
)
);
Expand Down

0 comments on commit 3784afc

Please sign in to comment.