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

Commit 3784afc

Browse files
committed
lower nonce size
1 parent 58c4c8c commit 3784afc

File tree

8 files changed

+42
-20
lines changed

8 files changed

+42
-20
lines changed

contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
453453
override
454454
public
455455
returns (
456-
uint256 _nonce
456+
uint64 _nonce
457457
)
458458
{
459459
return _getAccountNonce(ovmADDRESS());
@@ -464,7 +464,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
464464
* @param _nonce New nonce for the current contract.
465465
*/
466466
function ovmSETNONCE(
467-
uint256 _nonce
467+
uint64 _nonce
468468
)
469469
override
470470
public
@@ -1161,7 +1161,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
11611161
*/
11621162
function _setAccountNonce(
11631163
address _address,
1164-
uint256 _nonce
1164+
uint64 _nonce
11651165
)
11661166
internal
11671167
{
@@ -1179,7 +1179,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
11791179
)
11801180
internal
11811181
returns (
1182-
uint256 _nonce
1182+
uint64 _nonce
11831183
)
11841184
{
11851185
_checkAccountLoad(_address);

contracts/optimistic-ethereum/OVM/execution/OVM_StateManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ contract OVM_StateManager is iOVM_StateManager {
207207
*/
208208
function setAccountNonce(
209209
address _address,
210-
uint256 _nonce
210+
uint64 _nonce
211211
)
212212
override
213213
public
@@ -228,7 +228,7 @@ contract OVM_StateManager is iOVM_StateManager {
228228
public
229229
view
230230
returns (
231-
uint256
231+
uint64
232232
)
233233
{
234234
return accounts[_address].nonce;

contracts/optimistic-ethereum/iOVM/execution/iOVM_ExecutionManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ interface iOVM_ExecutionManager {
117117
* Account Abstraction Opcodes *
118118
******************************/
119119

120-
function ovmGETNONCE() external returns (uint256 _nonce);
121-
function ovmSETNONCE(uint256 _nonce) external;
120+
function ovmGETNONCE() external returns (uint64 _nonce);
121+
function ovmSETNONCE(uint64 _nonce) external;
122122
function ovmCREATEEOA(bytes32 _messageHash, uint8 _v, bytes32 _r, bytes32 _s) external;
123123

124124

contracts/optimistic-ethereum/iOVM/execution/iOVM_StateManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ interface iOVM_StateManager {
4545
function getAccount(address _address) external view returns (Lib_OVMCodec.Account memory _account);
4646
function hasAccount(address _address) external view returns (bool _exists);
4747
function hasEmptyAccount(address _address) external view returns (bool _exists);
48-
function setAccountNonce(address _address, uint256 _nonce) external;
49-
function getAccountNonce(address _address) external view returns (uint256 _nonce);
48+
function setAccountNonce(address _address, uint64 _nonce) external;
49+
function getAccountNonce(address _address) external view returns (uint64 _nonce);
5050
function getAccountEthAddress(address _address) external view returns (address _ethAddress);
5151
function getAccountStorageRoot(address _address) external view returns (bytes32 _storageRoot);
5252
function initPendingAccount(address _address) external;

contracts/optimistic-ethereum/libraries/codec/Lib_EIP155Tx.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library Lib_EIP155Tx {
2020
// Struct representing an EIP155 transaction. See EIP link above for more information.
2121
struct EIP155Tx {
2222
// These fields correspond to the actual RLP-encoded fields specified by EIP155.
23-
uint256 nonce;
23+
uint64 nonce;
2424
uint256 gasPrice;
2525
uint256 gasLimit;
2626
address to;
@@ -91,7 +91,7 @@ library Lib_EIP155Tx {
9191
bool isCreate = Lib_RLPReader.readBytes(decoded[3]).length == 0;
9292

9393
return EIP155Tx({
94-
nonce: Lib_RLPReader.readUint256(decoded[0]),
94+
nonce: Lib_RLPReader.readUint64(decoded[0]),
9595
gasPrice: Lib_RLPReader.readUint256(decoded[1]),
9696
gasLimit: Lib_RLPReader.readUint256(decoded[2]),
9797
to: Lib_RLPReader.readAddress(decoded[3]),

contracts/optimistic-ethereum/libraries/codec/Lib_OVMCodec.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library Lib_OVMCodec {
2929
***********/
3030

3131
struct Account {
32-
uint256 nonce;
32+
uint64 nonce;
3333
uint256 balance;
3434
bytes32 storageRoot;
3535
bytes32 codeHash;
@@ -38,7 +38,7 @@ library Lib_OVMCodec {
3838
}
3939

4040
struct EVMAccount {
41-
uint256 nonce;
41+
uint64 nonce;
4242
uint256 balance;
4343
bytes32 storageRoot;
4444
bytes32 codeHash;
@@ -170,7 +170,7 @@ library Lib_OVMCodec {
170170
// index-by-index circumvents this issue.
171171
raw[0] = Lib_RLPWriter.writeBytes(
172172
Lib_Bytes32Utils.removeLeadingZeros(
173-
bytes32(_account.nonce)
173+
bytes32(uint256(_account.nonce))
174174
)
175175
);
176176
raw[1] = Lib_RLPWriter.writeBytes(
@@ -201,7 +201,7 @@ library Lib_OVMCodec {
201201
Lib_RLPReader.RLPItem[] memory accountState = Lib_RLPReader.readList(_encoded);
202202

203203
return EVMAccount({
204-
nonce: Lib_RLPReader.readUint256(accountState[0]),
204+
nonce: uint64(Lib_RLPReader.readUint256(accountState[0])),
205205
balance: Lib_RLPReader.readUint256(accountState[1]),
206206
storageRoot: Lib_RLPReader.readBytes32(accountState[2]),
207207
codeHash: Lib_RLPReader.readBytes32(accountState[3])

contracts/optimistic-ethereum/libraries/rlp/Lib_RLPReader.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,28 @@ library Lib_RLPReader {
420420
);
421421
}
422422

423+
/**
424+
* Reads an RLP Uint64 value into a uint64.
425+
* @param _in RLP uint64 value.
426+
* @return Decoded uint64.
427+
*/
428+
function readUint64(
429+
RLPItem memory _in
430+
)
431+
internal
432+
pure
433+
returns (
434+
uint64
435+
)
436+
{
437+
require(
438+
_in.length <= 9,
439+
"Invalid RLP uint64 value."
440+
);
441+
442+
return uint64(readUint256(_in));
443+
}
444+
423445
/**
424446
* Reads the raw bytes of an RLP item.
425447
* @param _in RLP item to read.

contracts/optimistic-ethereum/libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ library Lib_SafeExecutionManagerWrapper {
195195
function safeGETNONCE()
196196
internal
197197
returns (
198-
uint256 _nonce
198+
uint64 _nonce
199199
)
200200
{
201201
bytes memory returndata = _safeExecutionManagerInteraction(
@@ -204,21 +204,21 @@ library Lib_SafeExecutionManagerWrapper {
204204
)
205205
);
206206

207-
return abi.decode(returndata, (uint256));
207+
return abi.decode(returndata, (uint64));
208208
}
209209

210210
/**
211211
* Performs a safe ovmSETNONCE call.
212212
* @param _nonce New account nonce.
213213
*/
214214
function safeSETNONCE(
215-
uint256 _nonce
215+
uint64 _nonce
216216
)
217217
internal
218218
{
219219
_safeExecutionManagerInteraction(
220220
abi.encodeWithSignature(
221-
"ovmSETNONCE(uint256)",
221+
"ovmSETNONCE(uint64)",
222222
_nonce
223223
)
224224
);

0 commit comments

Comments
 (0)