Skip to content
Prashant Chaudhari
Go back

My own server carries every byte and still can't read or forge one: from borrower to Solana pool in six hops

Edit page

TL;DR: In TEE Income Oracle my gateway touches every message and still can’t read the statement or change the tier, because each hop is signed, encrypted or bound to a one-time value. What a carrier can still do is stop the bytes, so availability isn’t protected. The enclave doesn’t trust its own clock either. On Solana the last hop works because the pool derives the attestation address from the wallet that signed the borrow, so a borrower can only ever reach their own tier. If you came for the Solana part, jump to the PDA section.

This is part 2 of 3 on how TEE Income Oracle works.

  1. A bank statement goes in, a risk tier comes out: the trust model of an income oracle on Solana
  2. My own server carries every byte and still can’t read or forge one: from borrower to Solana pool in six hops
  3. The crypto held, the restarts didn’t: what breaks first in an enclave oracle

Part 1 set up the trust model: an enclave scores a bank statement, and everything outside it, including my own gateway, is treated as hostile. This post walks one session through to show what that means in practice, from the borrower’s first click to the Solana pool that lends against the result. The scope is the same: Solana devnet and a sandbox bank I wrote.

If you want the other end of this, the browser page that refuses to show a tier until Solana agrees, read The browser doesn’t trust the server. It is the same idea from the frontend side.

One session, end to end

Here is the happy path, trimmed to the steps that matter. The full sequence is in the repo’s architecture doc.

One TIO session, step by step Eleven numbered steps between the borrower, the gateway, the enclave, the bank and Solana. The borrower starts a session. The bank returns an AA-signed consent. The gateway asks the enclave for a new session, and the enclave returns a signed data request. The borrower signs the intent with their wallet. The gateway carries the signed request to the bank, which returns the encrypted statement. The gateway sends the raw bytes to the enclave, which verifies, decrypts, scores and wipes, then returns the tier and a signature. The gateway submits the result to Solana. The borrower borrows against the attestation. Borrower Gateway Enclave Bank Solana verify, decrypt, score, wipe 1 start 2 AA-signed consent 3 session 4 request 5 wallet sig 6 signed request 7 encrypted data 8 raw bytes 9 tier + sig 10 submit 11 borrow
  1. The borrower starts a session with the gateway, giving a wallet and a test borrower profile (a persona).
  2. The gateway asks the sandbox bank for consent, and gets back a consent signed by the AA.
  3. The gateway asks the enclave to create a session, passing the policy, the wallet and the consent.
  4. The enclave returns a signed data request. The new session key was created inside it.
  5. The borrower signs the session intent with their wallet.
  6. The gateway carries the signed request to the bank, unchanged.
  7. The bank returns an encrypted statement with signatures.
  8. The gateway hands the raw bytes to the enclave. The enclave verifies, decrypts, scores and wipes.
  9. The enclave returns an 83-byte payload and a signature.
  10. The gateway submits it to Solana, where a secp256k1 check runs and a SAS attestation is created.
  11. The borrower borrows against the attestation.

Notice who does what. The gateway (my server) is in the middle of nearly every step. The enclave is in steps 3, 4, 8 and 9. The gateway never holds a key that matters.

What the gateway can and can’t do

The gateway touches every message and can still do very little. This table shows what it sees at each hop and what it can’t do:

HopThe gateway/host seesIt canIt cannot
Session createPublic key material and the signed requestRead public keysChange the key (the signature covers it) or swap the enclave’s request key (the bank checks a binding signature)
Bind walletThe intent and the wallet signatureDrop itBind a wallet it doesn’t control
FetchCiphertext and signed envelopesStore itDecrypt it or alter it (the AES-GCM tag and signatures break)
EvaluateRaw bytes in, signed payload outReplay old bytesGet them accepted (one-time session nonce)
SubmitThe Solana transactionCensor itChange the tier (the signature breaks)
BorrowNothing relevantNothingUse another wallet’s attestation, a stale one, or one from a build the pool hasn’t approved

Read the “cannot” column as a list of the reasons each hop holds:

One more rule sits under all of this: verify before parse. The enclave checks signatures with pinned keys before it parses anything, so hostile bytes never reach the parser. The keys are compiled into the image. That is the cost: rotating one means shipping a new build. I accept it, because it is the point of the second move in part 1: a key compiled into the measured image can’t be swapped by the host.

Why plain HTTP is fine

The enclave talks plain HTTP to the gateway. That sounds wrong, and it’s fine for a specific reason: every byte that matters is signed or encrypted end to end. The enclave produces signed requests and consumes signed responses. Whoever carries them can’t change them.

That covers integrity. It does not cover availability. The enclave’s port is public, so anyone who can get consents can fill its 256 open-session slots and lock other borrowers out. The gateway rate-limits session creation, and I accept this as a liveness risk. The host and gateway can already deny service anyway, so availability was never something this design could promise. The last column of the table says “censor it” for a reason.

The enclave’s clock is not trusted

There is one more thing a carrier controls: time. The host runs the enclave’s clock, so the enclave can’t be asked what day it is.

So the scoring window doesn’t come from the clock. It comes from the statement’s own dates, which must sit inside the range the enclave requested and inside the signed consent. Freshness is checked on chain, against the Solana clock. The check allows five minutes of skew, and a signature is usable for ten minutes after it is issued.

The cost is that the limits are fixed. A submission that arrives after the ten-minute window is rejected.

The Borrow hop on Solana: a PDA is the permission check

The last two hops are the ones on Solana: the gateway submits the enclave’s signed result, and the borrower borrows against it. This section assumes you know what a PDA is (a Program Derived Address, an address derived from seeds that only the deriving program can sign for) and roughly how an Anchor program is laid out.

What lives on chain

Four things on Solana carry the weight.

Nothing personal goes on chain. The attestation carries a tier, ids, hashes and timestamps, in an 83-byte payload.

The address is the permission check

Most access control in a program is a check you write: require!(caller == owner). Here the check is the address itself.

The tier is stored as a Solana Attestation Service (SAS) attestation, a standard credential any program can read. Its address is a PDA derived from the seeds attestation, the credential, the schema and a nonce, and the nonce is the borrower’s wallet. In the pool’s borrow instruction the borrower account must sign, and the attestation account’s seeds use that key. The credential and schema come from the pool’s own config. The pool doesn’t accept an attestation account the caller points at. It derives the address from the signer and reads that account.

So the borrower can only reach their own tier. To use someone else’s income, they would have to sign as that wallet. No comparison in my code can be forgotten, because there is nothing to compare: the wrong tier has no address the pool will ever derive. The payer can be a different account, such as a relayer, but only the borrower’s own key decides which attestation is read.

How the pool finds a borrower's tier The borrow transaction is signed by wallet W. The pool derives the attestation address from the seeds attestation, credential, schema and a nonce equal to W, then reads the account at that address. It checks that the credential and schema are the pinned ones, that the signer is the oracle's PDA, that the attestation is fresh, that the enclave build is approved and active, and that the policy hash matches. Then the borrow is allowed. A tier written for a different wallet sits at a different address, which the pool never derives from W, so W cannot point at it. Borrow transaction, signed by wallet W Pool derives the address from W seeds: attestation, credential, schema, nonce = W Pool reads the account at that address Pool checks what it read ✓ credential and schema are the pinned ones ✓ signer is the oracle's PDA ✓ attestation is fresh ✓ enclave build approved and active ✓ policy hash matches Borrow allowed ✕ Another wallet's tier sits at a different address. The pool never derives it from W.

The pool still checks what it reads. The address pins the credential and schema. The pool requires the stored signer to be the oracle’s own derived address, so a foreign credential can’t pass. It also checks freshness, that the enclave build is approved and still active, and the policy hash. That is the G6 link from part 1.

The oracle’s signer is a PDA too

The SAS credential has an authorized signer. In TIO that signer is a PDA of the oracle program, derived from the seed sas_signer. It has no private key.

That matters for two reasons. It can’t be stolen, because there is nothing to steal. And only the oracle program’s logic can sign with it, which means a tier can be written only after the program has checked the enclave’s signature against the registry. The enclave never writes to chain itself. It signs a payload, and the program decides whether to turn that into an attestation.

A signature that can’t be replayed

What the enclave signs is domain-separated. The signed bytes cover a tag, the program, the credential, the schema, the wallet, the payload and an expiry. Each part closes a replay:

Replacing a tier follows one more rule: a refresh must carry a strictly newer issued_at for that wallet. Without it, someone could resubmit an older, better signature over a newer, worse tier. A refresh closes the old attestation and creates a new one, and submit_attestation does both itself. The relayer gets the old rent back and pays the new rent, so a refresh costs about nothing. The SAS attestation expires 30 days after issued_at, and the pool adds its own limits on attestation age, statement age and statement length.

Why SAS and not a custom program

Pro. A tier written as a standard credential is readable by any pool that reads SAS, not just mine.

Con. I depend on someone else’s program. The rent for an attestation (about 0.002 SOL) stays locked until the same wallet refreshes, because I haven’t built a close path for expired attestations.

Why secp256k1, and what it costs

The enclave signs with a secp256k1 key because Oyster gives each enclave one at boot. So the oracle uses Solana’s secp256k1 precompile rather than the native ed25519 one.

Pro. Solana verifies the signature in a built-in instruction, and the key type is platform-neutral, so changing the TEE never changes the on-chain check.

Con. Every transaction carries an extra instruction and the bytes that go with it.

There is also a classic bug class here. The program never verifies the signature itself. The precompile does, one instruction earlier, and the program reads back what the precompile was given. The instruction-index fields in the precompile instruction must point at the precompile itself, or an attacker can make the check pass against other data. I test that case explicitly. If you copy this pattern, test it too. The five checks, and the attack each one stops, are in Don’t pass the signed bytes twice.

How the attested key is tied to this exact code (G3 and G4) is covered in Seven checks: verifying an AWS Nitro attestation in the browser.

What this doesn’t cover

The registry is still the weak link, G5 from part 1. An admin registers the enclave key, and in the demo that same wallet is also the program upgrade authority. The PDA design protects borrowers from each other. It doesn’t protect anyone from a stolen admin key. That, and what I’d change, is in part 3.

Where to look yourself

Previous: part 1, the trust model. Next: part 3 looks at what breaks first.


Edit page
Share this post on:

Previous Post
The crypto held, the restarts didn't: what breaks first in an enclave oracle
Next Post
A bank statement goes in, a risk tier comes out: the trust model of an income oracle on Solana