Skip to content

add AA benchmarking to repo #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
[submodule "lib/dynamic-contracts"]
path = lib/dynamic-contracts
url = https://github.com/thirdweb-dev/dynamic-contracts
[submodule "lib/aa-benchmark"]
path = lib/aa-benchmark
url = https://github.com/zerodevapp/aa-benchmark
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
5 changes: 4 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ remappings = [
'erc721a-upgradeable/=lib/ERC721A-Upgradeable/',
'erc721a/=lib/ERC721A/',
'@thirdweb-dev/dynamic-contracts/=lib/dynamic-contracts/',
'lib/sstore2=lib/dynamic-contracts/lib/sstore2/'
'lib/sstore2=lib/dynamic-contracts/lib/sstore2/',
'aa-benchmark/=lib/aa-benchmark/',
'solady/=lib/solady/src/'
]
fs_permissions = [{ access = "read-write", path = "./src/test/smart-wallet/utils"}]
src = 'contracts'
test = 'src/test'
verbosity = 0
Expand Down
1 change: 1 addition & 0 deletions lib/aa-benchmark
Submodule aa-benchmark added at 4b8e54
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at 77809c
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"forge:build": "forge build",
"forge:test": "forge test",
"gas": "forge test --mc Benchmark --gas-report > gasreport.txt",
"forge:snapshot": "forge snapshot --check"
"forge:snapshot": "forge snapshot --check",
"aabenchmark": "forge test --mc AABenchmarkPrepare && forge test --mc ProfileThirdwebAccount -vvv"
},
"dependencies": {}
}
19 changes: 19 additions & 0 deletions src/test/smart-wallet/utils/AABenchmarkArtifacts.sol

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/test/smart-wallet/utils/AABenchmarkPrepare.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

// Test utils
import "../../utils/BaseTest.sol";

// Account Abstraction setup for smart wallets.
import { IEntryPoint } from "contracts/prebuilts/account/utils/Entrypoint.sol";

import { AccountFactory } from "contracts/prebuilts/account/non-upgradeable/AccountFactory.sol";

import "solady/utils/LibString.sol";

import "forge-std/Test.sol";

contract AABenchmarkPrepare is BaseTest {
AccountFactory private accountFactory;

function setUp() public override {
super.setUp();
accountFactory = new AccountFactory(IEntryPoint(payable(address(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789))));
}

function test_prepareBenchmarkFile() public {
address accountFactoryAddress = address(accountFactory);
bytes memory accountFactoryBytecode = accountFactoryAddress.code;

address accountImplAddress = accountFactory.accountImplementation();
bytes memory accountImplBytecode = accountImplAddress.code;

string memory accountFactoryAddressString = string.concat(
"address constant THIRDWEB_ACCOUNT_FACTORY_ADDRESS = ",
LibString.toHexStringChecksummed(accountFactoryAddress),
";"
);
string memory accountFactoryBytecodeString = string.concat(
'bytes constant THIRDWEB_ACCOUNT_FACTORY_BYTECODE = hex"',
LibString.toHexStringNoPrefix(accountFactoryBytecode),
'"',
";"
);

string memory accountImplAddressString = string.concat(
"address constant THIRDWEB_ACCOUNT_IMPL_ADDRESS = ",
LibString.toHexStringChecksummed(accountImplAddress),
";"
);
string memory accountImplBytecodeString = string.concat(
'bytes constant THIRDWEB_ACCOUNT_IMPL_BYTECODE = hex"',
LibString.toHexStringNoPrefix(accountImplBytecode),
'"',
";"
);

string memory path = "src/test/smart-wallet/utils/AABenchmarkArtifacts.sol";

vm.removeFile(path);

vm.writeLine(path, "");
vm.writeLine(path, "pragma solidity ^0.8.0;");
vm.writeLine(path, "interface ThirdwebAccountFactory {");
vm.writeLine(
path,
" function createAccount(address _admin, bytes calldata _data) external returns (address);"
);
vm.writeLine(
path,
" function getAddress(address _adminSigner, bytes calldata _data) external view returns (address);"
);
vm.writeLine(path, "}");

vm.writeLine(path, "interface ThirdwebAccount {");
vm.writeLine(path, " function execute(address _target, uint256 _value, bytes calldata _calldata) external;");
vm.writeLine(path, "}");
vm.writeLine(path, accountFactoryAddressString);
vm.writeLine(path, accountImplAddressString);
vm.writeLine(path, accountFactoryBytecodeString);
vm.writeLine(path, accountImplBytecodeString);

vm.writeLine(path, "");
}
}
48 changes: 48 additions & 0 deletions src/test/smart-wallet/utils/AABenchmarkTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "aa-benchmark/src/TestBase.sol";
import { ThirdwebAccountFactory, ThirdwebAccount, THIRDWEB_ACCOUNT_FACTORY_ADDRESS, THIRDWEB_ACCOUNT_IMPL_ADDRESS, THIRDWEB_ACCOUNT_FACTORY_BYTECODE, THIRDWEB_ACCOUNT_IMPL_BYTECODE } from "./AABenchmarkArtifacts.sol";

contract ProfileThirdwebAccount is AAGasProfileBase {
ThirdwebAccountFactory factory;

function setUp() external {
initializeTest("thirdwebAccount");
factory = ThirdwebAccountFactory(THIRDWEB_ACCOUNT_FACTORY_ADDRESS);
vm.etch(address(factory), THIRDWEB_ACCOUNT_FACTORY_BYTECODE);
vm.etch(THIRDWEB_ACCOUNT_IMPL_ADDRESS, THIRDWEB_ACCOUNT_IMPL_BYTECODE);
setAccount();
}

function fillData(
address _to,
uint256 _value,
bytes memory _data
) internal view override returns (bytes memory) {
return abi.encodeWithSelector(ThirdwebAccount.execute.selector, _to, _value, _data);
}

function getSignature(UserOperation memory _op) internal view override returns (bytes memory) {
return signUserOpHash(key, _op);
}

function createAccount(address _owner) internal override {
// if (address(account).code.length == 0) {
factory.createAccount(_owner, "");
// }
}

function getAccountAddr(address _owner) internal view override returns (IAccount) {
return IAccount(factory.getAddress(_owner, ""));
}

function getInitCode(address _owner) internal view override returns (bytes memory) {
return abi.encodePacked(address(factory), abi.encodeWithSelector(factory.createAccount.selector, _owner, ""));
}

function getDummySig(UserOperation memory _op) internal pure override returns (bytes memory) {
return
hex"fffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
}
}