Conversation

Article cover image

How a 'Verifier-Only' Function Became a $300K Back Door

4 min read
#[spec_only] looks like a safety label. It isn't one. Here's how one attribute shipped a public, unauthenticated entry point into production — and how to check your own Sui Move contracts.

How I introduced it

I trusted my code. I had written it carefully, reviewed it line by line, and — to be extra safe — added formal verification on top. I used Claude Code with the @AsymptoticTech sui-prover skill to generate proofs over the money-flow logic.

To let the proofs read private fields, the skill instructed the agent to add #[spec_only] getters — helper functions meant to be visible only to the verifier. The skill's documentation said two contradictory things:

  • One section: #[spec_only] getters are "only visible to the prover, not included in regular compilation."
  • Another section: private-field access should use #[test_only] accessors.

The agent followed the first claim. It was wrong — but I wouldn't learn that until the functions were already live.

Four #[spec_only] public fun forwarders went on-chain: spec_call_add_to_scallop_lending, spec_call_pull_from_scallop_lending, spec_call_add_to_kai_lending, spec_call_pull_from_kai_lending. Each took &mut PositionManager with zero authorization checks, forwarding directly to private lending helpers.


The disassembly that proved it

The report from white-hat researcher @mehvetero didn't accuse me of sloppy code. It was worse — it showed that the very code I'd added for formal verification was carrying a back door. He found it not by reading source, but by disassembling the deployed bytecode. The source made these functions look harmless (labeled "spec-only"); the bytecode made them look like what they were:

public spec_call_pull_from_scallop_lending<Ty0>(Arg0: &mut PositionManager, Arg1: u64):
B0:
    0: MoveLoc[0](Arg0: &mut PositionManager)
    1: MoveLoc[1](Arg1: u64)
    2: Call pull_from_scallop_lending<Ty0>
    3: Ret

Three instructions. No branch, no abort path, no assert_caller_authorized, no pm.owner == sender. A single programmable transaction could drain any user's lending assets — roughly $300,000 across the live positions.

He disclosed it privately, as a white hat, and helped me secure the funds before anyone else could reach them. The assets were saved.


The root cause, finally clear

So how did a function meant only for the verifier end up on-chain? The answer was hiding in a single line of source:

#[spec_only]                    // ← NOT a Move primitive. The compiler ignores this.
public fun spec_call_pull_from_scallop_lending<T>(pm: &mut PositionManager, ...)

#[spec_only] is not a Move language primitive. It's a custom attribute understood only by the sui-prover verification toolchain. The Move compiler doesn't know what it means, emits an "unknown attribute" warning, and compiles the function into production bytecode as a normal public fun.

Compare it to #[test_only] — that one is a compiler-native primitive. The compiler strips it from non-test builds. That's the entire difference — and it changes everything.

Attribute

Compiler-native?

What happens in sui move build

#[test_only]

✅ Yes

Stripped from production bytecode

#[random_test]

✅ Yes

Stripped from production bytecode

#[expected_failure]

✅ Yes

Stripped from production bytecode

#[spec_only]

❌ No

Ignored as a warning — function ships

No part of the production toolchain knows how to strip #[spec_only]. Only the prover recognizes it; the compiler never removes it.


The fix: remove #[spec_only] from the on-chain package entirely

Understanding the root cause didn't make it easy to fix. The deployed bytecode was frozen under an only_dep_upgrades policy — no hot patch possible. After an emergency asset rescue (draining the seven lending positions back to users), the source fix had two stages:

Stage 1 — remove the four dangerous forwarders. They became #[test_only] wrappers (compiler-stripped) plus unit tests covering the same accumulation/conservation properties the removed specs had proved.

Stage 2 — remove all #[spec_only]. The on-chain package still carried 14 read-only #[spec_only] probes. Harmless (immutable refs only), but they still leaked into production bytecode — the same class of problem. The decisive experiment: switch the spec package to a #[test_only] getter and confirm sui-prover still verifies across packages. It did — Verification successful. So all 14 were deleted, and the on-chain package reached zero #[spec_only].

The final architecture:

repo/
├── sources/cdpm.move ← on-chain: zero #[spec_only], private access via #[test_only]
├── specs/ ← spec package: never published, sui-prover only
└── scripts/check_no_spec_symbols.sh ← CI gate: any spec_ symbol = fail

Result: production bytecode has 0 spec/test symbols, the on-chain build emits 0 warnings, 5/5 unit tests pass, sui-prover verifies.


How to check your own contract (copy-paste)

1. Grep for the offending attribute in your on-chain package:

grep -rn "spec_only" sources/ # any hit = you're at risk

2. Disassemble your production bytecode and look for the symbols directly:

sui move build
strings build/<pkg>/bytecode_modules/<module>.mv | grep -E "spec_|test_only"

If spec_* appears, those functions are live on-chain — regardless of what the source comments claim.

3. Add a CI regression gate that fails the build on any spec/test symbol in production bytecode. This is the single highest-leverage fix: it converts "remember to remove" into "structurally impossible to ship."

4. Verify the toolchain claim, don't believe it. The sui-prover skill's documentation said #[spec_only] is "not included in regular compilation." That claim was false. The only reliable source of truth is the disassembly.


The checklist for other projects

  1. On-chain package: zero custom attributes. #[spec_only], #[ext(...)] — any attribute the compiler doesn't natively recognize is a stranger it tolerates but never removes.
  2. Private-field access for specs: use #[test_only] getters. It's the compiler-native alternative, and sui-prover supports reading them cross-package.
  3. Isolate, don't delete. Put all verification code in a separate package the publish pipeline never touches. Make "never ships" structural, not a manual step.
  4. Disassemble before you deploy. The bytes are the contract; the source is just a wish.

The uncomfortable truth at the center of it all:

An attribute that looks like a safety mechanism — "spec-only", "not shipped" — was exactly the thing that shipped a back door. The safest-looking label in my codebase was the most dangerous one.

Thank you, mehvetero

mehvetero disassembled the live bytecode, wrote a meticulous advisory (disassembly evidence, impact quantification, remediation guidance), and — as a white hat — disclosed it privately and helped secure the funds. His latest open-source project, move-test-gen, generates edge-case test suites and security lints for Sui Move. Worth following if you build on Sui.


Timeline

2026-08-18 mehvetero disassembles on-chain bytecode, finds the vulnerability
2026-08-18 Private advisory delivered (coordinated disclosure)
2026-08-19 Asset rescue: 7 lending positions drained, ~$300K returned to users
2026-08-19 Commit 1: remove 4 spec_call_* forwarders → #[test_only] + unit tests
2026-08-19 Commit 2: on-chain package reaches zero #[spec_only]
@pikapikasui
Real man, not robot | DevRel Lead @CetusProtocol | Shipped @leafsheepfi | @SuiNetwork Ambassador Alumni | Sword Guardian @SuiSecurity | INTP from @Tsinghua_Uni
Join 2,146 followers
1:39 AM · Aug 19, 2026
19.6K
Views