Pinned Tweet
Spent two weeks building a rug-pull detector on Solana. Not the "we flag suspicious
tokens" kind — one with a measured number next to every alert.
The signal: the creator adds liquidity to its own token. 97.9% of those ended in a
drain (422 of 431, 431 distinct wallets), median 8 minutes of warning before the
pool went to zero.
The part nobody publishes: it only catches 65.3% of pool rugs. The other 35% are dev
dumps and migration pulls, where the drain IS the event — there is nothing to warn
about beforehand. That's on the dashboard, not buried in a footnote.
I also killed four of my own hypotheses with data. ">10 launches in 24h" as a signal:
1.0% precision. Sell-share before the drain: inverted once I fixed the liquidity
metric. Both documented as discarded, with the numbers that killed them.
Calibrated against 17M frames from one full night of mainnet, over Solami's Blur
stream. TypeScript, 242 tests, docker compose up and it runs. Without an API key it
replays a real recorded hour through the same detector.
@useSolami
🔍 Practice audit #2 on CodeHawks done: Thunder Loan, the flash-loan protocol from Cyfrin's security course. Flash loans, an AMM price oracle and a UUPS proxy, all new to me.
📊 3 High · 2 Medium · 3 Low, each with a Foundry PoC.
🐛 The worst: repaying a flash loan with deposit() instead of repay(). The balance check passes, and you get LP tokens on top. Put in 0.15 in fees, walk out with ~50 of the LPs' money.
🙈 What I missed: a High I had written in my own notes as an open question. Second audit in a row.
🔑 An unanswered question in your notes is an uninvestigated bug.
📄 Report + PoCs: github.com/alebeta06/codehaw…
2
111
Alejandro Betancourt retweeted
CodeHawks Practice audit #2: Thunder Loan, the flash-loan protocol from Cyfrin's security course. It sits behind a UUPS proxy.
The bug: the planned upgrade deletes one variable.
V1: s_feePrecision, s_flashLoanFee
V2: s_flashLoanFee, FEE_PRECISION (now a constant)
Constants take no storage, so everything after it moves up one slot. After the upgrade, s_flashLoanFee reads the old precision: 1e18. The flash loan fee jumps from 0.3% to 100%.
V2's initialize() sets the fee back to 0.3%. It never runs: the proxy was already initialized.
Found it with forge inspect <Contract> storage on both versions, comparing slot by slot.
🔑 In an upgrade, variables are positions, not names.
CodeHawks Practice audit #2: Thunder Loan, the flash-loan protocol from Cyfrin's security course. It sits behind a UUPS proxy.
The bug: the planned upgrade deletes one variable.
V1: s_feePrecision, s_flashLoanFee
V2: s_flashLoanFee, FEE_PRECISION (now a constant)
Constants take no storage, so everything after it moves up one slot. After the upgrade, s_flashLoanFee reads the old precision: 1e18. The flash loan fee jumps from 0.3% to 100%.
V2's initialize() sets the fee back to 0.3%. It never runs: the proxy was already initialized.
Found it with forge inspect <Contract> storage on both versions, comparing slot by slot.
🔑 In an upgrade, variables are positions, not names.
Alejandro Betancourt retweeted
Verifiable build for my Solana program: six weeks of mismatched hashes, fixed by one flag.
The official 4.2.2 image defaults to platform-tools v1.56. My build uses v1.57. Different compiler, different bytecode.
solana-verify build --cargo-build-sbf-args="--tools-version v1.57 --arch v3"
Now the Docker build is byte-for-byte my devnet deployment.
The explorer badge still won't show: remote verification is mainnet-only.
If you're moving to sBPFv3 on 4.2.x, check which platform-tools your build actually uses.
nitter.cf/SolPlay_jonas/status/2…
Soon you will only be able to deploy sBPFv3 Programs! 🚨
Please let us know if you see any problems with that asap!
Check the guide:
solana.com/upgrades/sbpfv3-p…
Verifiable build for my Solana program: six weeks of mismatched hashes, fixed by one flag.
The official 4.2.2 image defaults to platform-tools v1.56. My build uses v1.57. Different compiler, different bytecode.
solana-verify build --cargo-build-sbf-args="--tools-version v1.57 --arch v3"
Now the Docker build is byte-for-byte my devnet deployment.
The explorer badge still won't show: remote verification is mainnet-only.
If you're moving to sBPFv3 on 4.2.x, check which platform-tools your build actually uses.
nitter.cf/SolPlay_jonas/status/2…
Soon you will only be able to deploy sBPFv3 Programs! 🚨
Please let us know if you see any problems with that asap!
Check the guide:
solana.com/upgrades/sbpfv3-p…
Alejandro Betancourt retweeted
18.6 ETH in fees. totalFees() returns 0.153.
uint64 tops out at ~18.44 ETH, and an explicit cast doesn't revert: it keeps the low 64 bits. withdrawFees() requires balance == totalFees, which never holds again. Fees locked.
0.8 wouldn't save you here. It checks overflow, not downcasts.
Trace from my PoC 👇
github.com/alebeta06/codehaw…
nitter.cf/Ale_Beta/status/211553…
I practiced auditing on Puppy Raffle, CodeHawks' First Flight #1.
Found 6 of its 16 known issues and wrote 4 Foundry PoCs. The one I missed taught me the most.
refund() looks fine on its own. So does selectWinner().
But refund() doesn't remove you from players[]. It writes address(0) in your slot.
selectWinner() still counts that slot:
→ the winner can be address(0)
→ the prize math counts ETH that was already refunded
I reviewed each function separately. The bug lives in the state they share.
🔑 Audit the system, not the functions.
Findings + PoCs: github.com/alebeta06/codehaw…
18.6 ETH in fees. totalFees() returns 0.153.
uint64 tops out at ~18.44 ETH, and an explicit cast doesn't revert: it keeps the low 64 bits. withdrawFees() requires balance == totalFees, which never holds again. Fees locked.
0.8 wouldn't save you here. It checks overflow, not downcasts.
Trace from my PoC 👇
github.com/alebeta06/codehaw…
nitter.cf/Ale_Beta/status/211553…
I practiced auditing on Puppy Raffle, CodeHawks' First Flight #1.
Found 6 of its 16 known issues and wrote 4 Foundry PoCs. The one I missed taught me the most.
refund() looks fine on its own. So does selectWinner().
But refund() doesn't remove you from players[]. It writes address(0) in your slot.
selectWinner() still counts that slot:
→ the winner can be address(0)
→ the prize math counts ETH that was already refunded
I reviewed each function separately. The bug lives in the state they share.
🔑 Audit the system, not the functions.
Findings + PoCs: github.com/alebeta06/codehaw…
Alejandro Betancourt retweeted
Most reentrancy posts show the code. This is what it looks like when it runs.
Puppy Raffle's refund() sends ETH before zeroing your slot. My attacker's receive() calls refund() again with the same index.
1 ETH in. 5 ETH out. Each step to the right is another refund() inside the previous one, until there's nothing left.
It works because sendValue forwards all the gas. With transfer() and its 2300 gas, the re-entry would fail.
The fix: zero the slot first, then send.
PoC: github.com/alebeta06/codehaw…
@CodeHawks @cyfrin
Most reentrancy posts show the code. This is what it looks like when it runs.
Puppy Raffle's refund() sends ETH before zeroing your slot. My attacker's receive() calls refund() again with the same index.
1 ETH in. 5 ETH out. Each step to the right is another refund() inside the previous one, until there's nothing left.
It works because sendValue forwards all the gas. With transfer() and its 2300 gas, the re-entry would fail.
The fix: zero the slot first, then send.
PoC: github.com/alebeta06/codehaw…
@CodeHawks @cyfrin
I practiced auditing on Puppy Raffle, CodeHawks' First Flight #1.
Found 6 of its 16 known issues and wrote 4 Foundry PoCs. The one I missed taught me the most.
refund() looks fine on its own. So does selectWinner().
But refund() doesn't remove you from players[]. It writes address(0) in your slot.
selectWinner() still counts that slot:
→ the winner can be address(0)
→ the prize math counts ETH that was already refunded
I reviewed each function separately. The bug lives in the state they share.
🔑 Audit the system, not the functions.
Findings + PoCs: github.com/alebeta06/codehaw…
1
34
Alejandro Betancourt retweeted
I practiced auditing on Puppy Raffle, CodeHawks' First Flight #1.
Found 6 of its 16 known issues and wrote 4 Foundry PoCs. The one I missed taught me the most.
refund() looks fine on its own. So does selectWinner().
But refund() doesn't remove you from players[]. It writes address(0) in your slot.
selectWinner() still counts that slot:
→ the winner can be address(0)
→ the prize math counts ETH that was already refunded
I reviewed each function separately. The bug lives in the state they share.
🔑 Audit the system, not the functions.
Findings + PoCs: github.com/alebeta06/codehaw…
I practiced auditing on Puppy Raffle, CodeHawks' First Flight #1.
Found 6 of its 16 known issues and wrote 4 Foundry PoCs. The one I missed taught me the most.
refund() looks fine on its own. So does selectWinner().
But refund() doesn't remove you from players[]. It writes address(0) in your slot.
selectWinner() still counts that slot:
→ the winner can be address(0)
→ the prize math counts ETH that was already refunded
I reviewed each function separately. The bug lives in the state they share.
🔑 Audit the system, not the functions.
Findings + PoCs: github.com/alebeta06/codehaw…
My property tests passed with 256 cases.
At 50,000, one failed. No sabotage.
The property said: if a swap works at a low price, it works at a higher one.
The counterexample: amount = 0. Price 1 → Ok(0). A huge price → MathOverflow.
In the reverse swap the price sits in the denominator. With 20+ decimals, price × 10^dec_b overflows u128 even when the real result fits.
The function wasn't unsafe: typed error, no panic, nothing leaves the pool. My property was false.
So I kept the half that's true, and documented the limit instead of reworking the math for 20+ decimal mints nobody uses.
🔑 proptest's default case count looks like a performance setting. It's a correctness setting.
nitter.cf/Ale_Beta/status/211002…
Repo: github.com/alebeta06/solana-…
New project: my first Solana program, coming from Solidity. A fixed-price SPL token swap in Rust + Anchor, deployed on devnet, with a Next.js frontend.
Anyone can create a market for two tokens and set its price. Anyone can add liquidity, and users swap in both directions at that price.
Stack: Rust + Anchor 1.2 for the program. Next.js, TypeScript and wallet adapter on the frontend. Devnet test tokens with Metaplex metadata and a public faucet that pays for your token accounts, so you can try it without asking anyone.
Inside, it made me deal with:
- Thinking in accounts instead of storage: PDA vaults and a canonical mint order, so one pair can't end up as two markets
- Not trusting the caller: token decimals are read from the Mint account, not passed as a parameter
- Property-based tests over the swap math: 500,000 generated cases found a panic that 27 integration tests missed
- A CI I sabotaged on purpose to check it can actually fail
5 instructions, 9 typed errors, 133 tests across three suites, and known limitations written down in the README. Educational code, not audited.
Try it on devnet (you'll need a little devnet SOL to swap), read the code, and tell me what you'd do differently:
Demo: solana-token-swap.vercel.app
Code: github.com/alebeta06/solana-…
Audio note: I recorded the video in Spanish. The English you hear is YouTube's auto-dubbed track, not my voice.
#Solana #rustlang
3
239
Alejandro Betancourt retweeted
I fixed a vulnerability in my Solana swap and opened a panic. A property-based test found it, not me.
The fix first. The reference code took token decimals as an instruction parameter, even though the Mint accounts were right there. Declare decimals_a = 0 on a 9-decimal mint and the math is wrong forever, because the value is stored when the market is created. Two lines fixed it: read the decimals from the Mint.
What that fix opened: the caller can no longer lie about decimals, but the program now accepts whatever the Mint says. And an SPL mint can have any u8, from 0 to 255.
10^38 fits in a u128. 10^39 doesn't. The code did 10u128.pow(decimals) unchecked, so with a mint of 39+ decimals every swap panicked instead of returning the MathOverflow error the program already had for exactly that case.
27 integration tests never saw it. They all use 6 and 9 decimals, the range real tokens live in, which is the range anyone tests by hand.
The property tests sample decimals across the full 0..255. Capping them at 38 would have been a test designed to pass. proptest shrank the failure to the smallest case that still broke: amount = 0, price = 1, dec_a = 0, dec_b = 39.
The fix is a pow10() that uses checked_pow and returns the typed error. Side effect I didn't expect: the program binary shrank by 1,984 bytes.
How the tests were made: Claude Code wrote them. I chose the four properties the math had to obey and checked each one by breaking the code on purpose until it went red.
What I take from it: moving trust from the caller to the Mint doesn't remove the input. It widens it. Validating where a value comes from means validating its range too.
nitter.cf/Ale_Beta/status/211002…
New project: my first Solana program, coming from Solidity. A fixed-price SPL token swap in Rust + Anchor, deployed on devnet, with a Next.js frontend.
Anyone can create a market for two tokens and set its price. Anyone can add liquidity, and users swap in both directions at that price.
Stack: Rust + Anchor 1.2 for the program. Next.js, TypeScript and wallet adapter on the frontend. Devnet test tokens with Metaplex metadata and a public faucet that pays for your token accounts, so you can try it without asking anyone.
Inside, it made me deal with:
- Thinking in accounts instead of storage: PDA vaults and a canonical mint order, so one pair can't end up as two markets
- Not trusting the caller: token decimals are read from the Mint account, not passed as a parameter
- Property-based tests over the swap math: 500,000 generated cases found a panic that 27 integration tests missed
- A CI I sabotaged on purpose to check it can actually fail
5 instructions, 9 typed errors, 133 tests across three suites, and known limitations written down in the README. Educational code, not audited.
Try it on devnet (you'll need a little devnet SOL to swap), read the code, and tell me what you'd do differently:
Demo: solana-token-swap.vercel.app
Code: github.com/alebeta06/solana-…
Audio note: I recorded the video in Spanish. The English you hear is YouTube's auto-dubbed track, not my voice.
#Solana #rustlang
Alejandro Betancourt retweeted
I sabotaged my CI and it stayed green.
That was the correct result.
Same type error, two runs:
❌ without `yarn typecheck` → green
✅ with it → red, tests never ran
Vitest doesn't check types. It strips them and runs the JavaScript.
So typecheck is its own step, before the tests.
🔑 A green check means nothing until you've seen it go red.
Repo: github.com/alebeta06/solana-…
nitter.cf/Ale_Beta/status/211002…
New project: my first Solana program, coming from Solidity. A fixed-price SPL token swap in Rust + Anchor, deployed on devnet, with a Next.js frontend.
Anyone can create a market for two tokens and set its price. Anyone can add liquidity, and users swap in both directions at that price.
Stack: Rust + Anchor 1.2 for the program. Next.js, TypeScript and wallet adapter on the frontend. Devnet test tokens with Metaplex metadata and a public faucet that pays for your token accounts, so you can try it without asking anyone.
Inside, it made me deal with:
- Thinking in accounts instead of storage: PDA vaults and a canonical mint order, so one pair can't end up as two markets
- Not trusting the caller: token decimals are read from the Mint account, not passed as a parameter
- Property-based tests over the swap math: 500,000 generated cases found a panic that 27 integration tests missed
- A CI I sabotaged on purpose to check it can actually fail
5 instructions, 9 typed errors, 133 tests across three suites, and known limitations written down in the README. Educational code, not audited.
Try it on devnet (you'll need a little devnet SOL to swap), read the code, and tell me what you'd do differently:
Demo: solana-token-swap.vercel.app
Code: github.com/alebeta06/solana-…
Audio note: I recorded the video in Spanish. The English you hear is YouTube's auto-dubbed track, not my voice.
#Solana #rustlang
Alejandro Betancourt retweeted
Spent two weeks building a rug-pull detector on Solana. Not the "we flag suspicious
tokens" kind — one with a measured number next to every alert.
The signal: the creator adds liquidity to its own token. 97.9% of those ended in a
drain (422 of 431, 431 distinct wallets), median 8 minutes of warning before the
pool went to zero.
The part nobody publishes: it only catches 65.3% of pool rugs. The other 35% are dev
dumps and migration pulls, where the drain IS the event — there is nothing to warn
about beforehand. That's on the dashboard, not buried in a footnote.
I also killed four of my own hypotheses with data. ">10 launches in 24h" as a signal:
1.0% precision. Sell-share before the drain: inverted once I fixed the liquidity
metric. Both documented as discarded, with the numbers that killed them.
Calibrated against 17M frames from one full night of mainnet, over Solami's Blur
stream. TypeScript, 242 tests, docker compose up and it runs. Without an API key it
replays a real recorded hour through the same detector.
@useSolami
I sabotaged my CI and it stayed green.
That was the correct result.
Same type error, two runs:
❌ without `yarn typecheck` → green
✅ with it → red, tests never ran
Vitest doesn't check types. It strips them and runs the JavaScript.
So typecheck is its own step, before the tests.
🔑 A green check means nothing until you've seen it go red.
Repo: github.com/alebeta06/solana-…
nitter.cf/Ale_Beta/status/211002…
New project: my first Solana program, coming from Solidity. A fixed-price SPL token swap in Rust + Anchor, deployed on devnet, with a Next.js frontend.
Anyone can create a market for two tokens and set its price. Anyone can add liquidity, and users swap in both directions at that price.
Stack: Rust + Anchor 1.2 for the program. Next.js, TypeScript and wallet adapter on the frontend. Devnet test tokens with Metaplex metadata and a public faucet that pays for your token accounts, so you can try it without asking anyone.
Inside, it made me deal with:
- Thinking in accounts instead of storage: PDA vaults and a canonical mint order, so one pair can't end up as two markets
- Not trusting the caller: token decimals are read from the Mint account, not passed as a parameter
- Property-based tests over the swap math: 500,000 generated cases found a panic that 27 integration tests missed
- A CI I sabotaged on purpose to check it can actually fail
5 instructions, 9 typed errors, 133 tests across three suites, and known limitations written down in the README. Educational code, not audited.
Try it on devnet (you'll need a little devnet SOL to swap), read the code, and tell me what you'd do differently:
Demo: solana-token-swap.vercel.app
Code: github.com/alebeta06/solana-…
Audio note: I recorded the video in Spanish. The English you hear is YouTube's auto-dubbed track, not my voice.
#Solana #rustlang
I fixed a vulnerability in my Solana swap and opened a panic. A property-based test found it, not me.
The fix first. The reference code took token decimals as an instruction parameter, even though the Mint accounts were right there. Declare decimals_a = 0 on a 9-decimal mint and the math is wrong forever, because the value is stored when the market is created. Two lines fixed it: read the decimals from the Mint.
What that fix opened: the caller can no longer lie about decimals, but the program now accepts whatever the Mint says. And an SPL mint can have any u8, from 0 to 255.
10^38 fits in a u128. 10^39 doesn't. The code did 10u128.pow(decimals) unchecked, so with a mint of 39+ decimals every swap panicked instead of returning the MathOverflow error the program already had for exactly that case.
27 integration tests never saw it. They all use 6 and 9 decimals, the range real tokens live in, which is the range anyone tests by hand.
The property tests sample decimals across the full 0..255. Capping them at 38 would have been a test designed to pass. proptest shrank the failure to the smallest case that still broke: amount = 0, price = 1, dec_a = 0, dec_b = 39.
The fix is a pow10() that uses checked_pow and returns the typed error. Side effect I didn't expect: the program binary shrank by 1,984 bytes.
How the tests were made: Claude Code wrote them. I chose the four properties the math had to obey and checked each one by breaking the code on purpose until it went red.
What I take from it: moving trust from the caller to the Mint doesn't remove the input. It widens it. Validating where a value comes from means validating its range too.
nitter.cf/Ale_Beta/status/211002…
New project: my first Solana program, coming from Solidity. A fixed-price SPL token swap in Rust + Anchor, deployed on devnet, with a Next.js frontend.
Anyone can create a market for two tokens and set its price. Anyone can add liquidity, and users swap in both directions at that price.
Stack: Rust + Anchor 1.2 for the program. Next.js, TypeScript and wallet adapter on the frontend. Devnet test tokens with Metaplex metadata and a public faucet that pays for your token accounts, so you can try it without asking anyone.
Inside, it made me deal with:
- Thinking in accounts instead of storage: PDA vaults and a canonical mint order, so one pair can't end up as two markets
- Not trusting the caller: token decimals are read from the Mint account, not passed as a parameter
- Property-based tests over the swap math: 500,000 generated cases found a panic that 27 integration tests missed
- A CI I sabotaged on purpose to check it can actually fail
5 instructions, 9 typed errors, 133 tests across three suites, and known limitations written down in the README. Educational code, not audited.
Try it on devnet (you'll need a little devnet SOL to swap), read the code, and tell me what you'd do differently:
Demo: solana-token-swap.vercel.app
Code: github.com/alebeta06/solana-…
Audio note: I recorded the video in Spanish. The English you hear is YouTube's auto-dubbed track, not my voice.
#Solana #rustlang











