Атака Platypus использовала неправильное упорядочивание кода, утверждает аудитор

Disclaimer: The article has been updated to reflect that Omniscia did not audit a version of the MasterPlatypusV4 contract. Instead, the company audited a version of the MasterPlatypusV1 contract from Nov. 21 to Dec. 5, 2021.

The $8 million Platypus flash loan attack was made possible because of code that was in the wrong order, according to a post-mortem report from Platypus auditor Omniscia. The auditing company claims the problematic code didn’t exist in the version they audited.

Quote.

In light of the recent @Platypusdefi incident the team has prepared a technical post-mortem analysis describing how the exploit unravelled in great details.

Be sure to follow @Omniscia_sec to receive more security updates! pic.twitter.com/egHyoYaBhn

— Omniscia (@Omniscia_sec) February 17, 2023

End of Quote.

According to the report, the Platypus MasterPlatypusV4 contract “contained a fatal misconception in its emergencyWithdraw mechanism,” which made it perform “its solvency check before updating the LP tokens associated with the stake position.”

The report emphasized that the code for the emergencyWithdraw function had all of the necessary elements to prevent an attack, but these elements were simply written in the wrong order, as Omniscia explained:

Quote.

“The issue could have been prevented by re-ordering the MasterPlatypusV4::emergencyWithdraw statements and performing the solvency check after the user’s amount entry has been set to 0 which would have prohibited the attack from taking place.”

End of Quote.

Omniscia audited a version of the MasterPlatypusV1 contract from Nov. 21 to Dec. 5, 2021. However, this version “contained no integration points with an external platypusTreasure system” and therefore did not contain the misordered lines of code.

It is important to note that the code that was exploited did not exist at the time of Omniscia’s audit. Omniscia’s point of view implies that the developers must have deployed a new version of the contract at some point after the audit was made.

Related: Raydium объявляет подробности взлома, предлагает компенсацию жертвам

Аудитор утверждает, что использовалась реализация контракта по адресу Avalanche C-Chain 0xc007f27b757a782c833c568f5851ae1dfe0e6ec7. Строки 582-584 этого контракта вызывают функцию «isSolvent» контракта PlatypusTreasure, а строки 599-601 устанавливают сумму, фактор и rewardDebt пользователя в ноль. Однако эти суммы устанавливаются в ноль после того, как функция «isSolvent» уже была вызвана.

Команда Platypus подтвердила 16 февраля, что злоумышленник использовал «недостаток в механизме проверки платежеспособности USP», но первоначально команда не предоставила более подробной информации. Новый отчет аудитора проливает дополнительный свет на то, как злоумышленник мог осуществить эксплойт.

Команда Platypus объявила 16 февраля о том, что произошла атака. Она попыталась связаться с хакером и добиться возврата средств в обмен на вознаграждение за ошибку. Для осуществления атаки злоумышленник использовал прошитые кредиты, что похоже на стратегию, использованную в эксплойте Defrost Finance 25 декабря 2022 года.