Skip to content

Commit

Permalink
factory should return the wallet account address even if it has alrea…
Browse files Browse the repository at this point in the history
…dy been created
  • Loading branch information
davidinsuomi committed Feb 21, 2024
1 parent 48ebff2 commit ac50018
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 7 deletions.
8 changes: 7 additions & 1 deletion contracts/factory/SoulWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ contract SoulWalletFactory is Ownable {
* @return proxy Address of the deployed proxy
*/
function createWallet(bytes memory _initializer, bytes32 _salt) external returns (address proxy) {
// factory expected to return the wallet address even if the wallet has already been created.
address addr = getWalletAddress(_initializer, _salt);
uint codeSize = addr.code.length;
if (codeSize > 0) {
return addr;
}
bytes memory deploymentData = _proxyCode(_WALLETIMPL);
bytes32 salt = _calcSalt(_initializer, _salt);
assembly ("memory-safe") {
Expand Down Expand Up @@ -89,7 +95,7 @@ contract SoulWalletFactory is Ownable {
* @param _salt Salt for the create2 deployment
* @return proxy Counterfactual address of the SoulWallet
*/
function getWalletAddress(bytes memory _initializer, bytes32 _salt) external view returns (address proxy) {
function getWalletAddress(bytes memory _initializer, bytes32 _salt) public view returns (address proxy) {
bytes memory deploymentData = _proxyCode(_WALLETIMPL);
bytes32 salt = _calcSalt(_initializer, _salt);
proxy = Create2.computeAddress(salt, keccak256(deploymentData));
Expand Down
2 changes: 1 addition & 1 deletion lib/nitro-contracts
Submodule nitro-contracts updated 66 files
+46 −2 .github/workflows/contract-tests.yml
+1 −0 .gitignore
+1 −1 .prettierrc.js
+1 −1 .solhint.json
+1 −0 LICENSE.md
+2 −4 README.md
+3 −0 deploy/SequencerInbox.js
+14 −2 deploy/SequencerInboxStubCreator.js
+9 −2 foundry.toml
+1 −0 hardhat.config.ts
+13 −4 package.json
+1 −154 scripts/deployment.ts
+191 −0 scripts/deploymentUtils.ts
+4 −8 scripts/rollupCreation.ts
+107 −0 scripts/upgrade/deploy4844.ts
+2 −0 src/bridge/GasRefunder.sol
+22 −0 src/bridge/IBridge.sol
+69 −22 src/bridge/ISequencerInbox.sol
+436 −142 src/bridge/SequencerInbox.sol
+6 −0 src/challenge/ChallengeManager.sol
+24 −3 src/libraries/Error.sol
+52 −0 src/libraries/GasRefundEnabled.sol
+0 −25 src/libraries/IGasRefunder.sol
+13 −0 src/libraries/IReader4844.sol
+2 −2 src/mocks/InboxStub.sol
+11 −6 src/mocks/SequencerInboxStub.sol
+31 −1 src/mocks/Simple.sol
+100 −7 src/osp/OneStepProverHostIo.sol
+20 −0 src/precompiles/ArbGasInfo.sol
+8 −0 src/precompiles/ArbOwnerPublic.sol
+1 −1 src/rollup/BridgeCreator.sol
+31 −19 src/rollup/RollupCreator.sol
+4 −3 src/rollup/ValidatorWallet.sol
+6 −0 src/test-helpers/RollupMock.sol
+106 −14 test/contract/arbRollup.spec.ts
+3 −0 test/contract/batchData.json
+598 −0 test/contract/sequencerInbox.spec.4844.ts
+130 −17 test/contract/sequencerInboxForceInclude.spec.ts
+136 −0 test/contract/toolkit4844.ts
+14 −5 test/contract/validatorWallet.spec.ts
+28 −8 test/foundry/AbsInbox.t.sol
+6 −5 test/foundry/BridgeCreator.t.sol
+62 −0 test/foundry/ChallengeManager.t.sol
+24 −9 test/foundry/ERC20Bridge.t.sol
+2 −1 test/foundry/ERC20Inbox.t.sol
+133 −73 test/foundry/RollupCreator.t.sol
+614 −0 test/foundry/SequencerInbox.t.sol
+21 −0 test/foundry/util/TestUtil.sol
+25 −0 test/signatures/Bridge
+10 −0 test/signatures/BridgeCreator
+19 −0 test/signatures/ChallengeManager
+16 −0 test/signatures/DeployHelper
+26 −0 test/signatures/ERC20Bridge
+22 −0 test/signatures/ERC20Inbox
+23 −0 test/signatures/ERC20Outbox
+30 −0 test/signatures/Inbox
+22 −0 test/signatures/Outbox
+73 −0 test/signatures/RollupAdminLogic
+44 −0 test/signatures/RollupCore
+16 −0 test/signatures/RollupCreator
+71 −0 test/signatures/RollupUserLogic
+39 −0 test/signatures/SequencerInbox
+17 −0 test/signatures/test-sigs.bash
+14 −9 test/storage/SequencerInbox
+618 −22 yarn.lock
+39 −0 yul/Reader4844.yul
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable
2 changes: 1 addition & 1 deletion lib/solady
Submodule solady updated 170 files
108 changes: 108 additions & 0 deletions test/soulwallet/factory/SoulWalletFactory.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import {EntryPoint} from "@account-abstraction/contracts/core/EntryPoint.sol";
import "@source/validator/SoulWalletDefaultValidator.sol";
import {SoulWalletFactory} from "@source/factory/SoulWalletFactory.sol";
import "@source/modules/securityControlModule/SecurityControlModule.sol";
import "@source/modules/securityControlModule/trustedContractManager/trustedModuleManager/TrustedModuleManager.sol";
import "@source/modules/securityControlModule/trustedContractManager/trustedHookManager/TrustedHookManager.sol";
import
"@source/modules/securityControlModule/trustedContractManager/trustedValidatorManager/TrustedValidatorManager.sol";
import "@source/libraries/TypeConversion.sol";
import {SoulWalletLogicInstence} from "../base/SoulWalletLogicInstence.sol";
import {UserOpHelper} from "../../helper/UserOpHelper.t.sol";
import {UserOperationHelper} from "@soulwallet-core/test/dev/userOperationHelper.sol";
import "@source/abstract/DefaultCallbackHandler.sol";

contract SoulWalletFactoryTest is Test, UserOpHelper {
using TypeConversion for address;

SoulWalletDefaultValidator public soulWalletDefaultValidator;
SoulWalletLogicInstence public soulWalletLogicInstence;
SoulWalletFactory public soulWalletFactory;
DefaultCallbackHandler public defaultCallbackHandler;

function setUp() public {
defaultCallbackHandler = new DefaultCallbackHandler();
entryPoint = new EntryPoint();
soulWalletDefaultValidator = new SoulWalletDefaultValidator();
soulWalletLogicInstence = new SoulWalletLogicInstence(
address(entryPoint),
address(soulWalletDefaultValidator)
);
address logic = address(soulWalletLogicInstence.soulWalletLogic());

soulWalletFactory = new SoulWalletFactory(
logic,
address(entryPoint),
address(this)
);
require(soulWalletFactory._WALLETIMPL() == logic, "logic address not match");

}

function test_deployWallet() public {
bytes[] memory modules;
bytes[] memory hooks;
bytes32[] memory owners = new bytes32[](1);
owners[0] = address(this).toBytes32();
bytes32 salt = bytes32(0);
bytes memory initializer = abi.encodeWithSignature(
"initialize(bytes32[],address,bytes[],bytes[])",
owners,
defaultCallbackHandler,
modules,
hooks
);
address walletAddress1 = soulWalletFactory.getWalletAddress(
initializer,
salt
);
address walletAddress2 = soulWalletFactory.createWallet(
initializer,
salt
);
require(
walletAddress1 == walletAddress2,
"walletAddress1 != walletAddress2"
);
}
// test return the wallet account address even if it has already been created
function test_alreadyDeployedWallet() public {
bytes[] memory modules;
bytes[] memory hooks;
bytes32[] memory owners = new bytes32[](1);
owners[0] = address(this).toBytes32();
bytes32 salt = bytes32(0);
bytes memory initializer = abi.encodeWithSignature(
"initialize(bytes32[],address,bytes[],bytes[])",
owners,
defaultCallbackHandler,
modules,
hooks
);
address walletAddress1 = soulWalletFactory.getWalletAddress(
initializer,
salt
);
address walletAddress2 = soulWalletFactory.createWallet(
initializer,
salt
);
require(
walletAddress1 == walletAddress2,
"walletAddress1 != walletAddress2"
);
address walletAddress3 = soulWalletFactory.createWallet(
initializer,
salt
);
require(
walletAddress3 == walletAddress2,
"walletAddress3 != walletAddress2"
);
}

}

0 comments on commit ac50018

Please sign in to comment.