Skip to content

Commit

Permalink
More optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
eloi010 committed Nov 15, 2023
1 parent 17e8adc commit f8b9344
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
19 changes: 10 additions & 9 deletions contracts/core/BaseOpenfortAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ abstract contract BaseOpenfortAccount is

// Check if it is a masterSessionKey (no whitelist applies)
if (sessionKey.masterSessionKey) return true;

for (uint256 i = 0; i < toContracts.length;) {
uint256 i;
for (i; i < toContracts.length;) {
if (toContracts[i] == address(this)) {
return false;
} // Only masterSessionKey can reenter
if (sessionKey.whitelising && !sessionKey.whitelist[toContracts[i]]) {
return false;
} // One contract's not in the sessionKey's whitelist (if any)
unchecked {
++i; // gas optimization
++i;
}
}
return true;
Expand Down Expand Up @@ -217,10 +217,11 @@ abstract contract BaseOpenfortAccount is
if (_target.length > 9 || _target.length != _calldata.length || _target.length != _value.length) {
revert InvalidParameterLength();
}
for (uint256 i = 0; i < _target.length;) {
uint256 i;
for (i; i < _target.length;) {
_call(_target[i], _value[i], _calldata[i]);
unchecked {
++i; // gas optimization
++i;
}
}
}
Expand Down Expand Up @@ -263,7 +264,7 @@ abstract contract BaseOpenfortAccount is
override
returns (uint256 validationData)
{
// require(entryPoint().getUserOpHash(userOp) == userOpHash, "MEEECK!");
require(entryPoint().getUserOpHash(userOp) == userOpHash, "Calculated userOpHash doesn't match");
bytes32 hash = userOpHash.toEthSignedMessageHash();
address signer = hash.recover(userOp.signature);

Expand Down Expand Up @@ -296,14 +297,14 @@ abstract contract BaseOpenfortAccount is
_requireFromEntryPointOrOwner();

require(_whitelist.length < 11, "Whitelist too big");
uint256 i = 0;
uint256 i;
for (i; i < _whitelist.length;) {
sessionKeys[_key].whitelist[_whitelist[i]] = true;
unchecked {
++i; // gas optimization
++i;
}
}
if (i > 0) {
if (i != 0) {
// If there was some whitelisting, it is not a masterSessionKey
sessionKeys[_key].whitelising = true;
sessionKeys[_key].masterSessionKey = false;
Expand Down
4 changes: 3 additions & 1 deletion contracts/core/eip6551/EIP6551OpenfortAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ contract EIP6551OpenfortAccount is BaseOpenfortAccount, IERC6551Account, IERC655

uint256 public state;

error OperationNotAllowed();

event EntryPointUpdated(address oldEntryPoint, address newEntryPoint);

receive() external payable override(BaseOpenfortAccount, IERC6551Account) {}
Expand Down Expand Up @@ -89,7 +91,7 @@ contract EIP6551OpenfortAccount is BaseOpenfortAccount, IERC6551Account, IERC655
override
returns (bytes memory _result)
{
require(_operation == 0, "Only call operations are supported");
if (_operation != 0) revert OperationNotAllowed();
++state;
bool success;
// solhint-disable-next-line avoid-low-level-calls
Expand Down
4 changes: 1 addition & 3 deletions contracts/core/managed/ManagedOpenfortFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ contract ManagedOpenfortFactory is IBaseOpenfortFactory, UpgradeableBeacon {
bytes32 salt = keccak256(abi.encode(_admin, _nonce));
account = getAddressWithNonce(_admin, _nonce);

if (account.code.length > 0) {
return account;
}
if (account.code.length != 0) return account;

emit AccountCreated(account, _admin);
account = address(
Expand Down
5 changes: 3 additions & 2 deletions contracts/core/recoverable/RecoverableOpenfortAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract RecoverableOpenfortAccount is BaseOpenfortAccount, Ownable2StepUpgradea
RecoveryConfig public recoveryDetails;

// keccak256("Recover(address recoveryAddress,uint64 executeAfter,uint32 guardiansRequired)");
bytes32 public constant RECOVER_TYPEHASH = 0x9f7aca777caf11405930359f601a4db01fad1b2d79ef3f2f9e93c835e9feffa5;
bytes32 private constant RECOVER_TYPEHASH = 0x9f7aca777caf11405930359f601a4db01fad1b2d79ef3f2f9e93c835e9feffa5;

event EntryPointUpdated(address oldEntryPoint, address newEntryPoint);
event Locked(bool isLocked);
Expand Down Expand Up @@ -208,7 +208,8 @@ contract RecoverableOpenfortAccount is BaseOpenfortAccount, Ownable2StepUpgradea
*/
function getGuardians() external view returns (address[] memory) {
address[] memory guardians = new address[](guardiansConfig.guardians.length);
for (uint256 i = 0; i < guardiansConfig.guardians.length;) {
uint256 i;
for (i; i < guardiansConfig.guardians.length;) {
guardians[i] = guardiansConfig.guardians[i];
unchecked {
++i; // gas optimization
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/SimpleNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ contract SimpleNFT is ERC721 {

// Anyone can mint an NFT for anyone
function mint(address _to) public {
_safeMint(_to, tokenId++);
_safeMint(_to, ++tokenId);
}
}

0 comments on commit f8b9344

Please sign in to comment.