Skip to content
Race condition Audit finding Advanced

Nonces not used in signed data

The signature verification in a smart contract vault did not include a nonce, so two signed transactions could be reordered by a malicious miner. This could cause an insecure recipient address to take effect instead of a later secure one, allowing the attacker to transfer funds.

IllIllI Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-harpie-judging/tree/main/160-M

Found by

IllIllI

Summary

Nonces are not used in the signature checks

Vulnerability Detail

A nonce can prevent an old value from being used when a new value exists. Without one, two transactions submitted in one order, can appear in a block in a different order

Impact

If a user is attacked, then tries to change the recipient address to a more secure address, initially chooses an insecure compromised one, but immediately notices the problem, then re-submits as a different, uncompromised address, a malicious miner can change the order of the transactions, so the insecure one is the one that ends up taking effect, letting the attacker transfer the funds

Code Snippet

https://github.com/Harpieio/contracts/blob/97083d7ce8ae9d85e29a139b1e981464ff92b89e/contracts/Vault.sol#L67-L71

Tool used

Manual Review

Recommendation

Include a nonce in what is signed

Harpie Team

Fixed by changing nonce system to an incremental system. Fix here.

Lead Senior Watson

Not an issue AFAIK, miners can't reorder txs unless they are signed with the same nonce. There would have to be some serious mis-use of this function by the recipient address, i.e. they would have to ask the server to sign for two different addresses and then broadcast the txs with the same nonce for this call. The proposed fix could probably be safely removed but doesn't hurt to keep it there.

The original report as published on Sherlock, by IllIllI. 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

Likely the signed data lacked a nonce, so signatures were not bound to a specific transaction order or uniqueness.

Impact

A malicious miner could reorder transactions so an insecure recipient address takes effect, letting the attacker transfer funds; however, the lead reviewer notes miners cannot reorder transactions unless they share the same nonce, so the issue may require misuse by the recipient.

What the attacker needed

Attacker can reorder transactions; recipient requests signatures for two addresses

The fix

The team fixed it by changing to an incremental nonce system, though the lead reviewer suggested the fix could probably be safely removed.

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 nonce is a number used once to make each signed message unique. Without it, two signed messages can be swapped in order by whoever orders transactions, like a miner. Here, that could let an attacker's chosen address win over a safer one.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by IllIllI

View all

119 more disclosed reports, best first.

More from Harpie

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.