Skip to content

Commit

Permalink
exploring gas of using oz
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsoncusack committed Mar 10, 2024
1 parent cd68327 commit ae70644
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 60 deletions.
89 changes: 45 additions & 44 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
AddOwnerAddressTest:testEmitsAddOwner() (gas: 92330)
AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 90548)
AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 93093)
AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 11732)
AddOwnerAddressTest:testSetsIsOwner() (gas: 90432)
AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 98831)
AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 115377)
AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 116169)
AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 11656)
AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 113698)
AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 128444)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 308642)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 291413)
CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 267720)
CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 287384)
CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 269071)
CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 277937)
AddOwnerAddressTest:testEmitsAddOwner() (gas: 92374)
AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 90614)
AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 93137)
AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 11754)
AddOwnerAddressTest:testSetsIsOwner() (gas: 90476)
AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 98897)
AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 115509)
AddOwnerPublicKeyTest:testFuzzIsOwnerPublicKey(bytes32,bytes32) (runs: 256, μ: 115333, ~: 115333)
AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 116301)
AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 11744)
AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 113775)
AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 128543)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 283108)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 265831)
CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 249076)
CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 261498)
CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 250379)
CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 259033)
CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 29214)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 15384)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 78994)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 78975)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 101278)
RemoveOwnerAtIndexTest:testEmitsRemoveOwner() (gas: 33281)
RemoveOwnerAtIndexTest:testRemovesOwner() (gas: 32647)
RemoveOwnerAtIndexTest:testRemovesOwnerAtIndex() (gas: 27532)
RemoveOwnerAtIndexTest:testRevertsIfCalledByNonOwner() (gas: 11310)
RemoveOwnerAtIndexTest:testRevertsIfNoOwnerAtIndex() (gas: 16626)
TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 15889)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12491)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 424683)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729020)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3376320, ~: 3249240)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 48858)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49093)
TestExecuteWithoutChainIdValidation:test_canChangeOwnerWithoutChainId() (gas: 287917)
TestExecuteWithoutChainIdValidation:test_cannotCallExec() (gas: 220047)
TestExecuteWithoutChainIdValidation:test_revertsIfCallerNotEntryPoint() (gas: 8620)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 13194)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 78927)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 78908)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 101211)
RemoveOwnerAtIndexTest:testEmitsRemoveOwner() (gas: 33299)
RemoveOwnerAtIndexTest:testRemovesOwner() (gas: 32682)
RemoveOwnerAtIndexTest:testRemovesOwnerAtIndex() (gas: 27567)
RemoveOwnerAtIndexTest:testRevertsIfCalledByNonOwner() (gas: 11332)
RemoveOwnerAtIndexTest:testRevertsIfNoOwnerAtIndex() (gas: 16648)
TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 15845)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12469)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 424839)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729083)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3663189, ~: 3665261)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50164)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50399)
TestExecuteWithoutChainIdValidation:test_canChangeOwnerWithoutChainId() (gas: 288312)
TestExecuteWithoutChainIdValidation:test_cannotCallExec() (gas: 220443)
TestExecuteWithoutChainIdValidation:test_revertsIfCallerNotEntryPoint() (gas: 8598)
TestExecuteWithoutChainIdValidation:test_revertsIfWrongNonceKey() (gas: 62275)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 82302)
TestInitialize:testInitialize() (gas: 21122)
TestInitialize:test_cannotInitImplementation() (gas: 2678562)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 39464)
TestInitialize:test_cannotInitImplementation() (gas: 2935795)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 42452)
TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24046)
TestIsValidSignature:testSmartWalletSigner() (gas: 2951388)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24917)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23847)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 421251)
TestIsValidSignature:testSmartWalletSigner() (gas: 3214255)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 25347)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 25481)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 421262)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 34964)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 428717)
TestValidateUserOp:testValidateUserOp() (gas: 447113)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 428728)
TestValidateUserOp:testValidateUserOp() (gas: 449222)
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
url = https://github.com/daimo-eth/p256-verifier
[submodule "lib/account-abstraction"]
path = lib/account-abstraction
url = https://github.com/eth-infinitism/account-abstraction
url = https://github.com/eth-finitism/account-abstraction
[submodule "lib/FreshCryptoLib"]
path = lib/FreshCryptoLib
url = https://github.com/rdubois-crypto/FreshCryptoLib
Expand All @@ -16,3 +16,6 @@
[submodule "lib/webauthn-sol"]
path = lib/webauthn-sol
url = https://github.com/base-org/webauthn-sol
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at dbb610
6 changes: 3 additions & 3 deletions src/CoinbaseSmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity 0.8.23;

import {Receiver} from "solady/accounts/Receiver.sol";
import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";
import {SignatureCheckerLib} from "solady/utils/SignatureCheckerLib.sol";
import {UUPSUpgradeable} from "openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol";
import {SignatureChecker} from "openzeppelin-contracts/contracts/utils/cryptography/SignatureChecker.sol";
import {UserOperation, UserOperationLib} from "account-abstraction/interfaces/UserOperation.sol";
import {WebAuthn} from "webauthn-sol/WebAuthn.sol";

Expand Down Expand Up @@ -302,7 +302,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271
owner := mload(add(ownerBytes, 32))
}

return SignatureCheckerLib.isValidSignatureNow(owner, message, sigWrapper.signatureData);
return SignatureChecker.isValidSignatureNow(owner, message, sigWrapper.signatureData);
}

if (ownerBytes.length == 64) {
Expand Down
20 changes: 9 additions & 11 deletions src/CoinbaseSmartWalletFactory.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {LibClone} from "solady/utils/LibClone.sol";
import {Clones} from "openzeppelin-contracts/contracts/proxy/Clones.sol";
import {CoinbaseSmartWallet} from "./CoinbaseSmartWallet.sol";

/// @title Coinbase Smart Wallet Factory
Expand Down Expand Up @@ -31,24 +31,22 @@ contract CoinbaseSmartWalletFactory {
revert OwnerRequired();
}

(bool alreadyDeployed, address accountAddress) =
LibClone.createDeterministicERC1967(msg.value, implementation, _getSalt(owners, nonce));
bytes32 salt = _getSalt(owners, nonce);
address accountAddress = Clones.predictDeterministicAddress(implementation, salt, address(this));

account = CoinbaseSmartWallet(payable(accountAddress));

if (alreadyDeployed == false) {
account.initialize(owners);
if (address(account).code.length > 0) {
return account;
}

Clones.cloneDeterministic(implementation, salt);
account.initialize{value: msg.value}(owners);
}

/// @dev Returns the deterministic address of the account created via `createAccount`.
function getAddress(bytes[] calldata owners, uint256 nonce) external view returns (address predicted) {
predicted = LibClone.predictDeterministicAddress(initCodeHash(), _getSalt(owners, nonce), address(this));
}

/// @dev Returns the initialization code hash of the ERC4337 account (a minimal ERC1967 proxy).
function initCodeHash() public view virtual returns (bytes32 result) {
result = LibClone.initCodeHashERC1967(implementation);
predicted = Clones.predictDeterministicAddress(implementation, _getSalt(owners, nonce), address(this));
}

/// @dev Returns the salt that will be used for deterministic address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract TestExecuteWithoutChainIdValidation is SmartWalletTestBase {
UserOperation memory userOp = _getUserOpWithSignature();
vm.expectEmit(true, true, true, true);
emit IEntryPoint.UserOperationEvent(
entryPoint.getUserOpHash(userOp), userOp.sender, address(0), userOp.nonce, false, 0, 48027
entryPoint.getUserOpHash(userOp), userOp.sender, address(0), userOp.nonce, false, 0, 48423
);
_sendUserOperation(userOp);
}
Expand Down
2 changes: 2 additions & 0 deletions test/CoinbaseSmartWallet/IsValidSignature.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {SignatureCheckerLib} from "solady/utils/SignatureCheckerLib.sol";

import "./SmartWalletTestBase.sol";
import "webauthn-sol/../test/Utils.sol";

Expand Down

0 comments on commit ae70644

Please sign in to comment.