Penetration Test Report (X41 D-Sec): X41 Audit Thetanuts 2021 11 Public Report

SourceCodeReviewofSelectedOptionsVaultContracts
forThetanuts.Finance
FinalReportandManagementSummary
2022-02-16
PUBLIC
X41 D-SEC GmbH
Dennewartstr. 25-27
D-52068 Aachen
Amtsgericht Aachen: HRB19989
https://x41-dsec.de/
info@x41-dsec.de
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
Revision Date Change Author(s)
1 2021-11-30 DraftReport R.P.Weinmann,M.Vervier
2 2021-11-30 FinalReport R.P.Weinmann,M.Vervier
3 2021-12-14 Public Report Includ- M.Vervier
ingClientResponse
4 2022-02-16 UpdateAuditors M.Vervier
X41D-SecGmbH PUBLIC Page1of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
Contents
1 ExecutiveSummary 4
2 Introduction 6
2.1 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 FindingsOverview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 RecommendedFurtherTests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 RatingMethodology 9
3.1 CommonWeaknessEnumeration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 High-leveldescriptionofthesmartcontracts 10
4.1 CoveredCalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 SyntheticMining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 Results 12
5.1 Findings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 SideFindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6 AboutX41D-SecGmbH 21
X41D-SecGmbH PUBLIC Page2of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
Dashboard
Target
Customer Thetanuts.Finance
Name CoveredCallVaultV0,SynMiningVaultV1
Type SourceCodeReview
Version c9419488c5508f67832f4efa5556cc1acbb17a6b
Engagement
Type SourceCodeReview
Consultants Ralf-PhilippWeinmann,MarkusVervier
EngagementEffort 10person-days,2021-11-15to2021-11-26
Totalissuesfound 5
Critical - 0
High - 2
CWE-440(1)
CWE-266(2)
Medium - 3
CWE-367(1)
Low - 0
CWE-841(1)
None - 2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
Figure1:IssueOverview(l:Severity,r:CWEDistribution)
X41D-SecGmbH PUBLIC Page3of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
1 Executive Summary
InNovember2021,X41D-SecGmbHperformedaSourceCodeReviewofselectedsmartcon-
tracts by Thetanuts.Finance to identify vulnerabilities and weaknesses in the design and imple-
mentationofmodelingcashcoveredandphysicallysettledoptions.
Thetanuts.Financeplanstoprovidewithusersvaultstheycandepositcryptocurrencyassetsinto;
thesevaultsthengenerateyieldfortheusers. Theyieldisachievedbysellingoptionstomarket
makersbasedontheassetsinthevault. Anyseriousvulnerabilitiesinthecontractscouldresult
inalossoffundstocustomersorthemarketmaker(s)andhavenegativereputationaleffectson
Thetanuts.Finance.
AtotaloffivevulnerabilitieswerediscoveredduringthetestbyX41.Nonewereratedascritical,
twowereclassifiedashighseverity,threeasmedium,andnoneaslow. Additionally,twoissues
withoutadirectsecurityimpactwereidentified.
Medium - 3
High - 2
Figure1.1:IssuesandSeverity
X41D-SecGmbH PUBLIC Page4of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
In a Source Code Review, testers receive all available information about the target. The test
was performed by two experienced security experts between 2021-11-15 and 2021-11-26 in
collaborationwithRalf-PhilippWeinmannofComsecuris.
The majority of issues X41 identified were with the Synthetic Mining contract. This contract
alloweddepositslippageaswellasaneconomicattackinwhichanattackercangainashareof
theroundpremiumwithoutbeingexposedtotheriskoftheoption.Theseissueshavemeanwhile
beenfixedbyThetanuts.Finance.MoreoverintheSyntheticMiningcontract,assetmispricingcan
happenifthebasecurrencyofthecontractisnotdenotedinUSD.
For both the Synthetic Mining and the Covered Call contract, X41 found that the privileges of
theowneroftherespectivecontractcanbeasecurityproblemandthewaythemarketmakeris
givenaccesstothecontractistootrusting.
Inconclusiontheaudituncoveredrelevantflawsthatcouldhavenegativelyimpactedthesecure
operations of Thetanuts.Finance’s contracts. Despite these flaws, the attack surface was small
anddependenciesonthirdpartycontractswerelimited.
X41D-SecGmbH PUBLIC Page5of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
2 Introduction
X41 reviewed the yield-generating vault contracts of Thetanuts Finance which sell options to
marketmakerstogenerateprofitfortheirusers.
Thesesmartcontractsareconsideredsensitivebecausetheyhavedirectcontrolovercryptocur-
rencyassetscontributedbythirdparties.
Attackerscouldtrytoattackthesecontractstostealallorapartofthesecryptocurrencyassets,
causeassetstobelockedinasmartcontractorcauseotherfinancialorreputationallossestothe
partiesinteractingwiththesmartcontracts.
X41exclusivelyreviewedthetechnicalimplementationofthesmartcontractsdevelopedbyThe-
tanuts.Finance. The business model, operational security of Thetanuts.Finance, the security of
thirdpartyservicesorofrelatedsmart-contractswerenotinscopeofthisreview.
2.1 Methodology
X41firsttriedtogainahigher-levelunderstandingofwhatthecontractsaresupposedtodoand
howthosegoalsareachieved.Wematchedthisunderstandingwiththedevelopers’understand-
ing in two conference calls. Since there was no further written documentation to compare our
understandingto,wehavereproduceditinSection4.
Subsequentlyweperformedamanualauditofthesourcecode,evaluatingeachstatementofall
function.
X41adherestoestablishedstandardsforsourcecodereviewingandpenetrationtesting. These
areinparticulartheCERTSecureCoding1 standardsandtheStudy-APenetrationTestingModel2
oftheGermanFederalOfficeforInformationSecurity.
1https://wiki.sei.cmu.edu/confluence/display/seccode/SEI+CERT+Coding+Standards
2https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/Studies/Penetration/penetrati
on_pdf.pdf?__blob=publicationFile&v=1
X41D-SecGmbH PUBLIC Page6of22
SourceCodeReviewofSelectedOptionsVaultContracts Thetanuts.Finance
2.2 Findings Overview
DESCRIPTION SEVERITY ID REF
Contractownerhastoomuchpower HIGH THETA-PT-21-01 5.1.1
Marketmakerhastoomuchtrust MEDIUM THETA-PT-21-02 5.1.2
EconomicattackagainstSyntheticMining MEDIUM THETA-PT-21-03 5.1.3
DepositslippagepossibleonSyntheticMining MEDIUM THETA-PT-21-04 5.1.4
MispricinginSyntheticMiningforcertainvaultspossible HIGH THETA-PT-21-05 5.1.5
Somevariablescanbemadeimmutable NONE THETA-PT-21-100 5.2.1
Commonfunctionscanbefactoredout NONE THETA-PT-21-101 5.2.2
Table2.1:Security-RelevantFindings
2.3 Scope
Theauditwasperformedonthecodeofcommitidc9419483,containedintheGitHubrepository
locatedat:
• https://github.com/ezoia-com/thetanuts
Thefollowingfileswereinscopeforthisaudit:
filename SHA256hash
call_v0.sol
262e9a2bd70b1e23ae7eef03e2b25da3d3ab1823621f3399ffbee972a8102321
common_v0.sol
dbcb73f04bfc1a1491ad66a5a10b4bd63ada6eeb5c5da7b334bdf9028a0f92b0
common_v1.sol
3e8e5bc4663f80411553cee454d13f0e539a178663659d83b7444147c4b540e0
link.sol
c10966c18ba5cb1f835bab820aede607dbf39d910b13ff134faa4ac1e76933f9
syn.sol
794db1a2a03dba1c630c1ab7e5f[PII_REDACTED]eece1f09a7f8d023afc8cd189e5
Table2.2:Filesinscopeforaudit
Thecontractscontainingthemainpartsofthebusinesslogicofthisauditwere:
• CoveredCallVaultV0 which is contained in call_v0.sol and extends the vault contract
VaultV0 containedincommon_v0.sol
• SynMiningVaultV1 which is contained in syn.sol and extends the vault contract VaultV1
containedincommon_v1.sol
The contract HistoricalPriceConsumerV3_1 contained in link.sol is an auxilliary contract
that is used to retrieve pricing information from Chainlink price feeds. In total, the audit scope
was686linesofcode.
Thecodeofthird-partydependencieswerenotinscopeforthisaudit.
3thefullcommitidisc9419488c5508f67832f4efa5556cc1ac