Skip to content

Commit 0146bf7

Browse files
drortiroshshahafn
andauthored
AA-293 N-05 using uint instead of uint256 (eth-infinitism#417)
Co-authored-by: shahafn <shahaflol@gmail.com>
1 parent 075c6b9 commit 0146bf7

18 files changed

+58
-58
lines changed

.solhint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compiler-version": ["error",">=0.7.5"],
55
"func-visibility": ["off",{"ignoreConstructors":true}],
66
"custom-errors": ["off"],
7-
"explicit-types": ["off"],
7+
"explicit-types": ["warn", "explicit"],
88
"no-global-import": ["off"],
99
"immutable-vars-naming": ["off"],
1010
"mark-callable-contracts": ["off"]

contracts/core/EntryPoint.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
3737

3838
//compensate for innerHandleOps' emit message and deposit refund.
3939
// allow some slack for future gas price changes.
40-
uint private constant INNER_GAS_OVERHEAD = 10000;
40+
uint256 private constant INNER_GAS_OVERHEAD = 10000;
4141

4242
// Marker for inner call revert on out of gas
4343
bytes32 private constant INNER_OUT_OF_GAS = hex"deaddead";
@@ -85,7 +85,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard,
8585
bytes memory context = getMemoryBytesFromOffset(opInfo.contextOffset);
8686
bool success;
8787
{
88-
uint saveFreePtr;
88+
uint256 saveFreePtr;
8989
assembly ("memory-safe") {
9090
saveFreePtr := mload(0x40)
9191
}

contracts/core/EntryPointSimulations.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
180180
unchecked{
181181
// silly code, to waste some gas to make sure depositTo is always little more
182182
// expensive than on-chain call
183-
uint x = 1;
183+
uint256 x = 1;
184184
while (x < 5) {
185185
x++;
186186
}

contracts/interfaces/IEntryPoint.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ interface IEntryPoint is IStakeManager, INonceManager {
105105
/**
106106
* A custom revert error of handleOps, to report a revert by account or paymaster.
107107
* @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero).
108-
* @param reason - Revert reason. see FailedOp(uint,string), above
108+
* @param reason - Revert reason. see FailedOp(uint256,string), above
109109
* @param inner - data from inner cought revert reason
110110
* @dev note that inner is truncated to 2048 bytes
111111
*/

contracts/samples/LegacyTokenPaymaster.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ contract LegacyTokenPaymaster is BasePaymaster, ERC20 {
3232
_mint(address(this), 1);
3333

3434
//owner is allowed to withdraw tokens from the paymaster's balance
35-
_approve(address(this), msg.sender, type(uint).max);
35+
_approve(address(this), msg.sender, type(uint256).max);
3636
}
3737

3838

@@ -55,7 +55,7 @@ contract LegacyTokenPaymaster is BasePaymaster, ERC20 {
5555
_approve(address(this), owner(), 0);
5656
super.transferOwnership(newOwner);
5757
// new owner is allowed to withdraw tokens from the paymaster's balance
58-
_approve(address(this), newOwner, type(uint).max);
58+
_approve(address(this), newOwner, type(uint256).max);
5959
}
6060

6161
//Note: this method assumes a fixed ratio of token-to-eth. subclass should override to supply oracle
@@ -102,7 +102,7 @@ contract LegacyTokenPaymaster is BasePaymaster, ERC20 {
102102
* the user's TX , back to the state it was before the transaction started (before the validatePaymasterUserOp),
103103
* and the transaction should succeed there.
104104
*/
105-
function _postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost, uint actualUserOpFeePerGas) internal override {
105+
function _postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas) internal override {
106106
//we don't really care about the mode, we just pay the gas with the user's tokens.
107107
(mode);
108108
address sender = abi.decode(context, (address));

contracts/samples/SimpleAccountFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract SimpleAccountFactory {
2727
*/
2828
function createAccount(address owner,uint256 salt) public returns (SimpleAccount ret) {
2929
address addr = getAddress(owner, salt);
30-
uint codeSize = addr.code.length;
30+
uint256 codeSize = addr.code.length;
3131
if (codeSize > 0) {
3232
return SimpleAccount(payable(addr));
3333
}

contracts/samples/TokenPaymaster.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
152152
/// @param actualUserOpFeePerGas - the gas price this UserOp pays. This value is based on the UserOp's maxFeePerGas
153153
// and maxPriorityFee (and basefee)
154154
// It is not the same as tx.gasprice, which is what the bundler pays.
155-
function _postOp(PostOpMode, bytes calldata context, uint256 actualGasCost, uint actualUserOpFeePerGas) internal override {
155+
function _postOp(PostOpMode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas) internal override {
156156
unchecked {
157157
uint256 priceMarkup = tokenPaymasterConfig.priceMarkup;
158158
(

contracts/samples/bls/BLSAccountFactory.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ contract BLSAccountFactory {
3131
function createAccount(uint256 salt, uint256[4] calldata aPublicKey) public returns (BLSAccount) {
3232

3333
// the BLSSignatureAggregator depends on the public-key being the last 4 uint256 of msg.data.
34-
uint slot;
34+
uint256 slot;
3535
assembly {slot := aPublicKey}
3636
require(slot == msg.data.length - 128, "wrong pubkey offset");
3737

3838
address addr = getAddress(salt, aPublicKey);
39-
uint codeSize = addr.code.length;
39+
uint256 codeSize = addr.code.length;
4040
if (codeSize > 0) {
4141
return BLSAccount(payable(addr));
4242
}

contracts/samples/bls/BLSHelper.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ pragma solidity ^0.8.23;
66
library BLSHelper {
77

88
struct XY {
9-
uint x;
10-
uint y;
9+
uint256 x;
10+
uint256 y;
1111
}
1212
/**
1313
* sum all the points in the array
@@ -17,11 +17,11 @@ library BLSHelper {
1717
* @return ret the sum of all points
1818
*/
1919
function sum(XY[] memory points, uint256 _pp) internal pure returns (XY memory ret){
20-
uint x = points[0].x;
21-
uint y = points[0].y;
22-
uint z = 1;
20+
uint256 x = points[0].x;
21+
uint256 y = points[0].y;
22+
uint256 z = 1;
2323

24-
for (uint i = 1; i < points.length; i++) {
24+
for (uint256 i = 1; i < points.length; i++) {
2525
(x, y, z) = jacAdd(x, y, z, points[i].x, points[i].y, 1, _pp);
2626
}
2727
(x, y) = toAffine(x, y, z, _pp);
@@ -54,7 +54,7 @@ library BLSHelper {
5454
return (_x1, _y1, _z1);
5555

5656
// We follow the equations described in https://pdfs.semanticscholar.org/5c64/29952e08025a9649c2b0ba32518e9a7fb5c2.pdf Section 5
57-
uint[4] memory zs;
57+
uint256[4] memory zs;
5858
// z1^2, z1^3, z2^2, z2^3
5959
zs[0] = mulmod(_z1, _z1, _pp);
6060
zs[1] = mulmod(_z1, zs[0], _pp);
@@ -72,7 +72,7 @@ library BLSHelper {
7272
// In case of zs[0] == zs[2] && zs[1] == zs[3], double function should be used
7373
require(zs[0] != zs[2] || zs[1] != zs[3], "Use jacDouble function instead");
7474

75-
uint[4] memory hr;
75+
uint256[4] memory hr;
7676
//h
7777
hr[0] = addmod(zs[2], _pp - zs[0], _pp);
7878
//r
@@ -160,9 +160,9 @@ library BLSHelper {
160160
uint256 z = mulmod(_z, _z, _pp); //z1^2
161161

162162
// s
163-
uint s = mulmod(4, mulmod(_x, y, _pp), _pp);
163+
uint256 s = mulmod(4, mulmod(_x, y, _pp), _pp);
164164
// m
165-
uint m = addmod(mulmod(3, x, _pp), mulmod(_aa, mulmod(z, z, _pp), _pp), _pp);
165+
uint256 m = addmod(mulmod(3, x, _pp), mulmod(_aa, mulmod(z, z, _pp), _pp), _pp);
166166

167167
// x, y, z at this point will be reassigned and rather represent qx, qy, qz from the paper
168168
// This allows to reduce the gas cost and stack footprint of the algorithm
@@ -193,9 +193,9 @@ library BLSHelper {
193193
uint256 _pp)
194194
internal pure returns (uint256, uint256)
195195
{
196-
uint x = 0;
197-
uint y = 0;
198-
uint z = 0;
196+
uint256 x = 0;
197+
uint256 y = 0;
198+
uint256 z = 0;
199199

200200
// Double if x1==x2 else add
201201
if (_x1 == _x2) {

contracts/samples/bls/BLSSignatureAggregator.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ contract BLSSignatureAggregator is IAggregator {
4545
* return the trailing 4 words of input data
4646
*/
4747
function getTrailingPublicKey(bytes memory data) public pure returns (uint256[4] memory publicKey) {
48-
uint len = data.length;
48+
uint256 len = data.length;
4949
require(len > 32 * 4, "data too short for sig");
5050

5151
/* solhint-disable-next-line no-inline-assembly */
@@ -65,7 +65,7 @@ contract BLSSignatureAggregator is IAggregator {
6565
require(signature.length == 64, "BLS: invalid signature");
6666
(uint256[2] memory blsSignature) = abi.decode(signature, (uint256[2]));
6767

68-
uint userOpsLen = userOps.length;
68+
uint256 userOpsLen = userOps.length;
6969
uint256[4][] memory blsPublicKeys = new uint256[4][](userOpsLen);
7070
uint256[2][] memory messages = new uint256[2][](userOpsLen);
7171
for (uint256 i = 0; i < userOpsLen; i++) {
@@ -152,7 +152,7 @@ contract BLSSignatureAggregator is IAggregator {
152152
*/
153153
function aggregateSignatures(PackedUserOperation[] calldata userOps) external pure returns (bytes memory aggregatedSignature) {
154154
BLSHelper.XY[] memory points = new BLSHelper.XY[](userOps.length);
155-
for (uint i = 0; i < points.length; i++) {
155+
for (uint256 i = 0; i < points.length; i++) {
156156
(uint256 x, uint256 y) = abi.decode(userOps[i].signature, (uint256, uint256));
157157
points[i] = BLSHelper.XY(x, y);
158158
}

0 commit comments

Comments
 (0)