Skip to content

Commit

Permalink
Renames in preparation for eip-1271 signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Sep 29, 2023
1 parent cdc04f2 commit 93df3fa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions contracts/core/Modifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pragma solidity >=0.7.0 <0.9.0;

import "./Module.sol";
import "../interfaces/IAvatar.sol";
import "../signature/EIP712Signature.sol";
import "../signature/SignatureChecker.sol";

abstract contract Modifier is Module, IAvatar, EIP712Signature {
abstract contract Modifier is Module, IAvatar, SignatureChecker {
address internal constant SENTINEL_MODULES = address(0x1);
/// Mapping of modules.
mapping(address => address) internal modules;
Expand Down Expand Up @@ -75,10 +75,10 @@ abstract contract Modifier is Module, IAvatar, EIP712Signature {

modifier moduleOnly() {
if (modules[msg.sender] == address(0)) {
if (modules[eip712SignedBy()] == address(0)) {
if (modules[moduleTxSignedBy()] == address(0)) {
revert NotAuthorized(msg.sender);
}
eip712BumpNonce();
moduleTxNonceBump();
}

_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0 <0.9.0;

/// @title EIP712Signature - A contract that extracts and inspects EIP-712 signatures appended to calldata.

abstract contract EIP712Signature {
/// @title SignatureChecker - A contract that extracts and inspects signatures appended to calldata.
/// @notice currently supporting eip-712 and eip-1271 signatures
abstract contract SignatureChecker {
uint256 private nonce;

/**
* @dev Returns the current nonce value.
*/
function eip712Nonce() public view returns (uint256) {
function moduleTxNonce() public view returns (uint256) {
return nonce;
}

/**
* @dev Increments nonce.
*/
function eip712BumpNonce() internal {
function moduleTxNonceBump() internal {
nonce = nonce + 1;
}

/**
* @dev When signature present in calldata, returns the address of the signer.
*/
function eip712SignedBy() internal returns (address signer) {
function moduleTxSignedBy() internal view returns (address signer) {
if (msg.data.length >= 4 + 32 + 32 + 1) {
(
bytes calldata dataTrimmed,
Expand Down
8 changes: 4 additions & 4 deletions contracts/test/TestSignature.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

import "../signature/EIP712Signature.sol";
import "../signature/SignatureChecker.sol";

contract TestSignature is EIP712Signature {
contract TestSignature is SignatureChecker {
event Hello(address signer);

event Goodbye(address signer);

function hello() public {
emit Hello(eip712SignedBy());
emit Hello(moduleTxSignedBy());
}

function goodbye(uint256, bytes memory) public {
emit Goodbye(eip712SignedBy());
emit Goodbye(moduleTxSignedBy());
}
}
4 changes: 2 additions & 2 deletions test/03_Modifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe("Modifier", async () => {
await TestModifier__factory.connect(
modifier.address,
hre.ethers.provider
).eip712Nonce()
).moduleTxNonce()
).to.equal(0);
});
it("execute a transaction with signature nonce is incremented.", async () => {
Expand Down Expand Up @@ -433,7 +433,7 @@ describe("Modifier", async () => {
await TestModifier__factory.connect(
modifier.address,
hre.ethers.provider
).eip712Nonce()
).moduleTxNonce()
).to.equal(1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/06_Eip712Signature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("EIP712Signature", async () => {

it("it publicly exposes the eip712 nonce", async () => {
const { testSignature } = await loadFixture(setup);
expect(await testSignature.eip712Nonce()).to.equal(0);
expect(await testSignature.moduleTxNonce()).to.equal(0);
});
});

Expand Down

0 comments on commit 93df3fa

Please sign in to comment.