Skip to content
Race condition Write-up Intermediate

Guvenkaya Security Insights Series — Sweat Economy

The audit found that the claim function's race condition lock was not asserted at the start, potentially allowing double spending, but testing showed no actual race conditions due to accruals being cleared before cross-contract calls. Other low-severity issues included a batch operation that could fail under production batch size and suboptimal rounding of an oracle fee, plus an informational finding about using a custom check instead of the #[private] macro.

guvenkaya-sec Follow

Published on medium.com

Welcome to our first entry in our Security Insights blog series, brought to you by Guvenkaya, a leading security research firm specializing in the realm of Rust security, Web3 security of Rust-based protocols, and traditional Web2 security frameworks. Through this series, we aim to share relatively short, insightful…

Guvenkaya, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the lock assertion was placed after some operations instead of at the very start of the function, and other issues stemmed from insufficient testing with production parameters and rounding down instead of up.

Impact

The race condition lock was ineffective in theory, but no actual double spending was observed; other issues could cause transaction failures under production batch sizes or minor financial losses due to rounding down.

What the attacker needed

None

The fix

The lock assertion was added at the start of the claim function, a test with production batch size was added, rounding was changed to div_ceil, and the #[private] macro was used for the callback.

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 write-up has not been written yet. The Original tab links to the source.

This is a security audit of a smart contract on the NEAR blockchain. The main issue was that a function meant to prevent two transactions from happening at the same time did not check a lock at the beginning, but in practice no double spending occurred because the balance was cleared before any external call. Other minor issues were found and fixed.

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.

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.