Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
dd378a1
created interfaces for Account recovery feature
Oct 16, 2023
37e2c9d
guardian interface and contract
Oct 17, 2023
1b09442
added test suite for Guardian.sol
Oct 20, 2023
3f4e74c
Merge branch 'thirdweb-dev:main' into account-social-recovery
alfheimrShiven Oct 20, 2023
a3cc320
AccountGuardian contract
Oct 20, 2023
f22fb72
added test suite for AccountGuardian contract
Oct 21, 2023
d3e6fe0
dependency injection for social recovery feature
Oct 21, 2023
3dba350
account lock req creation, signature validation and acceptance check
Oct 24, 2023
2ee0e32
Chainlink automation for lock request evaluation and lock account fea…
Oct 26, 2023
c642267
refactored deploy script for smart account util contracts
Oct 27, 2023
c476031
Deploy script for util contracts and its test
Oct 28, 2023
d7bd5d6
added link to feature doc in Readme
Oct 28, 2023
5bd148f
Merge pull request #1 from alfheimrShiven/account-social-recovery
alfheimrShiven Oct 30, 2023
14dfa8f
fixing..
Oct 30, 2023
8395b06
brought back DeployGuardian as DeploySmartAccountUtilContracts script…
Oct 30, 2023
b106090
Merge pull request #2 from alfheimrShiven/account-social-recovery
alfheimrShiven Oct 30, 2023
8001b8b
moved account util contract deployments to Account.sol, commented out…
Nov 1, 2023
c72f748
switched AccountLock to single instance deployment (as per the system…
Nov 2, 2023
a8ca25f
Merge pull request #3 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 2, 2023
19f18e3
restoring to util contract deployments to createAccount()
Nov 4, 2023
0ddb444
Changed the approach of calling Account.sol from AccountLock.sol
Nov 8, 2023
9c15308
added modifier to restrict an Account's lock status change by Account…
Nov 8, 2023
493001e
Merge pull request #4 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 8, 2023
f6b4843
made AccountGuardianTest compatible with deployment of AccountGuardia…
Nov 8, 2023
53b9588
replaced DeployGuardian script with DeploySmartAccountUtilContracts s…
Nov 10, 2023
38e568d
Merge pull request #5 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 10, 2023
3f763ed
sending AccountLock address while initilizing Account clones for acco…
Nov 14, 2023
665f243
Merge pull request #6 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 14, 2023
bb6c8ba
AccountLock tests: createLockRequest() unit tests
Nov 14, 2023
dc9a859
[Buggy] ECDSA.recover(hash, signature) throwing error
Nov 16, 2023
5a7d6aa
Merge pull request #7 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 16, 2023
a6f7e33
foundry error
codypharm Nov 17, 2023
82c9281
depencies added but errors persist
codypharm Nov 17, 2023
598de03
error comntinues
codypharm Nov 17, 2023
3be95eb
build error persists
codypharm Nov 17, 2023
896717d
updated chainlink remappings
Nov 17, 2023
b15ce17
ECDSA.recover(...) bug fixed, made lockRequest hash EIP 191 compatibl…
Nov 17, 2023
fe87435
Merge pull request #8 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 17, 2023
819a0a7
unlock request feature, refactored concensys evaluation to both lock/…
Nov 18, 2023
a764396
Merge pull request #9 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 18, 2023
4ae52bb
added unit tests for account unlock feature
Nov 18, 2023
a50e537
Merge pull request #10 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 19, 2023
0aee37b
Makefile
Nov 21, 2023
ad2a9b1
Merge pull request #11 from alfheimrShiven/account-social-recovery
alfheimrShiven Nov 22, 2023
cb6691e
cross chain transaction now includes estimated amount deposit
codypharm Nov 28, 2023
11c2173
slippage calvualtion added
codypharm Nov 29, 2023
1687b2f
bugs fixed
codypharm Nov 30, 2023
0bc9b51
stopped at this stage
codypharm Dec 4, 2023
20e1477
added IAccountRecovery
Dec 5, 2023
ecab36c
native payment intiation done
codypharm Dec 5, 2023
c3c5a31
link transfer initiator done
codypharm Dec 5, 2023
e822483
Account Recovery interface
Dec 5, 2023
42322c5
stock with userOp
codypharm Dec 5, 2023
0f95847
external signing implemented
codypharm Dec 5, 2023
37c3a36
recovery request guardian signature collection & concensus evaluation
Dec 7, 2023
78bb350
used isValidSignature but review is needed
codypharm Dec 7, 2023
7ceeb42
comments added and code made more dynamic
codypharm Dec 7, 2023
0bf4596
private key restoration
Dec 8, 2023
fc7af00
now using just one estimate function
codypharm Dec 9, 2023
4d4a248
proceed now has _
codypharm Dec 9, 2023
5c6ada8
Merge pull request #13 from alfheimrShiven/account-social-recovery
alfheimrShiven Dec 9, 2023
aaee738
Merge branch 'main' into cross-chain-transactions
codypharm Dec 9, 2023
b81a628
cross chain contracts deployed with accessible address
codypharm Dec 10, 2023
921b5c8
merge added
codypharm Dec 10, 2023
706d43e
getter added for account lock
codypharm Dec 10, 2023
c48ef73
Merge pull request #12 from alfheimrShiven/cross-chain-transactions
codypharm Dec 10, 2023
b818a8b
cross chain script sample added
codypharm Dec 10, 2023
faed719
Merge pull request #14 from alfheimrShiven/cross-chain-script
codypharm Dec 10, 2023
67ab98b
interface changes
Dec 10, 2023
e838c6d
Updated contract deploy script, fixed backward compatibility issues d…
Dec 10, 2023
318e840
Code optimized
codypharm Dec 10, 2023
7ec5c55
restructured functions
codypharm Dec 10, 2023
c036372
link address also added to constructot
codypharm Dec 10, 2023
3ad8a0b
master deployment updated
codypharm Dec 11, 2023
648be6c
one step skipped
codypharm Dec 11, 2023
e426334
last trial
codypharm Dec 11, 2023
21c1db4
Merge pull request #16 from alfheimrShiven/Fix-compilation
alfheimrShiven Dec 11, 2023
13454b1
Merge pull request #15 from alfheimrShiven/account-social-recovery
alfheimrShiven Dec 11, 2023
9994ac3
Update README.md
alfheimrShiven Dec 11, 2023
ddf5634
building cancelling
codypharm Dec 16, 2023
4e07d7c
resolved conflicts with main
Dec 18, 2023
4d11bd3
added AccountRecovery to deploy script
Dec 19, 2023
d968a8b
commented out both CCIP contracts [build still failing]
Dec 19, 2023
b17bd89
[FIX]: Fixed the stack too deep error by removing the _router, _link …
Dec 19, 2023
4b0133d
updating owner of smart account
Dec 22, 2023
89d12a4
Email verification to generate recovery request
Dec 24, 2023
669d16f
uncommented the CCIP contracts
Dec 24, 2023
15718b2
moved the deployment of CCIP contracts from BaseAccountFactory to non…
Dec 24, 2023
6a28d89
Merge pull request #17 from alfheimrShiven/revert/debugging
alfheimrShiven Dec 24, 2023
6413321
merged with main
Dec 24, 2023
14cc533
Merge pull request #18 from alfheimrShiven/account-social-recovery
alfheimrShiven Dec 24, 2023
a91ba30
updated account util deploy script and test
Dec 25, 2023
e12640a
Moved smart account creation to deploy script, updated deployment scr…
Dec 27, 2023
ab94b18
Merge pull request #19 from alfheimrShiven/account-social-recovery
alfheimrShiven Dec 27, 2023
17ed4de
generateRecoveryReq(..) tests
Dec 31, 2023
b9b472e
collectGuardianSignaturesOnRecoveryRequest(..) unit tests
Dec 31, 2023
b5490d4
refactored AccountRecovery unit tests
Dec 31, 2023
6abbb81
Consensus evaluation tests
Dec 31, 2023
f694b4f
Merge pull request #20 from alfheimrShiven/account-social-recovery
alfheimrShiven Dec 31, 2023
abbeeff
fixed Account::updateAdmin() function signature and call from Account…
Jan 3, 2024
6454a6c
Merge pull request #21 from alfheimrShiven/account-social-recovery
alfheimrShiven Jan 3, 2024
625340b
removed _generateSalt dependency on account admin, as it can get upda…
Jan 4, 2024
b0d399a
finished AccountRecovery unit tests. Coverage: 92%
Jan 4, 2024
af976db
Merge pull request #22 from alfheimrShiven/account-social-recovery
alfheimrShiven Jan 4, 2024
faf0a62
reduced params for commitEmailVerificationHash()
Jan 5, 2024
41099ca
Merge pull request #23 from alfheimrShiven/account-social-recovery
alfheimrShiven Jan 5, 2024
047eac0
updated Readme: Problem statement, Architecture
Jan 6, 2024
548776e
Merge pull request #24 from alfheimrShiven/account-social-recovery
alfheimrShiven Jan 6, 2024
d4162c5
updated Readme: Benefits of smart wallets
Jan 8, 2024
d54fdb5
Readme touchups
Jan 8, 2024
8b9536a
Merge pull request #25 from alfheimrShiven/account-social-recovery
alfheimrShiven Jan 8, 2024
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
4 changes: 4 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ANVIL_PRIVATE_KEY=
ANVIL_PUBLIC_KEY=
ANVIL_RPC_URL=http://127.0.0.1:8545

47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-include .env

.PHONY: all test test_anvil clean deploy fund help install snapshot format anvil

DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

help:
@echo "Usage:"
@echo " make deploy [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\""
@echo ""
@echo " make fund [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\""

all: clean remove update build deploy

# Clean the repo
clean :; forge clean

# Remove modules
remove :; rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && touch .gitmodules && git add . && git commit -m "modules"

# Update Dependencies
update:; forge update

build:; forge build

test :; forge test

test_anvil :; forge test --rpc-url $(ANVIL_RPC_URL)

snapshot :; forge snapshot

format :; forge fmt

anvil :; anvil -m 'test test test test test test test test test test test junk' --steps-tracing --block-time 1

NETWORK_ARGS := --rpc-url $(ANVIL_RPC_URL) --private-key $(ANVIL_PRIVATE_KEY) --broadcast

# ifeq ($(findstring --network sepolia,$(ARGS)),--network sepolia)
# NETWORK_ARGS := --rpc-url $(SEPOLIA_RPC_URL) --private-key $(SEPOLIA_PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
# endif

# ifeq ($(findstring --network ganache,$(ARGS)),--network ganache)
# NETWORK_ARGS := --rpc-url $(GANACHE_RPC_URL) --private-key $(GANACHE_PRIVATE_KEY) --broadcast -vvvv
# endif

deploy:
@forge script scripts/DeploySmartAccountUtilContracts.s.sol:DeploySmartAccountUtilContracts $(NETWORK_ARGS)

Large diffs are not rendered by default.

Large diffs are not rendered by default.

272 changes: 272 additions & 0 deletions broadcast/DeploySmartAccountUtilContracts.s.sol/31337/run-latest.json

Large diffs are not rendered by default.

34 changes: 16 additions & 18 deletions contracts/prebuilts/account/interface/IAccountGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
pragma solidity ^0.8.12;

interface IAccountGuardian {

/*///////////////////////////////////////////////////////////////
/*///////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////*/

Expand All @@ -20,7 +19,6 @@ interface IAccountGuardian {
*/
event GuardianRemoved(address indexed guardian);


/*///////////////////////////////////////////////////////////////
Errors
//////////////////////////////////////////////////////////////*/
Expand All @@ -33,9 +31,9 @@ interface IAccountGuardian {
error GuardianNotVerified(address guardian);

/**
* An error thrown if the guardian the user is trying to remove is not a part of
* An error thrown if the guardian the user is trying to remove is not a part of
* the user's guardian list.
* @param guardian address which the user was trying to remove from their
* @param guardian address which the user was trying to remove from their
* guardian list but was not the guardian
*/
error NotAGuardian(address guardian);
Expand All @@ -46,27 +44,21 @@ interface IAccountGuardian {
* @param guardian address of guardian user is trying to remove
* @param recoveryHash active recovery request hash
*/
error GuardianNotRemovedDueToActiveRecoveryRequest(
address guardian,
bytes32 recoveryHash
);

error GuardianNotRemovedDueToActiveRecoveryRequest(address guardian, bytes32 recoveryHash);

/*///////////////////////////////////////////////////////////////
/*///////////////////////////////////////////////////////////////
External Functions
//////////////////////////////////////////////////////////////*/


/**
* @notice Add guardians for your smart-wallet.
* @dev The guardian address needs to connect to the thirdweb’s
* @dev The guardian address needs to connect to the thirdweb’s
* guardian signup dapp by accepting the signin request.
* @param guardian the verified address of a wallet to be
* added as a guardian.
*/
function addGuardian(address guardian) external;


/**
* @notice A user will be able to remove allotted guardian(s) from
* their smart-wallet guardian list.
Expand All @@ -79,17 +71,23 @@ interface IAccountGuardian {
* @notice Returns a list of all added guardians of the sender.
* @return List of guardians of the sender smart-wallet.
*/
function getAllGuardians() external returns(address[] memory);
function getAllGuardians() external returns (address[] memory);

/**
* @notice Returns a bool value indicating if the guardian is that
* account's guardian or not.
* @param guardian guardian to be checked for
* @return bool
*/
function isAccountGuardian(address guardian) external view returns (bool);

function isAccountGuardian(address guardian) external view returns (bool);

/**
* @dev This will return the number of guardians allot for the account. Will be used when creating shards of the account's private key
* @return uint256 No. of account guardians
*/
function getTotalGuardians() external view returns (uint256);

/**
* @notice Sign the lock request
*/
}
}
36 changes: 22 additions & 14 deletions contracts/prebuilts/account/interface/IAccountLock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ interface IAccountLock {
event AccountUnLockRequestCreated(address indexed account);

/**
* An event emitted when a guardian accepts a lock request.
* @param lockRequest type hash of the lock request
* @param guardian address of guardian who accepted the request
* @notice Event emitted when request Concensus achieved
* @param account Address of the account
*/
event AccountLockRequestAccepted(bytes32 indexed lockRequest, address indexed guardian);
event RequestConcensusAchieved(address indexed account);

/**
* @notice An event emitted when a guardian declines a lock request.
* @param lockRequest type hash of the lock request
* @param guardian address of guardian who accepted the request
* @notice Event emitted when request Concensus could not be achieved
* @param account Address of the account
*/
event AccountLockRequestRejected(bytes32 indexed lockRequest, address indexed guardian);
event RequestConcensusCouldNotBeAchieved(address indexed account);

/*///////////////////////////////////////////////////////////////
Errors
Expand All @@ -56,15 +54,26 @@ interface IAccountLock {
error AccountAlreadyLocked(address account);

/**
* Error returned when creating a account lock request for which lock reques already exists.
* Error thrown when a unlock request is created for an already unlocked smart-wallet
* @param account address of the smart wallet being unlocked
*/
error AccountAlreadyUnLocked(address account);

/**
* Error returned when creating a account lock request for which lock request already exists.
*/
error ActiveLockRequestFound();

/**
* Error thrown when a unlock request is created for an already unlocked smart-wallet
* @param account address of the smart wallet being unlocked
* Error returned when creating a account unlock request for which an unlock request already exists.
*/
error ActiveUnLockRequestFound();

/**
* Error thrown when trying to evaluate Concensus for lock request that is not connected to the account sent
* @param account account whose lock req Concensus is being evaluated
*/
error AccountAlreadyUnlocked(address account);
error NoActiveRequestFoundForAccount(address account);

/*///////////////////////////////////////////////////////////////
External Functions
Expand All @@ -87,11 +96,10 @@ interface IAccountLock {

/**
* @dev This function is used to evaluate if the lockRequest was accepted or rejected by the guardians.
* @param lockRequest The lockRequest to evaluate
* @param account Account to which the lock request belongs.
*/

function lockRequestEvaluation(bytes32 lockRequest, address account) external;
function accountRequestConcensusEvaluation(address account) external returns (bool);

/**
* Will be called to execute the lock request on an account
Expand Down
41 changes: 41 additions & 0 deletions contracts/prebuilts/account/interface/IAccountRecovery.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

interface IAccountRecovery {
// Errors //
error NotOwner(address sender);
error NotAGuardian(address sender);
error NoRecoveryRequestFound(address account);
error NoSignaturesYet();

// Events //
event PrivateKeyShardsAlloted();
event AccountRecoveryRequestCreated(address indexed account);
event GuardianSignatureRecorded(address indexed guardian);
event AccountRecoveryRequestConcensusAchieved(address indexed account);
event AccountRecoveryRequestConcensusFailed(address indexed account);

/**
* @dev Will be used to store the shards of user's private key in a secure cloud based storage of the user.
* @param privateKeyShards Array of private key shards of the user's account
*/
function storePrivateKeyShards(uint8[] calldata privateKeyShards) external;

/**
* @dev Will collect the guardians signatures on the account's active recovery request
* @param recoveryReqSignature The signature of the guardian on the account's active recovery req.
*/
function collectGuardianSignaturesOnRecoveryRequest(address guardian, bytes memory recoveryReqSignature) external;

/**
* @dev Will contain the evaluation logic for concensus of account recovery request by the guardians
* @return Boolean flag indicating if the concensus on account recovery was achieved or not
*/
function accountRecoveryConcensusEvaluation() external returns (bool);

/**
* @dev Will restore the private key, encrypt and return/email the user
* @return Encrypted private key of the account
*/
function restorePrivateKey() external returns (bytes memory);
}
35 changes: 22 additions & 13 deletions contracts/prebuilts/account/interface/IGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
pragma solidity ^0.8.12;

interface IGuardian {

//////////////////////////////////////
//////////////////////////////////////
/////////// Errors ////////////////
//////////////////////////////////////

/**
/**
* Emits error if the guardian already exists
* @param guardian wallet address of the guardian being added.
*/
Expand All @@ -19,7 +18,7 @@ interface IGuardian {
*/
error NotAGuardian(address guardian);

//////////////////////////////////////
//////////////////////////////////////
/////////// Events ////////////////
//////////////////////////////////////

Expand All @@ -32,7 +31,7 @@ interface IGuardian {
* @param guardian address of the guardian being removed.
*/
event GuardianRemoved(address indexed guardian);

/////////////////////////////////////
/////////// External Functions //////
//////////////////////////////////////
Expand All @@ -49,14 +48,13 @@ interface IGuardian {
* @return bool Boolean value indicating if a address is a verified
* guardian or not.
*/
function isVerifiedGuardian(address isVerified) external returns(bool);
function isVerifiedGuardian(address isVerified) external returns (bool);

/**
* @notice Remove the sender as a verified thirdweb guardian.
*/
function removeVerifiedGuardian() external;


/**
* @notice Used to maintain a record of each account and it's guardian (accountGuardian) contract instance
* @param account Address of the account that got initialised
Expand All @@ -68,9 +66,9 @@ interface IGuardian {
/**
* @notice Creates a mapping of account to their respective guardians
* @param guardian Guardian to be added to account
* @param account Account whose guardian list is to be updated.
* @param account Account whose guardian list is to be updated.
*/
function addAccountToGuardian(address guardian, address account) external;
function addAccountToGuardian(address guardian, address account) external;

//////////////////////////////////////
/////////// Getter Function //////////
Expand All @@ -80,19 +78,30 @@ interface IGuardian {
* Returns the list of verified guardians.
* Can only be called by the owner.
*/
function getVerifiedGuardians() external view returns(address[] memory);
function getVerifiedGuardians() external view returns (address[] memory);

/**
* @notice Returns the accountGuardian address of an account
* @param account account
* @return address accountGuardian
*/
function getAccountGuardian(address account) external view returns(address);
function getAccountGuardian(address account) external view returns (address);

/**
* @notice Returns the list of accounts the guardian is guarding
* @param guardian Guardian whose account list has to be returned
*/
function getAccountsTheGuardianIsGuarding(address guardian) external view returns(address[] memory);
function getAccountsTheGuardianIsGuarding(address guardian) external view returns (address[] memory);

}
/**
* @dev Returns the address of the Account Recovery contract of an account. Will be used by guardians to get the account recovery request and send signature back to the account recovery contract.
* @param account The account for which it's recovery contract is requested
*/
function getAccountRecovery(address account) external returns (address);

/**
* @dev A checker function to check if a sender is guardian for the account
* @param account Account address for which check is being done.
*/
function isGuardingAccount(address account, address guardian) external view returns (bool);
}
Loading