Skip to content

Commit

Permalink
use calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jul 22, 2024
1 parent 22ddfb7 commit d0fdca7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions contracts/abstraction/identity/IdentityP256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ contract IdentityP256Implementation is IERC1271 {
return Clones.fetchCloneArgs(address(this));
}

function isValidSignature(bytes32 h, bytes memory signature) external view returns (bytes4 magicValue) {
// fetch and decode immutable public key for the clone
(bytes32 qx, bytes32 qy) = abi.decode(publicKey(), (bytes32, bytes32));

function isValidSignature(bytes32 h, bytes calldata signature) external view returns (bytes4 magicValue) {
// parse signature
if (signature.length < 0x40) return bytes4(0);
bytes32 r;
bytes32 s;
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
r := calldataload(add(signature.offset, 0x00))
s := calldataload(add(signature.offset, 0x20))
}

// fetch and decode immutable public key for the clone
(bytes32 qx, bytes32 qy) = abi.decode(publicKey(), (bytes32, bytes32));

return P256.verify(h, r, s, qx, qy) ? IERC1271.isValidSignature.selector : bytes4(0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/abstraction/identity/IdentityRSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract IdentityRSAImplementation is IERC1271 {
return abi.decode(Clones.fetchCloneArgs(address(this)), (bytes, bytes));
}

function isValidSignature(bytes32 h, bytes memory signature) external view returns (bytes4 magicValue) {
function isValidSignature(bytes32 h, bytes calldata signature) external view returns (bytes4 magicValue) {
// fetch immutable public key for the clone
(bytes memory e, bytes memory n) = publicKey();

Expand All @@ -25,7 +25,7 @@ contract IdentityRSAImplementation is IERC1271 {
contract IdentityRSAFactory {
address public immutable implementation = address(new IdentityRSAImplementation());

function create(bytes memory e, bytes memory n) public returns (address instance) {
function create(bytes calldata e, bytes calldata n) public returns (address instance) {
// predict the address of the instance for that key
address predicted = predict(e, n);
// if instance does not exist ...
Expand All @@ -36,7 +36,7 @@ contract IdentityRSAFactory {
return predicted;
}

function predict(bytes memory e, bytes memory n) public view returns (address instance) {
function predict(bytes calldata e, bytes calldata n) public view returns (address instance) {
return Clones.predictWithImmutableArgsDeterministicAddress(implementation, abi.encode(e, n), bytes32(0));
}
}

0 comments on commit d0fdca7

Please sign in to comment.