Implementation Lab

BakerFi Share Accounting Challenge

Analyze BakerFi’s asset-to-share accounting and build a Foundry test that demonstrates whether one user’s actions can unfairly affect a later depositor.

What you will practice

  • Trace how changes in totalAssets() affect asset-to-share conversion during deposit().

  • Model multiple users and compare their share ownership, deposited assets, and withdrawal results.

  • Write a Foundry test that proves or disproves the Lab’s accounting-security condition.

Preparation and completion

Complete the BakerFi Leveraged Vault Learn section before starting this Lab.

You should understand:

  • How Strategy.deployed() contributes to totalAssets()
  • How RebaseLibrary.toBase() converts assets into shares
  • How deposit() calculates newly minted shares
  • How withdraw() converts shares back into assets
  • How Solidity integer division handles fractional results

The repository includes the vulnerable Vault model, supporting contracts, and a learner-editable Foundry test file.

Completion outcome

You will complete the Lab by writing a passing Foundry test that reaches the targeted accounting state and demonstrates whether one participant can obtain a disproportionate claim over assets supplied by another participant.