Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/all-geese-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': patch
---

Add constructors to the different signers.
27 changes: 0 additions & 27 deletions contracts/mocks/account/AccountMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ abstract contract AccountMock is Account, ERC7739, ERC7821, ERC721Holder, ERC115
}

abstract contract AccountECDSAMock is Account, SignerECDSA, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
constructor(address signerAddr) {
_setSigner(signerAddr);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand All @@ -53,10 +49,6 @@ abstract contract AccountECDSAMock is Account, SignerECDSA, ERC7739, ERC7821, ER
}

abstract contract AccountP256Mock is Account, SignerP256, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
constructor(bytes32 qx, bytes32 qy) {
_setSigner(qx, qy);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand All @@ -68,10 +60,6 @@ abstract contract AccountP256Mock is Account, SignerP256, ERC7739, ERC7821, ERC7
}

abstract contract AccountRSAMock is Account, SignerRSA, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
constructor(bytes memory e, bytes memory n) {
_setSigner(e, n);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand Down Expand Up @@ -141,10 +129,6 @@ abstract contract AccountERC7579HookedMock is AccountERC7579Hooked {
}

abstract contract AccountERC7913Mock is Account, SignerERC7913, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
constructor(bytes memory _signer) {
_setSigner(_signer);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand All @@ -156,11 +140,6 @@ abstract contract AccountERC7913Mock is Account, SignerERC7913, ERC7739, ERC7821
}

abstract contract AccountMultiSignerMock is Account, MultiSignerERC7913, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
constructor(bytes[] memory signers, uint64 threshold) {
_addSigners(signers);
_setThreshold(threshold);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand All @@ -179,12 +158,6 @@ abstract contract AccountMultiSignerWeightedMock is
ERC721Holder,
ERC1155Holder
{
constructor(bytes[] memory signers, uint64[] memory weights, uint64 threshold) {
_addSigners(signers);
_setSignerWeights(signers, weights);
_setThreshold(threshold);
}

/// @inheritdoc ERC7821
function _erc7821AuthorizedExecutor(
address caller,
Expand Down
21 changes: 3 additions & 18 deletions contracts/mocks/utils/cryptography/ERC7739Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@
pragma solidity ^0.8.20;

import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {ERC7739} from "../../../utils/cryptography/signers/draft-ERC7739.sol";
import {SignerECDSA} from "../../../utils/cryptography/signers/SignerECDSA.sol";
import {SignerP256} from "../../../utils/cryptography/signers/SignerP256.sol";
import {SignerRSA} from "../../../utils/cryptography/signers/SignerRSA.sol";

contract ERC7739ECDSAMock is ERC7739, SignerECDSA {
constructor(address signerAddr) EIP712("ERC7739ECDSA", "1") {
_setSigner(signerAddr);
}
}

contract ERC7739P256Mock is ERC7739, SignerP256 {
constructor(bytes32 qx, bytes32 qy) EIP712("ERC7739P256", "1") {
_setSigner(qx, qy);
}
}

contract ERC7739RSAMock is ERC7739, SignerRSA {
constructor(bytes memory e, bytes memory n) EIP712("ERC7739RSA", "1") {
_setSigner(e, n);
}
}
abstract contract ERC7739ECDSAMock is ERC7739, SignerECDSA {}
abstract contract ERC7739P256Mock is ERC7739, SignerP256 {}
abstract contract ERC7739RSAMock is ERC7739, SignerRSA {}
5 changes: 5 additions & 0 deletions contracts/utils/cryptography/signers/MultiSignerERC7913.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ abstract contract MultiSignerERC7913 is AbstractSigner {
/// @dev The `threshold` is unreachable given the number of `signers`.
error MultiSignerERC7913UnreachableThreshold(uint64 signers, uint64 threshold);

constructor(bytes[] memory signers_, uint64 threshold_) {
_addSigners(signers_);
_setThreshold(threshold_);
}

/**
* @dev Returns a slice of the set of authorized signers.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ abstract contract MultiSignerERC7913Weighted is MultiSignerERC7913 {
/// @dev Thrown when the arrays lengths don't match. See {_setSignerWeights}.
error MultiSignerERC7913WeightedMismatchedLength();

constructor(bytes[] memory signers_, uint64[] memory weights_, uint64 threshold_) MultiSignerERC7913(signers_, 1) {
_setSignerWeights(signers_, weights_);
_setThreshold(threshold_);
}

/// @dev Gets the weight of a signer. Returns 0 if the signer is not authorized.
function signerWeight(bytes memory signer) public view virtual returns (uint64) {
unchecked {
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/cryptography/signers/SignerECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import {ECDSA} from "../ECDSA.sol";
abstract contract SignerECDSA is AbstractSigner {
address private _signer;

constructor(address signerAddr) {
_setSigner(signerAddr);
}

/**
* @dev Sets the signer with the address of the native signer. This function should be called during construction
* or through an initializer.
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/cryptography/signers/SignerERC7913.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import {SignatureChecker} from "../SignatureChecker.sol";
abstract contract SignerERC7913 is AbstractSigner {
bytes private _signer;

constructor(bytes memory signer_) {
_setSigner(signer_);
}

/// @dev Return the ERC-7913 signer (i.e. `verifier || key`).
function signer() public view virtual returns (bytes memory) {
return _signer;
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/cryptography/signers/SignerP256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ abstract contract SignerP256 is AbstractSigner {

error SignerP256InvalidPublicKey(bytes32 qx, bytes32 qy);

constructor(bytes32 qx, bytes32 qy) {
_setSigner(qx, qy);
}

/**
* @dev Sets the signer with a P256 public key. This function should be called during construction
* or through an initializer.
Expand Down
4 changes: 4 additions & 0 deletions contracts/utils/cryptography/signers/SignerRSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ abstract contract SignerRSA is AbstractSigner {
bytes private _e;
bytes private _n;

constructor(bytes memory e, bytes memory n) {
_setSigner(e, n);
}

/**
* @dev Sets the signer with a RSA public key. This function should be called during construction
* or through an initializer.
Expand Down
2 changes: 1 addition & 1 deletion test/account/AccountECDSA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function fixture() {

// ERC-4337 account
const helper = new ERC4337Helper();
const mock = await helper.newAccount('$AccountECDSAMock', ['AccountECDSA', '1', signer]);
const mock = await helper.newAccount('$AccountECDSAMock', [signer, 'AccountECDSA', '1']);

// ERC-4337 Entrypoint domain
const entrypointDomain = await getDomain(entrypoint.v08);
Expand Down
2 changes: 1 addition & 1 deletion test/account/AccountERC7913.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function fixture() {
const domain = { name: 'AccountERC7913', version: '1', chainId: entrypointDomain.chainId }; // Missing verifyingContract,

const makeMock = signer =>
helper.newAccount('$AccountERC7913Mock', ['AccountERC7913', '1', signer]).then(mock => {
helper.newAccount('$AccountERC7913Mock', [signer, 'AccountERC7913', '1']).then(mock => {
domain.verifyingContract = mock.address;
return mock;
});
Expand Down
2 changes: 1 addition & 1 deletion test/account/AccountMultiSigner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function fixture() {
const domain = { name: 'AccountMultiSigner', version: '1', chainId: entrypointDomain.chainId }; // Missing verifyingContract

const makeMock = (signers, threshold) =>
helper.newAccount('$AccountMultiSignerMock', ['AccountMultiSigner', '1', signers, threshold]).then(mock => {
helper.newAccount('$AccountMultiSignerMock', [signers, threshold, 'AccountMultiSigner', '1']).then(mock => {
domain.verifyingContract = mock.address;
return mock;
});
Expand Down
2 changes: 1 addition & 1 deletion test/account/AccountMultiSignerWeighted.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function fixture() {

const makeMock = (signers, weights, threshold) =>
helper
.newAccount('$AccountMultiSignerWeightedMock', ['AccountMultiSignerWeighted', '1', signers, weights, threshold])
.newAccount('$AccountMultiSignerWeightedMock', [signers, weights, threshold, 'AccountMultiSignerWeighted', '1'])
.then(mock => {
domain.verifyingContract = mock.address;
return mock;
Expand Down
4 changes: 2 additions & 2 deletions test/account/AccountP256.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ async function fixture() {
// ERC-4337 account
const helper = new ERC4337Helper();
const mock = await helper.newAccount('$AccountP256Mock', [
'AccountP256',
'1',
signer.signingKey.publicKey.qx,
signer.signingKey.publicKey.qy,
'AccountP256',
'1',
]);

// ERC-4337 Entrypoint domain
Expand Down
4 changes: 2 additions & 2 deletions test/account/AccountRSA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ async function fixture() {
// ERC-4337 account
const helper = new ERC4337Helper();
const mock = await helper.newAccount('$AccountRSAMock', [
'AccountRSA',
'1',
signer.signingKey.publicKey.e,
signer.signingKey.publicKey.n,
'AccountRSA',
'1',
]);

// ERC-4337 Entrypoint domain
Expand Down
10 changes: 7 additions & 3 deletions test/utils/cryptography/ERC7739.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('ERC7739', function () {
describe('for an ECDSA signer', function () {
before(async function () {
this.signer = ethers.Wallet.createRandom();
this.mock = await ethers.deployContract('ERC7739ECDSAMock', [this.signer.address]);
this.mock = await ethers.deployContract('$ERC7739ECDSAMock', ['ERC7739ECDSA', '1', this.signer.address]);
});

shouldBehaveLikeERC1271({ erc7739: true });
Expand All @@ -15,7 +15,9 @@ describe('ERC7739', function () {
describe('for a P256 signer', function () {
before(async function () {
this.signer = new NonNativeSigner(P256SigningKey.random());
this.mock = await ethers.deployContract('ERC7739P256Mock', [
this.mock = await ethers.deployContract('$ERC7739P256Mock', [
'ERC7739P256',
'1',
this.signer.signingKey.publicKey.qx,
this.signer.signingKey.publicKey.qy,
]);
Expand All @@ -27,7 +29,9 @@ describe('ERC7739', function () {
describe('for an RSA signer', function () {
before(async function () {
this.signer = new NonNativeSigner(RSASHA256SigningKey.random());
this.mock = await ethers.deployContract('ERC7739RSAMock', [
this.mock = await ethers.deployContract('$ERC7739RSAMock', [
'ERC7739RSA',
'1',
this.signer.signingKey.publicKey.e,
this.signer.signingKey.publicKey.n,
]);
Expand Down