Skip to content

Commit

Permalink
check that datahash and hash of the pre-image data match
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jan 20, 2023
1 parent 9d188d3 commit 117706c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ contract Safe is
for (i = 0; i < requiredSignatures; i++) {
(v, r, s) = signatureSplit(signatures, i);
if (v == 0) {
require(keccak256(data) == dataHash, "GS027");
// If v is 0 then it is a contract signature
// When handling contract signatures the address of the contract is encoded into r
currentOwner = address(uint160(uint256(r)));
Expand Down
1 change: 1 addition & 0 deletions docs/error_codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `GS024`: `Invalid contract signature provided`
- `GS025`: `Hash has not been approved`
- `GS026`: `Invalid owner provided`
- `GS027`: `Data Hash and hash of the pre-image data do not match`

### General auth related
- `GS030`: `Only owners can approve a hash`
Expand Down
16 changes: 16 additions & 0 deletions test/core/Safe.Signatures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,21 @@ describe("Safe", async () => {

await safe.checkNSignatures(txHash, txHashData, signatures, 3)
})

it('should revert if the hash of the pre-image data and dataHash do not match', async () =>{
await setupTests()
const safe = await getSafeWithOwners([user1.address, user2.address, user3.address, user4.address], 2)
const tx = buildSafeTransaction({ to: safe.address, nonce: await safe.nonce() })
const txHashData = preimageSafeTransactionHash(safe, tx, await chainId())
const txHash = calculateSafeTransactionHash(safe, tx, await chainId())
const signatures = buildSignatureBytes([
await safeApproveHash(user1, safe, tx, true),
await safeApproveHash(user4, safe, tx),
await safeSignTypedData(user2, safe, tx)
])
await expect(
safe.checkNSignatures(txHash, "0x", signatures, 3)
).to.be.revertedWith("GS021")
})
})
})

0 comments on commit 117706c

Please sign in to comment.