Test your Stellar code on the ledger data that breaks it.

shapekit is a shared test kit for Stellar SDKs and indexers. It holds rare but valid ledger shapes, most of them recorded on a real stellar-core, and the tools that run them through your code.

Corpus 0.2.0Protocol 30Apache-2.0
1The corpus1,092 rare but valid shapes970 written by stellar-core104 synthetic18 refused by stellar-coreCoverage
2Runs through your codeSDKs and indexers
SDK conformance runner 11 targetsRustGoJavaScriptPythonJavaDartPHP.NETKotlinsoroban-sdkstellar-cli
Indexer replay harness 3 indexerswallet-backendstellar-rpcstellar-etl
Plus indexerlint for Go indexer code.Every target
3Finds what breaks57 findings14 data loss2 wrong data24 divergence17 robustness42 issues filed13 reproducedEvery finding

Every finding comes with its smallest corpus entry and the command that runs it again.

The problem

Rare data is still valid data.

Shapes like these are rare on the network, so tests do not cover them. Each one below broke software that the ecosystem uses. Each team found its bug alone.

When a SetOptions adds a signed-payload signer,

wallet-backend retried ledger 65 forever.

CAP-40 · wallet-backend#729

When a muxed account is the source of a Soroban call,

wallet-backend stored one account twice and stopped.

CAP-27 · wallet-backend#753

When the Stellar Asset Contract creates a trustline with no event,

wallet-backend wrote no trustline row.

CAP-73 · wallet-backend#731

When two map keys become one key in JavaScript,

js-stellar-sdk merged the two entries into one.

Soroban · js-stellar-sdk#1789

When the network orders pool assets by key bytes, not by text,

js-stellar-sdk refused valid pool pairs.

CAP-38 · js-stellar-sdk#1766

When an auth chain is 988 levels deep and stellar-core stops at 493,

go-stellar-sdk decoded it anyway.

Soroban · go-stellar-sdk#6047

shapekit gives every team the same shapes, and the tools to run them.

See every shape in the corpus

How it works

From a real stellar-core to your code.

Follow one chain: cap40.signed-payload-signer.p30

  1. Record

    A recipe runs on stellar-core 30.0.0, on a Docker network with no route off the host.

  2. Check

    Each entry re-encodes to the same bytes under both passphrases and agrees with the goldens of stellar-core.

  3. SDK conformance runner

    Sends each entry to an SDK. Writes a divergence matrix.

  4. Replay harness

    Serves the recorded chain to an indexer. Reads back what it stored.

  5. Report

    Groups failures by finding, with the smallest entry and the command that runs it again.

How it knows what is correct

The right answer is written down before any SDK runs.

Every entry in the corpus carries its own expected answer. shapekit compares your code with that answer, not with another SDK.

The 1,092 entries, by expected answer. Select a group to open one real entry.

  1. 1
    stellar-core wrote most of them. 970 entries are bytes that stellar-core wrote into a ledger.
  2. 2
    They round-trip. Each entry decodes and re-encodes to the same bytes under both passphrases. shapekit manifest validate
  3. 3
    They agree with stellar-core's own tests. The corpus is checked against the goldens of stellar-core. shapekit goldens agree

Corpus entry

cap40.signed-payload-signer.p28-account-four-payload-signers

An account entry with four signed-payload signers: 1, 4, 32 and 64 byte payloads, one of them sponsored.

Bytes from
stellar-core 30.0.0, ledger protocol 28, chain cap40.signed-payload-signer.p28
Expected
Decode it. Re-encode it to the same bytes. Render it as the expected XDR-JSON.
An SDK passes when
its bytes and its JSON are equal to the expected ones.

Corpus entry

cap23.claimable-balances.synth-strkey-b-invalid

Claimable balance IDs written as strkeys that are not valid: wrong lengths, set trailing bits, padding and lowercase.

Bytes from
Synthetic. A strkey is valid only if re-encoding it gives back the same text (SEP-23 1.4.0).
Expected
Refuse each one, as stellar-strkey 1.0.0 does.
An SDK passes when
it refuses the text. go-stellar-sdk accepted one of them: finding GO-1.

Corpus entry

soroban.scval-shapes.synth-bool-value-2

An ScVal bool with the value word 2. A bool must be 0 or 1, but the references do not agree on this value.

Bytes from
Synthetic. stellar-core reads the word as true. stellar-xdr reads it as false.
Expected
No single answer. shapekit does not take a vote. It keeps every answer in the matrix:
truestellar-core, Python, Dart, Kotlin
falseRust, .NET
refusesGo, JavaScript, Java, PHP

For an indexer, the ledger itself is the judge.

To test an indexer, you need the right answer for each transaction. There are three places to get it.

Option 1

Another indexer

Compare your rows with its rows. If both indexers have the same bug, the bug passes.

Option 2

Rows you write by hand

You test only the cases that you think of, and each new case is more work.

shapekit

The ledger

stellar-core already wrote what each transaction did into the transaction meta. The harness reads the answer from there, so every one of the 1,652 replays has its answer, and nobody writes it by hand.

Then each fact gets one result.

passThe indexer stored the same value.
droppedThe indexer stored nothing.
mishandledA wrong value, an extra fact or a stop.

Coverage

Coverage you can count, square by square.

98.9%

436 of 441 union arms that a ledger can hold have an entry from stellar-core.

499 squares, one for each union arm: 436 covered, 47 refused before a ledger, 11 never emitted by stellar-core, 5 for other reasons

1,092corpus entries, by source:
  • 844 recorded from a local stellar-core
  • 107 from the stellar-core test goldens
  • 19 from network history
  • 104 synthetic inputs
  • 18 inputs that stellar-core refuses
44CAPs that an indexer can see, each with an entry from stellar-core.
30/30fields that stellar-core does not fully validate are in the corpus.
shapekit coverage --check fails when these counts are out of date.Coverage for each CAP

What it found

Every square is a real bug report.

57findings in 11 components.42 issues filed upstream by shapekit. 13 issues reported before by others, now reproduced. 13 more records are intended behavior and are not filed.
wallet-backendIndexer
go-stellar-sdkGo SDK
js-stellar-sdkJavaScript SDK
rs-stellar-xdrRust XDR
stellar-coreValidator
stellar_flutter_sdkDart SDK
soneso/stellar-php-sdkPHP SDK
stellar-dotnet-sdk.NET SDK
kmp-stellar-sdkKotlin Multiplatform SDK
stellar-cliCLI
stellar-etlIndexer

What it runs against

The table of every SDK it tests.

0130.0.0RsRuststellar-xdr
02v0.9.0GoGogithub.com/stellar/go-stellar-sdk
0317.4.0JsJavaScript@stellar/stellar-sdk
0417.0.1PyPythonstellar-sdk
056.0.0JvJavanetwork.lightsail:stellar-sdk
063.13.0DtDartstellar_flutter_sdk
071.19.0PhPHPsoneso/stellar-php-sdk
0817.0.0Ne.NETstellar-dotnet-sdk
091.19.0KtKotlin Multiplatformcom.soneso.stellar:stellar-sdk-jvm
1030.0.0Sbsoroban-sdksoroban-sdk
1130.0.1Clstellar-clistellar-cli
11SDK targets at their current release. Older versions run too, to find where a bug starts and ends.

3 indexers. The same replays for each.

Indexer results
wallet-backendreference adapterFound wrong or missing rows in 222 replays10 reported findings

wallet-backend: 1,206 pass, 166 mishandled, 56 dropped

stellar-rpcrelease imageFound no wrong or missing rows

stellar-rpc: 1,416 pass

stellar-etlv2.8.35Found wrong or missing rows in 28 replays3 reported findings

stellar-etl: 1,388 pass, 28 dropped

passmishandleddropped

Proof on real bugs

It catches bugs that already happened.

Their own teams found and fixed these 13 bugs. shapekit goes back to the version just before each fix and runs the corpus on it. The run must fail there, and pass on the version with the fix.

13known bugs, run again from their own versions
13 of 13fail on the version before the fix
13 of 13pass on the version with the fix

wallet-backendIndexer, by commit

js-stellar-sdkSDK, by release

go-stellar-sdkSDK, by release

rs-stellar-xdrSDK, by release

wallet-backendBug 1 of 13
Signed-payload signer stops ingestion

A SetOptions adds a signed-payload signer. Ingestion retried ledger 65 forever.

Before the fixmishandled: halted

wallet-backend stopped at ledger 65 with an error.

With the fixpass

Every fact of the entry is stored with the same value.

Runs next.

Corpus entry cap40.signed-payload-signer.p28-set-options-payload-1-metashapekit harness reproduce fails if either result is wrong.

The indexer-hardening guide

88 envelope fields. Which ones does stellar-core check?

tx.envelope.type tx.v0.source_account_ed25519 tx.signatures tx.signatures.hint tx.signatures.signature tx.source_account tx.source_account.mux_id tx.fee tx.seq_num tx.cond.type tx.cond.time_bounds tx.cond.ledger_bounds tx.cond.min_seq_num tx.cond.min_seq_age tx.cond.min_seq_ledger_gap tx.cond.extra_signers signer_key.signed_payload.payload tx.memo.type tx.memo.text tx.memo.id tx.memo.hash tx.memo.return tx.operations tx.ext tx.soroban.resource_fee tx.soroban.resources.limits tx.soroban.footprint tx.soroban.ext.archived_soroban_entries feebump.fee_source feebump.fee_source.mux_id feebump.fee feebump.signatures feebump.inner_tx op.source_account op.source_account.mux_id op.create_account.destination op.create_account.starting_balance op.payment.destination op.payment.destination.mux_id op.payment.asset op.payment.amount op.path_payment.destination op.path_payment.destination.mux_id op.path_payment.amounts op.path_payment.path op.manage_offer.offer_id op.manage_offer.assets_amount_price op.set_options.home_domain op.set_options.inflation_dest op.set_options.signer op.set_options.thresholds_and_flags op.change_trust.line op.change_trust.line.liquidity_pool op.change_trust.limit op.allow_trust op.manage_data.data_name op.manage_data.data_value op.bump_sequence.bump_to op.create_claimable_balance.claimants.destination op.create_claimable_balance.claimants.predicate op.create_claimable_balance.asset_amount op.claim_claimable_balance.balance_id op.clawback.from op.clawback.from.mux_id op.clawback.asset_amount op.clawback_claimable_balance.balance_id op.set_trust_line_flags op.begin_sponsoring.sponsored_id op.revoke_sponsorship op.account_merge.destination op.liquidity_pool_deposit op.liquidity_pool_withdraw op.invoke_host_function.invoke_contract.contract_address op.invoke_host_function.invoke_contract.function_name op.invoke_host_function.invoke_contract.args op.invoke_host_function.upload_wasm op.invoke_host_function.create_contract.preimage op.invoke_host_function.create_contract_v2.constructor_args op.invoke_host_function.auth auth.credentials.source_account auth.credentials.address.address auth.credentials.address.nonce auth.credentials.address.signature_expiration_ledger auth.credentials.address.signature auth.credentials.address_with_delegates.delegates auth.root_invocation op.extend_footprint_ttl.extend_to op.restore_footprint

indexerlint

Three rules from the guide, checked in your Go code.

Do not trust a field that stellar-core does not check.

Put a cap on depth and size when you decode.

For indexers built on go-stellar-sdk. For other languages, the guide has the same checks as a checklist.Rules, suppressions and baselines

Fuzzing

113,063 inputs. Eight classes. One cause.

Inputs that got different answers flow into eight classes, one for each type that carries a bool, and the eight classes flow into one cause

113,063inputs with different answersContractEventLedgerCloseMetaLedgerEntryScValSorobanAuthorizationEntryTransactionEnvelopeTransactionResultMetaTransactionResultMetaV11 causea bool word of 2

The differential fuzzer sends the same input to rs-stellar-xdr and go-stellar-sdk. In its first run, 113,063 inputs got different answers. They fell into eight classes, one for each type that carries a bool, and all eight had one cause.

How the fuzzers work

The coverage-guided search runs the Rust, Go and JavaScript SDKs side by side. An input that reaches new code in one SDK goes to the other two. With this feedback, each SDK reached more code in 100,000 inputs:

Rust16,010 to 16,128 code ranges+118
Go6,446 to 6,529 code ranges+83
JavaScript4,086 to 4,106 code ranges+20

Stays current

Ready for the next protocol before it ships.

Corpus entries by the protocol of their ledgerProtocol 31: rehearsed

988 recorded corpus entries by protocol: 1 at protocol 1, 9 at protocol 9, 6 at protocol 10, 3 at protocol 11, 42 at protocol 12, 18 at protocol 14, 2 at protocol 15, 57 at protocol 17, 1 at protocol 18, 37 at protocol 19, 10 at protocol 20, 7 at protocol 21, 71 at protocol 22, 14 at protocol 23, 14 at protocol 24, 1 at protocol 25, 9 at protocol 26, 2 at protocol 27, 63 at protocol 28, 4 at protocol 29, 617 at protocol 30. Protocol 31 is rehearsed.

Local stellar-core 844stellar-core test goldens 107Mainnet and testnet history 19Refused by stellar-core 18

The 104 synthetic entries have no ledger, so they have no protocol.

Every Monday

Upstream changes open an issue.

A scheduled job checks stellar-core, the XDR definitions, every SDK and stellar-cli. A new release opens a tracking issue with the upgrade checklist and a first run against the new version.

Before protocol 31

The upgrade is already rehearsed.

On the next-protocol build of stellar-core, all 144 transaction test cases pass at every protocol from 0 to 31, and 452,555 transaction metas convert with every hash matching.

Through protocol 31

A named maintainer, then an open runbook.

Eren Topal maintains shapekit through the protocol 31 upgrade. The runbook, the corpus format and the interfaces are documented, so anyone can continue.

Get started

I want to

  1. Check that you have the tools for the JavaScript SDK.
    shapekit doctor sdk --sdk js
  2. Run the corpus against @stellar/stellar-sdk 17.4.0.
    shapekit check sdk --sdk js
  3. Read the divergence matrix in target/conformance/MATRIX.md.

Use --sdk go, rust, python or another SDK. Leave it out to check every SDK.

Install shapekit Run it in the CI of an SDK Put your own SDK behind shapekit
  1. Pull the pinned database image. You need Linux and Docker.
    docker pull "$(scripts/pin.sh image timescaledb)"
  2. Replay one chain into wallet-backend.
    shapekit check indexer --adapter "adapters/bin/wb-adapter --commit $(scripts/pin.sh git wallet-backend)" --chain cap40.signed-payload-signer.p30
  3. Read the results in harness-out/HARNESS.md.
  1. Run indexerlint on your Go indexer module.
    shapekit lint <your indexer>
  2. Keep known findings in a baseline file. Fail only on new ones.
    shapekit lint <your indexer> --baseline indexerlint-baseline.json --json

indexerlint and the Go toolchain must be on PATH.

Install shapekit indexerlint rules