Skip to content
Smart contracts Audit finding Intermediate

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)

Solidity
    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

https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/PartyB/PartyBFacetImpl.sol#L29-L38

Tool used

Manual Review

Recommendation

Solidity
    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

The original report as published on Sherlock, by Juntao. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by Juntao

View all

2 more disclosed reports, best first.

More from Symmetrical Update

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.