i earned a 15k bug bounty from @Aptos, by demonstrating how to...

@moonshiesty
moon shiesty@moonshiesty
45 views Jan 27, 2025 ~5 min read
Advertisement
1
i earned a 15k bug bounty from @Aptos, by demonstrating how to bypass aptos coin (fungible-asset) freeze functionality

i also proposed the patch which fixed the issue in aptos-framework upgrade v1.24.1

here's how i found and fixed the issue:
Media image
2
we need to start with some background on the latest aptos token standard: fungible assets (FA) standard

aptos fungible asset balances are stored in objects owned by the user. to deposit, transfer, and freeze FA balances, users/admins need to pass in reference to the store: Object
Media image
3
to create a new reference to an object, the object must exist. this means if the object is deleted, new reference to the object cannot be created

however the aptos object implementation allows objects to be deleted, while resources stored in the same object address still exists

this means if you delete the object containing a FungibleStore, the FA admin (circle, tether, thala) with the freeze capability can no longer create a reference to that object

as a result those assets can never be frozen
Media image
4
deleting the object also means the exploiter cannot create new references to the Object containing FungibleStore. the trick is to store a reference of type Object, before deleting the object

this allows the exploiter to continue to deposit/withdraw from that FungibleStore, while the admin cannot freeze the funds

storing an Object reference to the FungibleStore is step 1) of the exploit
Media image
5
this exploit would be entirely pointless if the exploiter had no way to later withdraw funds

and before users can withdraw a FungibleAsset, there is an ownership check: signer == object.owner

normally this check requires the object metadata, ObjectCore still exists

but i found a way to bypass this check

here is the previous object::owns() implementation, can you spot the issue?
Media image
6
here is the 15k issue: object::owns() assumes if the object is the "owner" (ie the object is the signer to withdraw), the object still exists

this assumption does not hold true; a user can store the object's ExtendRef and generate signatures for the object, even AFTER the object is destroyed

step 2) to the exploit is storing the FungibleStore's Object's ExtendRef
7
we're still in the function constructing the FungibleStore object, lets fill in the remaining steps

step 3) we save the DeleteRef to later delete the object
Media image
8
for now, the FungibleStore appears normal, it can be deposited, withdraw, frozen just a normal store

now lets say the exploiter has done some malicious activity and wants to prevent the admin from freezing their funds

step 4) we delete the Object

from this point on, the only way to withdraw, freeze or deposit funds is through the single Object reference we have stored

no other modules or users can read/write to this reference
Media image
9
one example of where a bad actor could abuse this, was the @ThalaLabs exploiter

the thala admin was able to freeze MOD and thAPT balances, ending the drawdown of MOD and thAPT liquidity. with this trick, the exploiters assets could never be frozen, presenting an existential risk to MOD and thAPT liquidity

circle, tether and most stablecoin issuers also have AML compliance obligations to freeze OFAC and other illegal on-chain activity


@moonshiesty
moon shiesty@moonshiesty
the exploiter removes staked liquidity and swaps into 400k APT

finally thala freezes the exploiters MOD and thAPT and the exploiter returns 400,000 APT to the thala treasury leaving the account with a balance of 0.01 APT
Media image
Media image
10
at any point the exploiter can use their Object reference to withdraw their funds

the withdraw address can also be another FungibleStore Object with freeze disabled, preventing the admin from ever freezing or seizing malicious funds, all while the exploiter can continue to misuse their funds

step 5) withdraw all funds to a new address
Media image
11
you can view the proof of concept exploit here:

github.com/MoonShiesty/fa…

aptos patched the issue in aptos-framework v1.24.1

you can deploy this code, to confirm it's patched
12
here is the current object::owns() implementation

can you spot what aptos changed?
Media image
13
aptos moved the object existence check before short-circuiting 'true' when current_address == owner

this guarantees that if an object is owned by an address, the object still exists

now when the object metadata containing the owner is destroyed, developers are guaranteed there is no longer an object "owner"
14
now when the exploiter destroys the object containing the funds, they are no longer the object owner. this means they also can't withdraw their funds

github.com/aptos-labs/apt…
15
shoutout to the @Aptos team for quickly triaging and addressing the issue

there were only 23 days between the bug report, and the governance vote approval patching the issue
Media image
16
aptos is shipping features to make objects more intuitive and easier to reason about. this will help prevent similar issues in the future

AIP-112, allows objects to manage access policies for resources stored inside them

this will allows aptos devs to restrict access to resources stored inside an object, if the object is destroyed
Media image
17
for those who know, this conversation highlights some deep technical differences between @SuiNetwork object model and aptos

i like the direction aptos objects are headed. and i like how aptos objects are more powerful than sui objects; aptos object don't force developers into specific design patterns

aptos objects model is also clearly more complicated than sui's object model. this makes aptos objects more difficult to understand and reason about. in my opinion this was a key factor that contributed to this issue making into prod

i hope the new features in the aptos pipeline continue to make objects more useful, while providing the tools and apis to easily and securely reason about objects
18
this is also a lesson that formal verification can't solve every issue

object::owns() behavior was formally specified, but the specification itself contained an incorrect assumption that objects cannot sign for themselves after they are destroyed

the only way to find this issue was to read the code and reason about the way objects and the fungible asset api interact
Media image
19
@SuiNetwork shoutout to @HackenProof bug bounty portal

it's a good system to incentivize devs to find and report issues

didn't get the max 1m bounty, maybe next time
Media image
20
how did i find this bug?

i was reviewing @mirage_protocol code and thought to myself "i should check we never destroy an object containing a FungibleStore by mistake, then there's probably no way recover the funds"

so i looked. turns out you can still withdraw after destroying the object, if a reference of type Object exists

my next thought was "doesn't that mean you can't freeze the assets" 🤔

so i created the proof-of-concept, demonstrated it locally and submitted to the aptos bug portal

i racked my brain, and fungible_asset was the only aptos-framework code impacted by this issue

its possible other protocols were affected depending on implementation. i did some research and i wasn't able to find any
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement