Skip to content

Commit

Permalink
add solidity pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Nov 27, 2023
1 parent 92d7fff commit 5a53e09
Show file tree
Hide file tree
Showing 139 changed files with 6,824 additions and 4,491 deletions.
14 changes: 12 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"semi": false,
"printWidth": 120,
"singleQuote": true,
"printWidth": 120
"trailingComma": "all",
"arrowParens": "avoid",
"overrides": [
{
"files": "*.sol",
"options": {
"singleQuote": false
}
}
],
"plugins": ["prettier-plugin-solidity"]
}
21 changes: 10 additions & 11 deletions contracts/SmartAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ contract SmartAccount is
_disableInitializers();
}

function initialize(address defalutCallbackHandler, address[] calldata validators, bytes[] calldata data)
external
initializer
{
function initialize(
address defalutCallbackHandler,
address[] calldata validators,
bytes[] calldata data
) external initializer {
if (validators.length != data.length) {
revert WrongArrayLength();
}
_setFallbackHandler(defalutCallbackHandler);
_setupValidators();
_setupRecoverors();
for (uint256 i = 0; i < validators.length;) {
for (uint256 i = 0; i < validators.length; ) {
_enableValidator(validators[i], data[i]);
unchecked {
i++;
Expand All @@ -45,12 +46,10 @@ contract SmartAccount is
return _entryPoint();
}

function _validateSignature(UserOperation calldata userOp, bytes32 userOpHash)
internal
virtual
override
returns (uint256 validationData)
{
function _validateSignature(
UserOperation calldata userOp,
bytes32 userOpHash
) internal virtual override returns (uint256 validationData) {
(address validator, bytes memory signature) = abi.decode(userOp.signature, (address, bytes));

if (!isValidatorEnabled(validator)) {
Expand Down
43 changes: 23 additions & 20 deletions contracts/SmartAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ contract SmartAccountFactory {
accountImplementation = new SmartAccount(_entryPoint);
}

function createAccount(address[] calldata validators, bytes[] calldata data, uint256 salt)
public
returns (SmartAccount ret)
{
function createAccount(
address[] calldata validators,
bytes[] calldata data,
uint256 salt
) public returns (SmartAccount ret) {
address addr = getAddress(validators, data, salt);
uint256 codeSize = addr.code.length;
if (codeSize > 0) {
Expand All @@ -28,28 +29,30 @@ contract SmartAccountFactory {
ret = SmartAccount(
payable(
new ERC1967Proxy{salt: bytes32(salt)}(
address(accountImplementation), abi.encodeCall(SmartAccount.initialize, (handler, validators, data))
address(accountImplementation),
abi.encodeCall(SmartAccount.initialize, (handler, validators, data))
)
)
);
}

function getAddress(address[] calldata validators, bytes[] calldata data, uint256 salt)
public
view
returns (address)
{
return Create2.computeAddress(
bytes32(salt),
keccak256(
abi.encodePacked(
type(ERC1967Proxy).creationCode,
abi.encode(
address(accountImplementation),
abi.encodeCall(SmartAccount.initialize, (handler, validators, data))
function getAddress(
address[] calldata validators,
bytes[] calldata data,
uint256 salt
) public view returns (address) {
return
Create2.computeAddress(
bytes32(salt),
keccak256(
abi.encodePacked(
type(ERC1967Proxy).creationCode,
abi.encode(
address(accountImplementation),
abi.encodeCall(SmartAccount.initialize, (handler, validators, data))
)
)
)
)
);
);
}
}
13 changes: 7 additions & 6 deletions contracts/core/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,23 @@ abstract contract ExecutionManager is Authority {
_execute(dest, value, func);
}

function executeBatch(address[] calldata dest, uint256[] calldata value, bytes[] calldata func)
external
onlyEntryPoint
{
function executeBatch(
address[] calldata dest,
uint256[] calldata value,
bytes[] calldata func
) external onlyEntryPoint {
if (dest.length != func.length || (value.length != 0 && value.length != func.length)) {
revert WrongArrayLength();
}
if (value.length == 0) {
for (uint256 i = 0; i < dest.length;) {
for (uint256 i = 0; i < dest.length; ) {
_execute(dest[i], 0, func[i]);
unchecked {
i++;
}
}
} else {
for (uint256 i = 0; i < dest.length;) {
for (uint256 i = 0; i < dest.length; ) {
_execute(dest[i], value[i], func[i]);
unchecked {
i++;
Expand Down
8 changes: 6 additions & 2 deletions contracts/core/FallbackManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ abstract contract FallbackManager is Authority {
bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
assembly {
let handler := sload(slot)
if iszero(handler) { return(0, 0) }
if iszero(handler) {
return(0, 0)
}
calldatacopy(0, 0, calldatasize())
// The msg.sender address is shifted to the left by 12 bytes to remove the padding
// Then the address without padding is stored right after the calldata
mstore(calldatasize(), shl(96, caller()))
// Add 20 bytes for the address appended add the end
let success := call(gas(), handler, 0, 0, add(calldatasize(), 20), 0, 0)
returndatacopy(0, 0, returndatasize())
if iszero(success) { revert(0, returndatasize()) }
if iszero(success) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
Expand Down
9 changes: 4 additions & 5 deletions contracts/core/RecoveryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ abstract contract RecoveryManager is Authority {

mapping(address => address) internal recoverors;

function getRecoverorsPaginated(address start, uint256 pageSize)
external
view
returns (address[] memory array, address next)
{
function getRecoverorsPaginated(
address start,
uint256 pageSize
) external view returns (address[] memory array, address next) {
return recoverors.page(start, pageSize);
}

Expand Down
15 changes: 9 additions & 6 deletions contracts/core/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ abstract contract ValidatorManager is Authority {

error ValidatorCannotBeZeroOrSentinel(address validator);
error ValidatorAlreadyEnabled(address validator);
error ValidatorAndPrevValidatorMismatch(address expectedValidator, address returnedValidator, address prevValidator);
error ValidatorAndPrevValidatorMismatch(
address expectedValidator,
address returnedValidator,
address prevValidator
);

event EnabledValidator(address validator);
event DisabledValidator(address validator);

mapping(address => address) internal validators;

function getValidatorsPaginated(address start, uint256 pageSize)
external
view
returns (address[] memory array, address next)
{
function getValidatorsPaginated(
address start,
uint256 pageSize
) external view returns (address[] memory array, address next) {
return validators.page(start, pageSize);
}

Expand Down
9 changes: 5 additions & 4 deletions contracts/interfaces/IValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {UserOperation} from "@account-abstraction/contracts/interfaces/UserOpera
import "./Metadata.sol";

interface IValidator is Metadata {
function validateSignature(UserOperation calldata userOp, bytes32 userOpHash, bytes calldata signature)
external
payable
returns (uint256 validationData);
function validateSignature(
UserOperation calldata userOp,
bytes32 userOpHash,
bytes calldata signature
) external payable returns (uint256 validationData);

function validCaller(address caller, bytes calldata data) external view returns (bool);

Expand Down
10 changes: 5 additions & 5 deletions contracts/libraries/LinkedAddressList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ library LinkedAddressList {
address internal constant SENTINEL = address(0x1);
uint160 internal constant SENTINEL_UINT = 1;

function page(mapping(address => address) storage target, address start, uint256 pageSize)
internal
view
returns (address[] memory array, address next)
{
function page(
mapping(address => address) storage target,
address start,
uint256 pageSize
) internal view returns (address[] memory array, address next) {
array = new address[](pageSize);

uint256 count;
Expand Down
55 changes: 31 additions & 24 deletions contracts/paymaster/VerifyingPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,34 @@ contract VerifyingPaymaster is BasePaymaster {
}
}

function getHash(UserOperation calldata userOp, uint48 validUntil, uint48 validAfter)
public
view
returns (bytes32)
{
return keccak256(
abi.encode(
pack(userOp), block.chainid, address(this), senderNonce[userOp.getSender()], validUntil, validAfter
)
);
function getHash(
UserOperation calldata userOp,
uint48 validUntil,
uint48 validAfter
) public view returns (bytes32) {
return
keccak256(
abi.encode(
pack(userOp),
block.chainid,
address(this),
senderNonce[userOp.getSender()],
validUntil,
validAfter
)
);
}

function _validatePaymasterUserOp(UserOperation calldata userOp, bytes32, /*userOpHash*/ uint256 requiredPreFund)
internal
override
returns (bytes memory context, uint256 validationData)
{
function _validatePaymasterUserOp(
UserOperation calldata userOp,
bytes32,
/*userOpHash*/ uint256 requiredPreFund
) internal override returns (bytes memory context, uint256 validationData) {
(requiredPreFund);

(uint48 validUntil, uint48 validAfter, bytes calldata signature) =
parsePaymasterAndData(userOp.paymasterAndData);
(uint48 validUntil, uint48 validAfter, bytes calldata signature) = parsePaymasterAndData(
userOp.paymasterAndData
);
require(
signature.length == 64 || signature.length == 65,
"VerifyingPaymaster: invalid signature length in paymasterAndData"
Expand All @@ -70,13 +77,13 @@ contract VerifyingPaymaster is BasePaymaster {
return ("", _packValidationData(false, validUntil, validAfter));
}

function parsePaymasterAndData(bytes calldata paymasterAndData)
public
pure
returns (uint48 validUntil, uint48 validAfter, bytes calldata signature)
{
(validUntil, validAfter) =
abi.decode(paymasterAndData[VALID_TIMESTAMP_OFFSET:SIGNATURE_OFFSET], (uint48, uint48));
function parsePaymasterAndData(
bytes calldata paymasterAndData
) public pure returns (uint48 validUntil, uint48 validAfter, bytes calldata signature) {
(validUntil, validAfter) = abi.decode(
paymasterAndData[VALID_TIMESTAMP_OFFSET:SIGNATURE_OFFSET],
(uint48, uint48)
);
signature = paymasterAndData[SIGNATURE_OFFSET:];
}

Expand Down
11 changes: 5 additions & 6 deletions contracts/validators/ECDSAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ contract ECDSAValidator is BaseValidator {

mapping(address => address) public owner;

function validateSignature(UserOperation calldata userOp, bytes32 userOpHash, bytes calldata signature)
external
payable
override
returns (uint256 validationData)
{
function validateSignature(
UserOperation calldata userOp,
bytes32 userOpHash,
bytes calldata signature
) external payable override returns (uint256 validationData) {
address _owner = owner[userOp.sender];
bytes32 hash = ECDSA.toEthSignedMessageHash(userOpHash);
if (_owner != ECDSA.recover(hash, signature)) {
Expand Down
21 changes: 11 additions & 10 deletions contracts/validators/OIDCSessionOnlyValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import "../common/Contants.sol";
import "./BaseValidator.sol";

interface IVerifier {
function verifyProof(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[2] memory input)
external
view
returns (bool r);
function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[2] memory input
) external view returns (bool r);
}

// OIDC ZK based validator that can only to add session validator
contract OIDCSessionOnlyValidator is BaseValidator {
string public constant override NAME = "OIDC Validator";
string public constant override VERSION = "0.0.1";

function validateSignature(UserOperation calldata userOp, bytes32 userOpHash, bytes calldata signature)
external
payable
override
returns (uint256 validationData)
{}
function validateSignature(
UserOperation calldata userOp,
bytes32 userOpHash,
bytes calldata signature
) external payable override returns (uint256 validationData) {}

function validCaller(address caller, bytes calldata data) external view override returns (bool) {}

Expand Down
6 changes: 4 additions & 2 deletions contracts/validators/p256/Base64.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ library Base64 {
// - `data.length + 2` -> Round up
// - `/ 3` -> Number of 3-bytes chunks
// - `4 *` -> 4 characters for each chunk
uint256 newlength = data.length * 8 / 6;
uint256 newlength = (data.length * 8) / 6;
if (data.length % 6 > 0) {
newlength++;
}
Expand All @@ -45,7 +45,9 @@ library Base64 {
for {
let dataPtr := data
let endPtr := add(data, mload(data))
} lt(dataPtr, endPtr) {} {
} lt(dataPtr, endPtr) {

} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
Expand Down
Loading

0 comments on commit 5a53e09

Please sign in to comment.