Skip to content

Commit

Permalink
feat complete
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Jun 25, 2024
1 parent e2f60c3 commit bdc70ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/MultiOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,22 @@ contract MultiChainValidator is ERC7579ValidatorBase {
* Handles the uninstallation of the module and clears the threshold and owners
* @dev the data parameter is not used
*/
function onUninstall(bytes calldata) external override { }
function onUninstall(bytes calldata) external override {
FlatBytesLib.Bytes storage $local = owners[msg.sender];
$local.clear();
}

/**
* Checks if the module is initialized
*
* @param smartAccount address of the smart account
* @return true if the module is initialized, false otherwise
*/
function isInitialized(address smartAccount) public view returns (bool) { }
function isInitialized(address smartAccount) public view returns (bool) {
bytes32 slot = getOwnerSlot(smartAccount);
bytes memory value = SloadLib.sload(L1SELF, slot);
return value.length != 0;
}

/**
* Sets the threshold for the account
Expand Down Expand Up @@ -138,6 +145,7 @@ contract MultiChainValidator is ERC7579ValidatorBase {
{
// todo use getSender lib
bytes32 slot = getOwnerSlot(userOp.sender);
// sload from L1, fallback if L1 has no data set
bytes memory value = SloadLib.sload(L1SELF, slot);
Owner memory signer = abi.decode(value, (Owner));

Expand Down Expand Up @@ -208,7 +216,7 @@ contract MultiChainValidator is ERC7579ValidatorBase {
* @return name of the module
*/
function name() external pure virtual returns (string memory) {
return "OwnableValidator";
return "OwnableValidatorL1Sload";
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/SloadLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ library SloadLib {
return l1BlockNum;
}

function retrieveFromL1(address target, bytes32 slot) internal returns (bytes memory ret) {
function retrieveFromL1(
address target,
bytes32 slot
)
internal
view
returns (bytes memory ret)
{
uint256 l1BlockNum = IL1Blocks(L1BLOCKS_PRECOMPILE).latestBlockNumber();
bytes memory input = abi.encodePacked(l1BlockNum, target, slot);
bool success;
(success, ret) = L1SLOAD_PRECOMPILE.call(input);
(success, ret) = L1SLOAD_PRECOMPILE.staticcall(input);
require(success, "SloadLib: retrieveFromL1 failed");
}

function sload(address target, bytes32 slot) internal returns (bytes memory ret) {
function sload(address target, bytes32 slot) internal view returns (bytes memory ret) {
FlatBytesLib.Bytes storage local;

assembly {
Expand Down

0 comments on commit bdc70ea

Please sign in to comment.