diff --git a/.changeset/all-geese-stand.md b/.changeset/all-geese-stand.md new file mode 100644 index 000000000..44e6f2563 --- /dev/null +++ b/.changeset/all-geese-stand.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': patch +--- + +Add constructors to the different signers. diff --git a/contracts/mocks/account/AccountMock.sol b/contracts/mocks/account/AccountMock.sol index ab5c81dac..a8701566f 100644 --- a/contracts/mocks/account/AccountMock.sol +++ b/contracts/mocks/account/AccountMock.sol @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/contracts/mocks/utils/cryptography/ERC7739Mock.sol b/contracts/mocks/utils/cryptography/ERC7739Mock.sol index b8fe747c4..c803a40a3 100644 --- a/contracts/mocks/utils/cryptography/ERC7739Mock.sol +++ b/contracts/mocks/utils/cryptography/ERC7739Mock.sol @@ -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 {} diff --git a/contracts/utils/cryptography/signers/MultiSignerERC7913.sol b/contracts/utils/cryptography/signers/MultiSignerERC7913.sol index de735917f..c81c02b4d 100644 --- a/contracts/utils/cryptography/signers/MultiSignerERC7913.sol +++ b/contracts/utils/cryptography/signers/MultiSignerERC7913.sol @@ -70,6 +70,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. * diff --git a/contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol b/contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol index 09cd34c3d..12191a010 100644 --- a/contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol +++ b/contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol @@ -68,6 +68,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 { diff --git a/contracts/utils/cryptography/signers/SignerECDSA.sol b/contracts/utils/cryptography/signers/SignerECDSA.sol index f08e6f905..1b1f68095 100644 --- a/contracts/utils/cryptography/signers/SignerECDSA.sol +++ b/contracts/utils/cryptography/signers/SignerECDSA.sol @@ -28,6 +28,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. diff --git a/contracts/utils/cryptography/signers/SignerERC7913.sol b/contracts/utils/cryptography/signers/SignerERC7913.sol index 4a8ff153b..292a73ee0 100644 --- a/contracts/utils/cryptography/signers/SignerERC7913.sol +++ b/contracts/utils/cryptography/signers/SignerERC7913.sol @@ -32,6 +32,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; diff --git a/contracts/utils/cryptography/signers/SignerP256.sol b/contracts/utils/cryptography/signers/SignerP256.sol index fe449b08a..14c81055a 100644 --- a/contracts/utils/cryptography/signers/SignerP256.sol +++ b/contracts/utils/cryptography/signers/SignerP256.sol @@ -31,6 +31,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. diff --git a/contracts/utils/cryptography/signers/SignerRSA.sol b/contracts/utils/cryptography/signers/SignerRSA.sol index cfa88cbd9..5b29b15f4 100644 --- a/contracts/utils/cryptography/signers/SignerRSA.sol +++ b/contracts/utils/cryptography/signers/SignerRSA.sol @@ -29,6 +29,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. diff --git a/test/account/AccountECDSA.test.js b/test/account/AccountECDSA.test.js index d85cc7137..e6bf27ac3 100644 --- a/test/account/AccountECDSA.test.js +++ b/test/account/AccountECDSA.test.js @@ -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); diff --git a/test/account/AccountERC7913.test.js b/test/account/AccountERC7913.test.js index 118938b17..297a5ebf5 100644 --- a/test/account/AccountERC7913.test.js +++ b/test/account/AccountERC7913.test.js @@ -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; }); diff --git a/test/account/AccountMultiSigner.test.js b/test/account/AccountMultiSigner.test.js index 29badb26b..db563a2f0 100644 --- a/test/account/AccountMultiSigner.test.js +++ b/test/account/AccountMultiSigner.test.js @@ -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; }); diff --git a/test/account/AccountMultiSignerWeighted.test.js b/test/account/AccountMultiSignerWeighted.test.js index 15f24c2d4..d3522360d 100644 --- a/test/account/AccountMultiSignerWeighted.test.js +++ b/test/account/AccountMultiSignerWeighted.test.js @@ -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; diff --git a/test/account/AccountP256.test.js b/test/account/AccountP256.test.js index a4f7759db..33aadbb96 100644 --- a/test/account/AccountP256.test.js +++ b/test/account/AccountP256.test.js @@ -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 diff --git a/test/account/AccountRSA.test.js b/test/account/AccountRSA.test.js index b8cad7802..707469f0a 100644 --- a/test/account/AccountRSA.test.js +++ b/test/account/AccountRSA.test.js @@ -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 diff --git a/test/utils/cryptography/ERC7739.test.js b/test/utils/cryptography/ERC7739.test.js index c7e9c0091..8dc6a2b42 100644 --- a/test/utils/cryptography/ERC7739.test.js +++ b/test/utils/cryptography/ERC7739.test.js @@ -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 }); @@ -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, ]); @@ -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, ]);