This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
mt030d - Incorrect encoding of bytes for EIP712 digest in TitleGraph
causes signatures generated by common EIP712 tools to be unusable
#74
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
mt030d
medium
Incorrect encoding of bytes for EIP712 digest in
TitleGraph
causes signatures generated by common EIP712 tools to be unusableSummary
The signature in
TitleGraph.acknowledgeEdge()
and TitleGraph.unacknowledgeEdge()
is generated based on a digest computed from edgeId
and data
. However, the data
bytes argument is not correctly encoded according to the EIP712 specification. Consequently, a signature generated using common EIP712 tools would not pass validation in TitleGraph.checkSignature()
.Vulnerability Detail
According to EIP712:
However, the
checkSignature()
modifier in theTitlesGraph
contract reconstructs the digest by encoding the data bytes argument without first applying keccak256 hashing.As a result, a signature generated using common EIP712 tools (e.g. using the
signTypedData
function fromethers.js
) would not pass validation in TitleGraph.checkSignature()
.POC
here we run
The output is
0xab4623a7bacf25ed3d6779684f195ed63a5ed1ed46c278c107390086e74b739b35f1db213c6075dedc041d68ced3d11798d49afaf3c47743d4696c49f03037b51b
here we run
forge test --mc EIP712Test -vv
The output is
test_sig()
simulates the way the digest is reconstructed inTitleGraph.checkSignature()
, whiletest_sigShouldBe()
shows how the digest should be reconstructed.From the above output, we can see the signature generated by ethers.js matches the signature generated in
test_sigShouldBe()
and does not match the signature generated intest_sig()
.This PoC shows the way
TitleGraph.checkSignature()
reconstruct the digest is not compatible with the way data is encoded in EIP712.Impact
A signature generated by the signer using common EIP712 tools (e.g. signTypedData in
ethers.js
) would not pass validation in TitleGraph.checkSignature()
.Code Snippet
https://github.com/sherlock-audit/2024-04-titles/blob/main/wallflower-contract-v2/src/graph/TitlesGraph.sol#L41
Tool used
Manual Review, ethers.js, foundry
Recommendation
Encoding the
data
bytes as a keccak256 hash of its contents before computing the digest from it:The text was updated successfully, but these errors were encountered: