lockQuote() increaseNonce parameters do not work properly
In the lockQuote function, the nonce increment uses quote.partyB before it is set, so it increments the nonce for address(0) instead of the actual partyB. This means the increaseNonce parameter does not work as intended, potentially allowing a partyB to reuse a signature to lock multiple quotes.
Juntao Follow with Viktor_Cortess, bin2chen and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/123
Found by
Juntao, Viktor_Cortess, bin2chen, cergyk, kutugu, n1punp, nobody2018, rvierdiiev, xiaoming90
Summary
in lockQuote() will execute partyBNonces[quote.partyB][quote.partyA] += 1 if increaseNonce == true
But this operation is executed before setting quote.partyB, resulting in actually setting partyBNonces[address(0)][quote.partyA] += 1
Vulnerability Detail
in lockQuote() , when execute partyBNonces[quote.partyB][quote.partyA] += 1 , quote.paryB is address(0)
function lockQuote(uint256 quoteId, SingleUpnlSig memory upnlSig, bool increaseNonce) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
LibMuon.verifyPartyBUpnl(upnlSig, msg.sender, quote.partyA);
checkPartyBValidationToLockQuote(quoteId, upnlSig.upnl);
if (increaseNonce) {
@> accountLayout.partyBNonces[quote.partyB][quote.partyA] += 1;
}
quote.modifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.LOCKED;
@> quote.partyB = msg.sender;
// lock funds for partyB
accountLayout.partyBPendingLockedBalances[msg.sender][quote.partyA].addQuote(quote);
quoteLayout.partyBPendingQuotes[msg.sender][quote.partyA].push(quote.id);
}
actually setting partyBNonces[address(0)][quote.partyA] += 1
Impact
increaseNonce parameters do not work properly
Code Snippet
Tool used
Manual Review
Recommendation
function lockQuote(uint256 quoteId, SingleUpnlSig memory upnlSig, bool increaseNonce) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
LibMuon.verifyPartyBUpnl(upnlSig, msg.sender, quote.partyA);
checkPartyBValidationToLockQuote(quoteId, upnlSig.upnl);
if (increaseNonce) {
- accountLayout.partyBNonces[quote.partyB][quote.partyA] += 1;
+ accountLayout.partyBNonces[msg.sender][quote.partyA] += 1;
}
quote.modifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.LOCKED;
quote.partyB = msg.sender;
// lock funds for partyB
accountLayout.partyBPendingLockedBalances[msg.sender][quote.partyA].addQuote(quote);
quoteLayout.partyBPendingQuotes[msg.sender][quote.partyA].push(quote.id);
}
Discussion
MoonKnightDev
The Party B can lock the quotes of only one Party A with a single signature and it cannot even open all of them. The sole repercussion would be the locking of the user's quotes. so we don't consider it as "High"
MoonKnightDev
Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/5
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
The code increments partyBNonces using quote.partyB before quote.partyB is assigned msg.sender, so the increment applies to the zero address instead of the actual partyB.
Impact
The increaseNonce parameter does not work properly, which could allow a partyB to lock multiple quotes from the same partyA with a single signature, though the impact is limited to locking quotes.
What the attacker needed
PartyB has a valid signature; increaseNonce is true
The fix
The code was fixed by changing the nonce increment to use msg.sender instead of quote.partyB.
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 smart contract function is supposed to increase a counter (nonce) for the party accepting a quote, but it does so before recording who that party is. So the counter for the real party never goes up, and the security check that relies on it is bypassed.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.