-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't use
chainId
when calculating domain hash of <=1.2.0
- Loading branch information
Showing
2 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/components/transactions/TxDetails/Summary/SafeTxHashDataRow/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { faker } from '@faker-js/faker' | ||
import { getDomainHash } from '.' | ||
import { AbiCoder, keccak256 } from 'ethers' | ||
|
||
// <= 1.2.0 | ||
// keccak256("EIP712Domain(address verifyingContract)"); | ||
const OLD_DOMAIN_TYPEHASH = '0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749' | ||
|
||
// >= 1.3.0 | ||
// keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"); | ||
const NEW_DOMAIN_TYPEHASH = '0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218' | ||
|
||
describe('SafeTxHashDataRow', () => { | ||
describe('getDomainHash', () => { | ||
it.each(['1.0.0' as const, '1.1.1' as const, '1.2.0' as const])( | ||
'should return the domain hash without chain ID for version %s', | ||
(version) => { | ||
const chainId = faker.string.numeric() | ||
const safeAddress = faker.finance.ethereumAddress() | ||
|
||
const result = getDomainHash({ chainId, safeAddress, safeVersion: version }) | ||
|
||
expect(result).toEqual( | ||
keccak256(AbiCoder.defaultAbiCoder().encode(['bytes32', 'address'], [OLD_DOMAIN_TYPEHASH, safeAddress])), | ||
) | ||
}, | ||
) | ||
|
||
it.each(['1.3.0' as const, '1.4.1' as const])( | ||
'should return the domain hash with chain ID for version %s', | ||
(version) => { | ||
const chainId = faker.string.numeric() | ||
const safeAddress = faker.finance.ethereumAddress() | ||
|
||
const result = getDomainHash({ chainId, safeAddress, safeVersion: version }) | ||
|
||
expect(result).toEqual( | ||
keccak256( | ||
AbiCoder.defaultAbiCoder().encode( | ||
['bytes32', 'uint256', 'address'], | ||
[NEW_DOMAIN_TYPEHASH, chainId, safeAddress], | ||
), | ||
), | ||
) | ||
}, | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters