Malicious users can block creators from acknowledging or deacknowledging an edge
The acknowledge and unacknowledge functions share the same signature format and replay-protection store, so a signature meant for one can be submitted to the other. An attacker can front-run a creator's transaction with the same signature sent to the opposite function, marking it used and causing the creator's transaction to revert.
0x73696d616f Follow with 1337, Bigsam and 15 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-titles-judging/issues/273
The protocol has acknowledged this issue.
Found by
0x73696d616f, 1337, Bigsam, ComposableSecurity, Krace, KupiaSec, Yu3H0, alexzoid, cryptic, fibonacci, fugazzi, jecikpo, jennifer37, juan, kennedy1030, mt030d, xiaoming90, zoyi
Summary
Malicious users can block someone from acknowledging or deacknowledging an edge, affecting the sanctity of the data in the Graph.
Vulnerability Detail
[!IMPORTANT]
The following is an extract from the contest's README:
Additional audit information.
In addition to the security of funds, we would also like there to be focus on the sanctity of the data in the TitlesGraph and the permissioning around it (only the appropriate people/contracts can signal reference and acknowledgement of reference).
The contest's README stated that apart from the loss of assets, the protocol team would like there to be a focus on the sanctity of the data. Thus, any issues related to the sanctity of the data in the Graph would be considered a valid Medium issue in the context of this audit contest, as the Contest's README supersede Sherlock's judging rules per Sherlock's Hierarchy of truth.
Both acknowledgeEdge and unacknowledgeEdge functions rely on the same modifier (checkSignature) to verify the signature validity. Thus, the signature used for acknowledgment and deacknowledgment of an edge follows the same format and can be used interchangeably. However, this design creates an issue, as described next.
-
Assume that Bob wants to acknowledge an edge. Thus, Bob calls the
acknowledgeEdgefunction with his signature $Sig_1$. -
A malicious user can always front-run Bob, take his signature ($Sig_1$) and sent to the
unacknowledgeEdgefunction instead. When theunacknowledgeEdgefunction is executed with $Sig_1$, the signature will be marked as used by the code_isUsed[keccak256(signature)] = true;. -
When Bob's
acknowledgeEdgetransaction gets executed, it will revert because his signature ($Sig_1$) has already been used.
The malicious users can keep repeating as the chain's gas fees on L2 are cheap.
The same trick can also be used to block someone from deacknowledge an edge.
File: TitlesGraph.sol
118: function acknowledgeEdge(bytes32 edgeId_, bytes calldata data_, bytes calldata signature_)
119: external
120: checkSignature(edgeId_, data_, signature_)
121: returns (Edge memory edge)
122: {
123: return _setAcknowledged(edgeId_, data_, true);
124: }
File: TitlesGraph.sol
146: function unacknowledgeEdge(bytes32 edgeId_, bytes calldata data_, bytes calldata signature_)
147: external
148: checkSignature(edgeId_, data_, signature_)
149: returns (Edge memory edge)
150: {
151: return _setAcknowledged(edgeId_, data_, false);
152: }
File: TitlesGraph.sol
39: /// @notice Modified to check the signature for a proxied acknowledgment.
40: modifier checkSignature(bytes32 edgeId, bytes calldata data, bytes calldata signature) {
41: bytes32 digest = _hashTypedData(keccak256(abi.encode(ACK_TYPEHASH, edgeId, data)));
42: if (
43: !edges[edgeId].to.creator.target.isValidSignatureNowCalldata(digest, signature)
44: || _isUsed[keccak256(signature)]
45: ) {
46: revert Unauthorized();
47: }
48: _;
49: _isUsed[keccak256(signature)] = true;
50: }
Impact
Malicious users can block someone from acknowledging or deacknowledging an edge, affecting the sanctity of the data in the Graph.
Code Snippet
Tool used
Manual Review
Recommendation
bytes32 public constant ACK_TYPEHASH = keccak256("Ack(bytes32 edgeId,bytes data)");
bytes32 public constant DEACK_TYPEHASH = keccak256("Deack(bytes32 edgeId,bytes data)");
bytes32 digest = _hashTypedData(keccak256(abi.encode(ACK_TYPEHASH, edgeId, data)));
bytes32 digest = _hashTypedData(keccak256(abi.encode(DEACK_TYPEHASH, edgeId, data)));
Consider using two different hash types for acknowledging or deacknowledging within the signature and use a different modifier for checking the signature. This will prevent malicious users from taking the signature intended for acknowledgeEdge and submitting it to unacknowledgeEdge, and vice versa.
modifier checkSignatureForAck(bytes32 edgeId, bytes calldata data, bytes calldata signature) {
bytes32 digest = _hashTypedData(keccak256(abi.encode(ACK_TYPEHASH, edgeId, data)));
..SNIP..
}
modifier checkSignatureForDeack(bytes32 edgeId, bytes calldata data, bytes calldata signature) {
bytes32 digest = _hashTypedData(keccak256(abi.encode(DEACK_TYPEHASH, edgeId, data)));
..SNIP..
}
function acknowledgeEdge(bytes32 edgeId_, bytes calldata data_, bytes calldata signature_)
external
- checkSignature(edgeId_, data_, signature_)
+ checkSignatureForAck(edgeId_, data_, signature_)
returns (Edge memory edge)
{
function unacknowledgeEdge(bytes32 edgeId_, bytes calldata data_, bytes calldata signature_)
external
- checkSignature(edgeId_, data_, signature_)
+ checkSignatureForDeack(edgeId_, data_, signature_)
returns (Edge memory edge)
{
With this design, if a creator creates a signature intended for acknowledgeEdge function, and a malicious user front-runs and copies the signature and submits it to acknowledgeEdge function, no harm is done as the malicious user is simply executing the task on behalf of the creator. The edge will still be acknowledged at the end.
Discussion
pqseags
Will investigate
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the acknowledge and unacknowledge functions use the same type hash and the same used-signature registry, so a signature is valid for either action and can be consumed by the wrong one.
Impact
A malicious user can repeatedly block a creator from acknowledging or deacknowledging an edge, undermining the integrity of the graph data; the attack relies on cheap gas on L2.
What the attacker needed
Attacker can front-run transactions; victim submits a signed acknowledge or unacknowledge; low gas costs on L2
The fix
Use separate type hashes and separate signature-checking modifiers for acknowledge and unacknowledge so a signature for one cannot be used for the other.
How it was found
- Bob signs a message to acknowledge an edge and submits acknowledgeEdge with that signature.
- A malicious user sees the pending transaction and front-runs it, submitting the same signature to unacknowledgeEdge.
- The unacknowledgeEdge call succeeds and marks the signature as used.
- Bob's acknowledgeEdge transaction then reverts because the signature is already used.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A signature is like a signed permission slip proving the creator approved a specific action. Here the same permission slip works for two opposite actions (acknowledge and unacknowledge), and once used it cannot be used again. An attacker can grab the slip and use it for the wrong action first, so the creator's real transaction fails.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.