Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Expects signatures to be in the same order that signers were added
Browse files Browse the repository at this point in the history
  • Loading branch information
acenolaza committed Oct 4, 2023
1 parent d4dbc0d commit 89328b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
24 changes: 11 additions & 13 deletions contracts/utils/TimestampedHashRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,20 @@ contract TimestampedHashRegistry is
require(signers.length() != 0, "Signers have not been set");
require(
signatures.length == signers.length(),
"Signatures length mismatch"
"Invalid number of signatures"
);
for (uint256 ind = 0; ind < signatures.length; ind++) {
for (uint256 ind = 0; ind < signers.length(); ind++) {
require(
signers.contains(
_hashTypedDataV4(
keccak256(
abi.encode(
_SIGNED_HASH_TYPE_HASH,
hashType,
signedHash.hash,
signedHash.timestamp
)
_hashTypedDataV4(
keccak256(
abi.encode(
_SIGNED_HASH_TYPE_HASH,
hashType,
signedHash.hash,
signedHash.timestamp
)
).recover(signatures[ind])
),
)
).recover(signatures[ind]) == signers.at(ind),
"Signature mismatch"
);
}
Expand Down
18 changes: 17 additions & 1 deletion test/utils/TimestampedHashRegistry.sol.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ describe('TimestampedHashRegistry', function () {
...signatures.slice(1),
])
).to.be.revertedWith('Signature mismatch');
// All signatures are different
await expect(
timestampedHashRegistry.registerSignedHash(
dapiFallbackHashType,
{ hash: root, timestamp },
Array(3).fill(signatures[0])
)
).to.be.revertedWith('Signature mismatch');
// All signatures are in the expected order
await expect(
timestampedHashRegistry.registerSignedHash(
dapiFallbackHashType,
{ hash: root, timestamp },
signatures.reverse()
)
).to.be.revertedWith('Signature mismatch');
});
});
});
Expand All @@ -380,7 +396,7 @@ describe('TimestampedHashRegistry', function () {
{ hash: root, timestamp },
signatures.slice(1)
)
).to.be.revertedWith('Signatures length mismatch');
).to.be.revertedWith('Invalid number of signatures');
});
});
});
Expand Down

0 comments on commit 89328b3

Please sign in to comment.