Skip to content

Commit d2315a9

Browse files
committed
Add coinType to prevent crosschain replay attacks
1 parent 27ad314 commit d2315a9

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

contracts/reverseRegistrar/L2ReverseRegistrar.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error SignatureOutOfDate();
1515
error Unauthorised();
1616
error NotOwnerOfContract();
1717

18-
// Note on inception date
18+
// @note Inception date
1919
// The inception date is in milliseconds, and so will be divided by 1000
2020
// when comparing to block.timestamp. This means that the date will be
2121
// rounded down to the nearest second.
@@ -95,8 +95,9 @@ contract L2ReverseRegistrar is
9595
uint256 inceptionDate,
9696
bytes memory signature
9797
) internal view returns (bool) {
98-
bytes32 message = keccak256(abi.encodePacked(hash, addr, inceptionDate))
99-
.toEthSignedMessageHash();
98+
bytes32 message = keccak256(
99+
abi.encodePacked(hash, addr, inceptionDate, coinType)
100+
).toEthSignedMessageHash();
100101
bytes32 node = _getNamehash(addr);
101102

102103
if (!SignatureChecker.isValidSignatureNow(addr, message, signature)) {
@@ -119,7 +120,7 @@ contract L2ReverseRegistrar is
119120
bytes memory signature
120121
) internal view returns (bool) {
121122
bytes32 message = keccak256(
122-
abi.encodePacked(hash, addr, owner, inceptionDate)
123+
abi.encodePacked(hash, addr, owner, inceptionDate, coinType)
123124
).toEthSignedMessageHash();
124125
bytes32 node = _getNamehash(addr);
125126

test/reverseRegistrar/TestL2ReverseRegistrar.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('L2ReverseRegistrar', function () {
2020
'setTextForAddrWithSignature(address,string,string,uint256,bytes)'
2121
let setTextForAddrWithSignatureAndOwnableFuncSig =
2222
'setTextForAddrWithSignatureAndOwnable(address,address,string,string,uint256,bytes)'
23+
let coinType = 123
2324

2425
before(async function () {
2526
signers = await ethers.getSigners()
@@ -31,7 +32,7 @@ describe('L2ReverseRegistrar', function () {
3132
)
3233
L2ReverseRegistrar = await L2ReverseRegistrarFactory.deploy(
3334
namehash('optimism.reverse'),
34-
123,
35+
coinType,
3536
)
3637

3738
const MockSmartContractWalletFactory = await ethers.getContractFactory(
@@ -87,11 +88,12 @@ describe('L2ReverseRegistrar', function () {
8788
const signature = await signers[0].signMessage(
8889
ethers.utils.arrayify(
8990
keccak256(
90-
['bytes32', 'address', 'uint256'],
91+
['bytes32', 'address', 'uint256', 'uint256'],
9192
[
9293
keccak256(['bytes4', 'string'], [funcId, 'hello.eth']),
9394
account,
9495
inceptionDate,
96+
coinType,
9597
],
9698
),
9799
),
@@ -148,11 +150,12 @@ describe('L2ReverseRegistrar', function () {
148150
const signature = await signers[0].signMessage(
149151
ethers.utils.arrayify(
150152
keccak256(
151-
['bytes32', 'address', 'uint256'],
153+
['bytes32', 'address', 'uint256', 'uint256'],
152154
[
153155
keccak256(['bytes4', 'string'], [funcId, 'hello.eth']),
154156
account,
155157
inceptionDate,
158+
coinType,
156159
],
157160
),
158161
),
@@ -172,11 +175,12 @@ describe('L2ReverseRegistrar', function () {
172175
const signature2 = await signers[0].signMessage(
173176
ethers.utils.arrayify(
174177
keccak256(
175-
['bytes32', 'address', 'uint256'],
178+
['bytes32', 'address', 'uint256', 'uint256'],
176179
[
177180
keccak256(['bytes4', 'string'], [funcId, 'hello.eth']),
178181
account,
179182
inceptionDate2,
183+
coinType,
180184
],
181185
),
182186
),
@@ -206,12 +210,13 @@ describe('L2ReverseRegistrar', function () {
206210
const signature = await signers[0].signMessage(
207211
ethers.utils.arrayify(
208212
keccak256(
209-
['bytes32', 'address', 'address', 'uint256'],
213+
['bytes32', 'address', 'address', 'uint256', 'uint256'],
210214
[
211215
keccak256(['bytes4', 'string'], [funcId, 'ownable.eth']),
212216
MockOwnable.address,
213217
MockSmartContractWallet.address,
214218
inceptionDate,
219+
coinType,
215220
],
216221
),
217222
),
@@ -257,14 +262,15 @@ describe('L2ReverseRegistrar', function () {
257262
const signature = await signers[0].signMessage(
258263
ethers.utils.arrayify(
259264
keccak256(
260-
['bytes32', 'address', 'uint256'],
265+
['bytes32', 'address', 'uint256', 'uint256'],
261266
[
262267
keccak256(
263268
['bytes4', 'string', 'string'],
264269
[funcId, 'url', 'http://ens.domains'],
265270
),
266271
account,
267272
inceptionDate,
273+
coinType,
268274
],
269275
),
270276
),
@@ -329,14 +335,15 @@ describe('L2ReverseRegistrar', function () {
329335
const signature = await signers[0].signMessage(
330336
ethers.utils.arrayify(
331337
keccak256(
332-
['bytes32', 'address', 'uint256'],
338+
['bytes32', 'address', 'uint256', 'uint256'],
333339
[
334340
keccak256(
335341
['bytes4', 'string', 'string'],
336342
[funcId, 'url', 'http://ens.domains'],
337343
),
338344
account,
339345
inceptionDate,
346+
coinType,
340347
],
341348
),
342349
),
@@ -360,14 +367,15 @@ describe('L2ReverseRegistrar', function () {
360367
const signature2 = await signers[0].signMessage(
361368
ethers.utils.arrayify(
362369
keccak256(
363-
['bytes32', 'address', 'uint256'],
370+
['bytes32', 'address', 'uint256', 'uint256'],
364371
[
365372
keccak256(
366373
['bytes4', 'string', 'string'],
367374
[funcId, 'url', 'http://ens.domains'],
368375
),
369376
account,
370377
inceptionDate2,
378+
coinType,
371379
],
372380
),
373381
),
@@ -398,7 +406,7 @@ describe('L2ReverseRegistrar', function () {
398406
const signature = await signers[0].signMessage(
399407
ethers.utils.arrayify(
400408
keccak256(
401-
['bytes32', 'address', 'address', 'uint256'],
409+
['bytes32', 'address', 'address', 'uint256', 'uint256'],
402410
[
403411
keccak256(
404412
['bytes4', 'string', 'string'],
@@ -407,6 +415,7 @@ describe('L2ReverseRegistrar', function () {
407415
MockOwnable.address,
408416
MockSmartContractWallet.address,
409417
inceptionDate,
418+
coinType,
410419
],
411420
),
412421
),
@@ -468,18 +477,18 @@ describe('L2ReverseRegistrar', function () {
468477
const block = await ethers.provider.getBlock('latest')
469478
const inceptionDate = block.timestamp
470479

471-
console.log('inceptionDate', inceptionDate)
472480
const signature1 = await signers[0].signMessage(
473481
ethers.utils.arrayify(
474482
keccak256(
475-
['bytes32', 'address', 'uint256'],
483+
['bytes32', 'address', 'uint256', 'uint256'],
476484
[
477485
keccak256(
478486
['bytes4', 'string', 'string'],
479487
[funcId1, 'url', 'http://ens.domains'],
480488
),
481489
account,
482490
inceptionDate,
491+
coinType,
483492
],
484493
),
485494
),
@@ -488,11 +497,12 @@ describe('L2ReverseRegistrar', function () {
488497
const signature2 = await signers[0].signMessage(
489498
ethers.utils.arrayify(
490499
keccak256(
491-
['bytes32', 'address', 'uint256'],
500+
['bytes32', 'address', 'uint256', 'uint256'],
492501
[
493502
keccak256(['bytes4', 'string'], [funcId2, 'hello.eth']),
494503
account,
495504
inceptionDate + 1,
505+
coinType,
496506
],
497507
),
498508
),
@@ -553,8 +563,8 @@ describe('L2ReverseRegistrar', function () {
553563
const signature = await signers[0].signMessage(
554564
ethers.utils.arrayify(
555565
keccak256(
556-
['bytes32', 'address', 'uint256'],
557-
[keccak256(['bytes4'], [funcId]), account, inceptionDate],
566+
['bytes32', 'address', 'uint256', 'uint256'],
567+
[keccak256(['bytes4'], [funcId]), account, inceptionDate, coinType],
558568
),
559569
),
560570
)
@@ -587,8 +597,8 @@ describe('L2ReverseRegistrar', function () {
587597
const signature = await signers[0].signMessage(
588598
ethers.utils.arrayify(
589599
keccak256(
590-
['bytes32', 'address', 'uint256'],
591-
[keccak256(['bytes4'], [funcId]), account, inceptionDate],
600+
['bytes32', 'address', 'uint256', 'uint256'],
601+
[keccak256(['bytes4'], [funcId]), account, inceptionDate, coinType],
592602
),
593603
),
594604
)

0 commit comments

Comments
 (0)