Skip to content

Commit

Permalink
PP-325/REL-002 (#54)
Browse files Browse the repository at this point in the history
* refactor(CustomSmartWallet): initialization of the customSmartWallet contract

updated tests

* test(RelayHub): mod test to pass

* test: add unit testing and refactoring commom methods

* test(CustomSmartWalletFactory): add new test and use expect instead of assert

* test(RelayHub): updating test

* test(CustomSmartWalletFactory): refactor to use expect

* test(CustomSmartWallet.template): add test for smart wallet template
  • Loading branch information
franciscotobar authored Sep 12, 2022
1 parent 90aa30b commit aa2c585
Show file tree
Hide file tree
Showing 7 changed files with 860 additions and 702 deletions.
38 changes: 23 additions & 15 deletions contracts/smartwallet/CustomSmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ contract CustomSmartWallet is IForwarder {

uint256 public override nonce;
bytes32 public constant DATA_VERSION_HASH = keccak256("2");
bytes32 public domainSeparator;
bytes32 public domainSeparator;

constructor() public {
setOwner(msg.sender);
}

function buildDomainSeparator() internal {
domainSeparator = keccak256(
Expand All @@ -36,6 +40,23 @@ contract CustomSmartWallet is IForwarder {
_verifySig(suffixData, req, sig);
}

function setOwner(address owner) private {
//To avoid re-entrancy attacks by external contracts, the first thing we do is set
//the variable that controls "is initialized"
//We set this instance as initialized, by
//storing the logic address
//Set the owner of this Smart Wallet
//slot for owner = bytes32(uint256(keccak256('eip1967.proxy.owner')) - 1) = a7b53796fd2d99cb1f5ae019b54f9e024446c3d12b483f733ccc62ed04eb126a
bytes32 ownerCell = keccak256(abi.encodePacked(owner));

assembly {
sstore(
0xa7b53796fd2d99cb1f5ae019b54f9e024446c3d12b483f733ccc62ed04eb126a,
ownerCell
)
}
}

function getOwner() private view returns (bytes32 owner){
assembly {
owner := sload(
Expand Down Expand Up @@ -269,20 +290,7 @@ contract CustomSmartWallet is IForwarder {

require(getOwner() == bytes32(0), "already initialized");

//To avoid re-entrancy attacks by external contracts, the first thing we do is set
//the variable that controls "is initialized"
//We set this instance as initialized, by
//storing the logic address
//Set the owner of this Smart Wallet
//slot for owner = bytes32(uint256(keccak256('eip1967.proxy.owner')) - 1) = a7b53796fd2d99cb1f5ae019b54f9e024446c3d12b483f733ccc62ed04eb126a
bytes32 ownerCell = keccak256(abi.encodePacked(owner));

assembly {
sstore(
0xa7b53796fd2d99cb1f5ae019b54f9e024446c3d12b483f733ccc62ed04eb126a,
ownerCell
)
}
setOwner(owner);

//we need to initialize the contract
if (tokenAmount > 0) {
Expand Down
Loading

0 comments on commit aa2c585

Please sign in to comment.