Skip to content

Commit

Permalink
AA-138 N-07 rename vars and internal methods (#221)
Browse files Browse the repository at this point in the history
* N-07 rename vars and internal methods
  • Loading branch information
drortirosh committed Feb 9, 2023
1 parent 80d5c89 commit 7bd9909
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions contracts/core/BaseAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract contract BaseAccount is IAccount {
using UserOperationLib for UserOperation;

//return value in case of signature failure, with no time-range.
// equivalent to packSigTimeRange(true,0,0);
// equivalent to _packSigTimeRange(true,0,0);
uint256 constant internal SIG_VALIDATION_FAILED = 1;

/**
Expand All @@ -26,7 +26,7 @@ abstract contract BaseAccount is IAccount {
* @param validUntil last timestamp this UserOperation is valid (or zero for infinite)
* @param validAfter first timestamp this UserOperation is valid
*/
function packSigTimeRange(bool sigFailed, uint64 validUntil, uint64 validAfter) internal pure returns (uint256) {
function _packSigTimeRange(bool sigFailed, uint64 validUntil, uint64 validAfter) internal pure returns (uint256) {
return uint256(sigFailed ? 1 : 0) | (uint256(validUntil) << 8) | (uint256(validAfter) << 64+8);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/core/BasePaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ abstract contract BasePaymaster is IPaymaster, Ownable {
* @param validUntil last timestamp this UserOperation is valid (or zero for infinite)
* @param validAfter first timestamp this UserOperation is valid
*/
function packSigTimeRange(bool sigFailed, uint64 validUntil, uint64 validAfter) internal pure returns (uint256) {
function _packSigTimeRange(bool sigFailed, uint64 validUntil, uint64 validAfter) internal pure returns (uint256) {
return uint256(sigFailed ? 1 : 0) | (uint256(validUntil) << 8) | (uint256(validAfter) << 64 + 8);
}
}
12 changes: 6 additions & 6 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract EntryPoint is IEntryPoint, StakeManager {
/**
* Execute a batch of UserOperation.
* no signature aggregator is used.
* if any account requires an aggregator (that is, it returned an "actualAggregator" when
* if any account requires an aggregator (that is, it returned an aggregator when
* performing simulateValidation), then handleAggregatedOps() must be used instead.
* @param ops the operations to execute
* @param beneficiary the address to receive the fees
Expand Down Expand Up @@ -286,21 +286,21 @@ contract EntryPoint is IEntryPoint, StakeManager {
UserOpInfo memory outOpInfo;

(uint256 sigTimeRange, uint256 paymasterTimeRange, address aggregator) = _validatePrepayment(0, userOp, outOpInfo, SIMULATE_FIND_AGGREGATOR);
StakeInfo memory paymasterInfo = getStakeInfo(outOpInfo.mUserOp.paymaster);
StakeInfo memory senderInfo = getStakeInfo(outOpInfo.mUserOp.sender);
StakeInfo memory paymasterInfo = _getStakeInfo(outOpInfo.mUserOp.paymaster);
StakeInfo memory senderInfo = _getStakeInfo(outOpInfo.mUserOp.sender);
StakeInfo memory factoryInfo;
{
bytes calldata initCode = userOp.initCode;
address factory = initCode.length >= 20 ? address(bytes20(initCode[0 : 20])) : address(0);
factoryInfo = getStakeInfo(factory);
factoryInfo = _getStakeInfo(factory);
}

(bool sigFailed, uint64 validAfter, uint64 validUntil) = _intersectTimeRange(sigTimeRange, paymasterTimeRange);
ReturnInfo memory returnInfo = ReturnInfo(outOpInfo.preOpGas, outOpInfo.prefund,
sigFailed, validAfter, validUntil, getMemoryBytesFromOffset(outOpInfo.contextOffset));

if (aggregator != address(0)) {
AggregatorStakeInfo memory aggregatorInfo = AggregatorStakeInfo(aggregator, getStakeInfo(aggregator));
AggregatorStakeInfo memory aggregatorInfo = AggregatorStakeInfo(aggregator, _getStakeInfo(aggregator));
revert ValidationResultWithAggregation(returnInfo, senderInfo, factoryInfo, paymasterInfo, aggregatorInfo);
}
revert ValidationResult(returnInfo, senderInfo, factoryInfo, paymasterInfo);
Expand Down Expand Up @@ -601,7 +601,7 @@ contract EntryPoint is IEntryPoint, StakeManager {
revert FailedOp(opIndex, paymaster, "A51 prefund below actualGasCost");
}
uint256 refund = opInfo.prefund - actualGasCost;
internalIncrementDeposit(refundAddress, refund);
_incrementDeposit(refundAddress, refund);
bool success = mode == IPaymaster.PostOpMode.opSucceeded;
emit UserOperationEvent(opInfo.userOpHash, mUserOp.sender, mUserOp.paymaster, mUserOp.nonce, success, actualGasCost, actualGas);
} // unchecked
Expand Down
4 changes: 2 additions & 2 deletions contracts/core/SenderCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ contract SenderCreator {
* @return sender the returned address of the created account, or zero address on failure.
*/
function createSender(bytes calldata initCode) external returns (address sender) {
address initAddress = address(bytes20(initCode[0 : 20]));
address factory = address(bytes20(initCode[0 : 20]));
bytes memory initCallData = initCode[20 :];
bool success;
/* solhint-disable no-inline-assembly */
assembly {
success := call(gas(), initAddress, 0, add(initCallData, 0x20), mload(initCallData), 0, 32)
success := call(gas(), factory, 0, add(initCallData, 0x20), mload(initCallData), 0, 32)
sender := mload(0)
}
if (!success) {
Expand Down
18 changes: 9 additions & 9 deletions contracts/core/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract StakeManager is IStakeManager {
}

// internal method to return just the stake info
function getStakeInfo(address addr) internal view returns (StakeInfo memory info) {
function _getStakeInfo(address addr) internal view returns (StakeInfo memory info) {
DepositInfo storage depositInfo = deposits[addr];
info.stake = depositInfo.stake;
info.unstakeDelaySec = depositInfo.unstakeDelaySec;
Expand All @@ -36,7 +36,7 @@ abstract contract StakeManager is IStakeManager {
depositTo(msg.sender);
}

function internalIncrementDeposit(address account, uint256 amount) internal {
function _incrementDeposit(address account, uint256 amount) internal {
DepositInfo storage info = deposits[account];
uint256 newAmount = info.deposit + amount;
require(newAmount <= type(uint112).max, "deposit overflow");
Expand All @@ -47,31 +47,31 @@ abstract contract StakeManager is IStakeManager {
* add to the deposit of the given account
*/
function depositTo(address account) public payable {
internalIncrementDeposit(account, msg.value);
_incrementDeposit(account, msg.value);
DepositInfo storage info = deposits[account];
emit Deposited(account, info.deposit);
}

/**
* add to the account's stake - amount and delay
* any pending unstake is first cancelled.
* @param _unstakeDelaySec the new lock duration before the deposit can be withdrawn.
* @param unstakeDelaySec the new lock duration before the deposit can be withdrawn.
*/
function addStake(uint32 _unstakeDelaySec) public payable {
function addStake(uint32 unstakeDelaySec) public payable {
DepositInfo storage info = deposits[msg.sender];
require(_unstakeDelaySec > 0, "must specify unstake delay");
require(_unstakeDelaySec >= info.unstakeDelaySec, "cannot decrease unstake time");
require(unstakeDelaySec > 0, "must specify unstake delay");
require(unstakeDelaySec >= info.unstakeDelaySec, "cannot decrease unstake time");
uint256 stake = info.stake + msg.value;
require(stake > 0, "no stake specified");
require(stake <= type(uint112).max, "stake overflow");
deposits[msg.sender] = DepositInfo(
info.deposit,
true,
uint112(stake),
_unstakeDelaySec,
unstakeDelaySec,
0
);
emit StakeLocked(msg.sender, stake, _unstakeDelaySec);
emit StakeLocked(msg.sender, stake, unstakeDelaySec);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IAggregator {
* This method is called off-chain to calculate the signature to pass with handleOps()
* bundler MAY use optimized custom code perform this aggregation
* @param userOps array of UserOperations to collect the signatures from.
* @return aggregatesSignature the aggregated signature
* @return aggregatedSignature the aggregated signature
*/
function aggregateSignatures(UserOperation[] calldata userOps) external view returns (bytes memory aggregatesSignature);
function aggregateSignatures(UserOperation[] calldata userOps) external view returns (bytes memory aggregatedSignature);
}
6 changes: 3 additions & 3 deletions contracts/interfaces/IEntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ interface IEntryPoint is IStakeManager {
/**
* return value of simulateHandleOp
*/
error ExecutionResult(uint256 preOpGas, uint256 paid, uint64 validAfter, uint64 validBefore, bool targetSuccess, bytes targetResult);
error ExecutionResult(uint256 preOpGas, uint256 paid, uint64 validAfter, uint64 validUntil, bool targetSuccess, bytes targetResult);

//UserOps handled, per aggregator
struct UserOpsPerAggregator {
Expand All @@ -113,7 +113,7 @@ interface IEntryPoint is IStakeManager {
/**
* Execute a batch of UserOperation.
* no signature aggregator is used.
* if any account requires an aggregator (that is, it returned an "actualAggregator" when
* if any account requires an aggregator (that is, it returned an aggregator when
* performing simulateValidation), then handleAggregatedOps() must be used instead.
* @param ops the operations to execute
* @param beneficiary the address to receive the fees
Expand Down Expand Up @@ -167,7 +167,7 @@ interface IEntryPoint is IStakeManager {
* the aggregator returned by the account, and its current stake.
*/
struct AggregatorStakeInfo {
address actualAggregator;
address aggregator;
StakeInfo stakeInfo;
}

Expand Down
16 changes: 8 additions & 8 deletions contracts/samples/bls/BLSSignatureAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ contract BLSSignatureAggregator is IAggregator {
* the account checks the signature over this value using its public-key
*/
function userOpToMessage(UserOperation memory userOp) public view returns (uint256[2] memory) {
bytes32 hashPublicKey = _getPublicKeyHash(getUserOpPublicKey(userOp));
return _userOpToMessage(userOp, hashPublicKey);
bytes32 publicKeyHash = _getPublicKeyHash(getUserOpPublicKey(userOp));
return _userOpToMessage(userOp, publicKeyHash);
}

function _userOpToMessage(UserOperation memory userOp, bytes32 publicKeyHash) internal view returns (uint256[2] memory) {
Expand All @@ -106,12 +106,12 @@ contract BLSSignatureAggregator is IAggregator {

// helper for test
function getUserOpHash(UserOperation memory userOp) public view returns (bytes32) {
bytes32 hashPublicKey = _getPublicKeyHash(getUserOpPublicKey(userOp));
return _getUserOpHash(userOp, hashPublicKey);
bytes32 publicKeyHash = _getPublicKeyHash(getUserOpPublicKey(userOp));
return _getUserOpHash(userOp, publicKeyHash);
}

function _getUserOpHash(UserOperation memory userOp, bytes32 hashPublicKey) internal view returns (bytes32) {
return keccak256(abi.encode(internalUserOpHash(userOp), hashPublicKey, address(this), block.chainid));
function _getUserOpHash(UserOperation memory userOp, bytes32 publicKeyHash) internal view returns (bytes32) {
return keccak256(abi.encode(internalUserOpHash(userOp), publicKeyHash, address(this), block.chainid));
}

function _getPublicKeyHash(uint256[4] memory publicKey) internal pure returns(bytes32) {
Expand Down Expand Up @@ -141,9 +141,9 @@ contract BLSSignatureAggregator is IAggregator {
* This method is called off-chain to calculate the signature to pass with handleOps()
* bundler MAY use optimized custom code perform this aggregation
* @param userOps array of UserOperations to collect the signatures from.
* @return aggregatesSignature the aggregated signature
* @return aggregatedSignature the aggregated signature
*/
function aggregateSignatures(UserOperation[] calldata userOps) external pure returns (bytes memory aggregatesSignature) {
function aggregateSignatures(UserOperation[] calldata userOps) external pure returns (bytes memory aggregatedSignature) {
BLSHelper.XY[] memory points = new BLSHelper.XY[](userOps.length);
for (uint i = 0; i < points.length; i++) {
(uint256 x, uint256 y) = abi.decode(userOps[i].signature, (uint256, uint256));
Expand Down
12 changes: 6 additions & 6 deletions contracts/samples/gnosis/EIP4337Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract EIP4337Manager is GnosisSafe, IAccount {
address public immutable entryPoint;

// return value in case of signature failure, with no time-range.
// equivalent to packSigTimeRange(true,0,0);
// equivalent to _packSigTimeRange(true,0,0);
uint256 constant internal SIG_VALIDATION_FAILED = 1;

constructor(address anEntryPoint) {
Expand All @@ -39,8 +39,8 @@ contract EIP4337Manager is GnosisSafe, IAccount {
*/
function validateUserOp(UserOperation calldata userOp, bytes32 userOpHash, address /*aggregator*/, uint256 missingAccountFunds)
external override returns (uint256 sigTimeRange) {
address _msgSender = address(bytes20(msg.data[msg.data.length - 20 :]));
require(_msgSender == entryPoint, "account: not from entrypoint");
address msgSender = address(bytes20(msg.data[msg.data.length - 20 :]));
require(msgSender == entryPoint, "account: not from entrypoint");

GnosisSafe pThis = GnosisSafe(payable(address(this)));
bytes32 hash = userOpHash.toEthSignedMessageHash();
Expand All @@ -56,7 +56,7 @@ contract EIP4337Manager is GnosisSafe, IAccount {

if (missingAccountFunds > 0) {
//Note: MAY pay more than the minimum, to deposit for future transactions
(bool success,) = payable(_msgSender).call{value : missingAccountFunds}("");
(bool success,) = payable(msgSender).call{value : missingAccountFunds}("");
(success);
//ignore failure (its EntryPoint's job to verify, not account.)
}
Expand All @@ -75,8 +75,8 @@ contract EIP4337Manager is GnosisSafe, IAccount {
bytes memory data,
Enum.Operation operation
) external {
address _msgSender = address(bytes20(msg.data[msg.data.length - 20 :]));
require(_msgSender == entryPoint, "account: not from entrypoint");
address msgSender = address(bytes20(msg.data[msg.data.length - 20 :]));
require(msgSender == entryPoint, "account: not from entrypoint");

(bool success, bytes memory returnData) = execTransactionFromModuleReturnData(to, value, data, operation);

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/TestExpirePaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract TestExpirePaymaster is BasePaymaster {
returns (bytes memory context, uint256 sigTimeRange) {
(userOp, userOpHash, maxCost);
(uint64 validAfter, uint64 validUntil) = abi.decode(userOp.paymasterAndData[20 :], (uint64, uint64));
sigTimeRange = packSigTimeRange(false, validUntil, validAfter);
sigTimeRange = _packSigTimeRange(false, validUntil, validAfter);
context = "";
}
}
2 changes: 1 addition & 1 deletion contracts/test/TestExpiryAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ contract TestExpiryAccount is SimpleAccount {

//we have "until" value for all valid owners. so zero means "invalid signature"
bool sigFailed = _until == 0;
return packSigTimeRange(sigFailed, _until, _after);
return _packSigTimeRange(sigFailed, _until, _after);
}
}
2 changes: 1 addition & 1 deletion contracts/test/TestSignatureAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TestSignatureAggregator is IAggregator {
/**
* dummy test aggregator: sum all nonce values of UserOps.
*/
function aggregateSignatures(UserOperation[] calldata userOps) external pure returns (bytes memory aggregatesSignature) {
function aggregateSignatures(UserOperation[] calldata userOps) external pure returns (bytes memory aggregatedSignature) {
uint sum = 0;
for (uint i = 0; i < userOps.length; i++) {
sum += userOps[i].nonce;
Expand Down
Loading

0 comments on commit 7bd9909

Please sign in to comment.