DocumentationProtocol Spec~5685 words
Source: docs/protocol/SPEC.en.md

#NACRE Protocol Specification

This page is the protocol for NACRE, written for someone building an indexer or a wallet from the current code. Every price, fee, and output below can be recomputed with integer arithmetic. The first keyless launchpad on Pearl.

The rules were checked on a local Pearl test chain. There is no external audit yet. Mainnet figures are pending, and every number below is from that local run or from the current code.

#Status

A local test chain run on 2026-11-22 confirmed a launch, curve buys, a transfer, a curve sell, fills through all 800 layers, the harvest that moves the pool into the on-chain market, and market buys and sells. The same run reorganized two blocks and, after replay and an indexer restart, matched pool balance, holdings, trades, and candles. The record is the end-to-end report. A separate local run recorded curve sells between 2,150 vB and 2,220 vB. Those runs do not replace an external audit.

#How to read this page

NACRE is the product. Pearl is the chain. PRL is the native coin. A pearl is one token launched on NACRE. The pool is the script-locked output that holds that pearl's PRL. The pool is keyless: it has no private key, and it can move only when a transaction satisfies one of its scripts.

A layer is one position on the curve. The code stores the layer index in step, from 0 through 800. The code stores the number of layers in one trade in lots. This page says "layer" in prose and uses those names only for fields. Selling all 800 layers moves the pearl to the on-chain market. The product name for that move is harvested. The code calls the transaction graduate. This page says harvested after this sentence.

Amounts of PRL are in grain. 1 PRL is 100,000,000 grain. Token amounts are whole tokens, never a fraction. Do not store either amount in floating point.

Inside a transaction, a txid is in internal byte order: reverse the 32 display bytes, then append the 4-byte little-endian output index. Amounts of PRL are 8-byte little-endian grain. A token amount a is the 4-byte field AMT(a) = le32(a + 2^24). That encoding is also the shortest script number for a. AMT(0) is the bytes 00 00 01 00. a is an integer from 0 through 1,000,000,000.

The modules below are the source of the rules. When an older design note disagrees with them, follow the code.

ModulePathWhat it fixes
Curve pricepackages/protocol/src/curve/price.ts, curve/pool.tsReserve table, leaf order, Taproot tree
State and token leavespackages/protocol/src/token/state.ts, token/leaf.ts61-byte record, 24 token leaves, provenance
Curve buypackages/protocol/src/pool/leaf.ts, pool/build.tsBuy leaf, witness, launch layout
Curve sellpackages/protocol/src/poolsell/leaf.ts, poolsell/build.tsSame template, sell constants
Launchpackages/protocol/src/launch/index.ts, launch/genesis.ts, launch/envelope.tsCommit, reveal, inscription
Harvestpackages/protocol/src/graduate/leaf.ts, graduate/tx.tsLast curve state to the market pool
Marketpackages/protocol/src/market/price.ts, graduate/amm/leaf.ts, graduate/amm/tx.tsMarket table and its buy and sell leaves

#Parameters

#Constants

ItemValueName in code
1 PRL100,000,000 grainGRAINS_PER_PRL
Total supply1,000,000,000 tokensTOKEN_SUPPLY
Tokens in one layer1,000,000TOKENS_PER_LOT
Curve lengthLayers 0 through 800. 800 layers are sold on the curve. 200,000,000 tokens stay in the pool for the marketCURVE_LOTS = 800
Curve trade sizes1, 2, 5, 10, 20, or 50 layersALLOWED_STEP_LOTS
Opening pool C[0]10,000 graininitialPoolGrains
Virtual token reserve x1,075,000,000 tokensvirtualTokenReserveTokens
Virtual PRL reserve y103,125,000,000 grainvirtualPrlReserveGrains
Platform trade fee100 bps (1%), rounded upDEFAULTS.tradeFeeBps
Launch fee500,000,000 grain (5 PRL), unless an operator sets another canonical valueLAUNCH_FEE_GRAIN
Token output value1,000 grainTOKEN_UTXO_VALUE
Smallest change a builder will emit1,000 grainminOutputGrains
Relay dust reference330 grainp2trDustGrains
Commit change dust333 grain. A smaller commit change is omittedlocal constant in the launch builder
Market states-1,610 through 4,607, which is 6,218 statesAMM_MIN_STATE, AMM_MAX_STATE
Market trade sizes1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377AMM_STEPS
Pool-move size cap3,000 vB. A builder throws past thisMAX_POOL_TX_VBYTES
Leaf version0xc0curve tree and market tree
Internal keyThe BIP 341 point with no known private keyTAPROOT_UNSPENDABLE_KEY
Mainnet fee addressprl1phern7h3fyflh9e33f5qqzzm7v332jtrjsgcdepvru82dv0kscdxq02h0aqPLATFORM_FEE_ADDRESS

The published curve file is curve-params.json. Its SHA-256 is 3f6f9809b360cfaedfa95523c7629f7596a94fe07e8712c40124fe8418b4d953. The published market file is amm-table.json. Its SHA-256 is 21fd439f7639d050572e6a24a7073919cd659f568be66baf07d3de26ba075fb6. Recompute both from the formulas in this page. Do not use floating point.

#Which fee value is accepted

The platform trade fee is 100 bps (1%). NACRE indexes a launch only when the inscription and the price table both use that rate. Any other rate is rejected and is not recorded as a pearl. The decoder error is trade fee N bps rejected; platform rate is 100 bps.

Three library checks are wider than that rule, and they are not the indexing rule:

CheckIntegers it accepts
makePriceTable0 through 10,000
Inscription parser validateTradeFee, genesis, and the market table1 through 10,000. A fee of 0 fails while the inscription is built
Decoder, by default100 only

The leaves do not read the fee rate back. They contain the fee amount in grain, computed when the tree was built. A tree built at another rate can still be a valid script. NACRE does not list it. The on-chain scripts were not given a second copy of the number 100. The rate comes from DEFAULTS.tradeFeeBps.

The launch fee is separate. The decoder compares the launch-fee output with the canonical value trees.launchFee, then expectedLaunchFee, then DEFAULTS.launchFeeGrains (5 PRL). It does not compare the output with the amount the transaction claims. A short payment is launch fee mismatch and is not listed. If an operator changes the launch fee, the indexer has to pass that same value into the launch resolver or a correct launch is rejected too.

The miner fee is separate again. It is paid in grain from the spender's own PRL and is not subtracted a second time from a sell refund.

On mainnet the fee address must be PLATFORM_FEE_ADDRESS. On a test network the same configured address has to appear in the tree, the decoder, and the queue.

#Curve reserves

Let sold = step * 1,000,000, the tokens already sold at layer step.

text
C[0] = 10,000
C[step] = C[0] + floor(103,125,000,000 * sold / (1,075,000,000 - sold))

step runs from 1 through 800. Each reserve must be strictly larger than the one before it, and no reserve may exceed 2^63 - 1 grain. The division is integer division. Writing the same formula in layers, floor(103,125,000,000 * i / (1,075 - i)), is the same number, because i layers are i * 1,000,000 tokens and the virtual token reserve scales the same way.

Check values from the default table:

LayerPool reserve
010,000 grain
196,029,553 grain
2192,228,080 grain
800300,000,010,000 grain

Layer 1 is the worked example. sold = 1,000,000. The fraction is floor(103,125,000,000 * 1,000,000 / 1,074,000,000) = 96,019,553. Adding the opening 10,000 grain gives 96,029,553 grain.

Inventory written into output 0 is tokens, not layers:

text
Y(step) = 1,000,000,000 - step * 1,000,000

Layer 0 holds the full 1,000,000,000 tokens. Layer 800 holds 200,000,000 tokens.

#Quotes and the platform fee

quoteBuy and quoteSell use the reserve table:

text
D = abs(C[stepTo] - C[stepFrom])
F = ceil(D * tradeFeeBps / 10,000) = (D * bps + 9,999) // 10,000
buy settlement = D + F
sell settlement = D - F

At 100 bps, F = (D + 99) // 100. For the layer 0 to layer 1 buy, D = 96,019,553 grain and F = 960,196 grain. The buyer settles 96,979,749 grain. After the buy, the pool output must equal C[1] and the platform-fee output must equal F.

On a sell, the miner fee comes out of the seller's own PRL input. It is not subtracted again from D - F.

A market trade uses the same ceiling on abs(X_to - X_from). The market leaf builder also refuses a platform fee below 1,000 grain. The curve quote has no second floor.

#Leaf order on the curve

enumerateTransitions walks step from 0 through 799. At each layer it emits buys first, from the smallest trade size to the largest, keeping only sizes with step + lots <= 800. It then emits sells, keeping only sizes with step >= lots. Layer 800 has no sell leaf. The last leaf in the tree is the harvest leaf.

With the default sizes that is 4,718 buys, 4,712 sells, and 1 harvest leaf: 9,431 leaves. Count them from the rule above rather than hard-coding the total in a second place.

#Market table

At harvest, X_0 = C[800] = 300,000,010,000 grain and Y_0 = 200,000,000 tokens. The constant product is k = X_0 * Y_0.

Token reserves move away from Y_0 by the 60-decimal fixed-point factors 5^(1/1610) and 5^(-1/1610), then round half to even. The PRL reserve is ceil(k / Y_s). State -1,610 is fixed at Y_0 * 5 = 1,000,000,000 tokens, which is the whole supply. Neighboring states must have a strictly smaller token reserve and a strictly larger PRL reserve, so the PRL in the pool identifies exactly one state (stateFromPoolAmount).

Use these integers. SCALE = 10^60. A half-even rounding of a scaled value scaled takes the integer whole = scaled / SCALE. It rounds away from zero when 2 * (scaled % SCALE) > SCALE, and also when the remainder is exactly one half and whole is odd.

DirectionFactor, the integer part of SCALE times 5 to the power +1/1610 or -1/1610
Toward more tokens (state decreases)1001000150694760275774499109716182828129711690933480030673300
Toward fewer tokens (state increases)999000848607199404438354486700711816566668247055847663535372

The implementation carries an outward-rounded upper bound one unit above the factor, and it throws if the two bounds round to different token counts. Recompute that way. An internal review recorded a price difference of about 0.26% between the last curve price and the first market price. The table was left as specified, and a later price is whatever the table says at that state.

Leaf order is every buy, then every sell. Inside each side, the source state runs from low to high and the trade size follows AMM_STEPS, skipping a size that would leave the range -1,610 through 4,607. At 100 bps the tree has 159,698 leaves.

amm-table.json must match makeAmmTable() at every state. An indexer recomputes with integer division.

#Taproot tree

The curve tree and the market tree use the same rules.

  • A leaf hash is the tagged hash TapLeaf of version byte 0xc0, then the compact size of the script, then the script. A script of 253 bytes or more uses the 3-byte 0xfd compact-size prefix.
  • A range of n > 1 leaves splits after floor(n / 2). The left child is the first half.
  • A branch hash is TapBranch of the two child hashes, sorted by bytes.
  • The output script is OP_1 OP_PUSHBYTES_32 and the tweaked output key. There is no key-path spend. The internal point has no known private key.
  • The control block is 0xc0 with the output-key parity bit, then the internal key, then the sibling hashes on the path. Its length is 33 + 32 * depth bytes.

A 9,431-leaf curve tree built with that split has depth 13 or 14, so the control block is 449 or 481 bytes. The market tree is deeper. Its longest control block in the current tests is 609 bytes (33 + 32 * 18). Compute the path. Do not freeze a market control block length into a constant.

Build order for one pearl: GENESIS = commitTxid:0, then the token tree, then the market pool P_a, then the curve pool P_c. Curve leaves put the program of P_a on the change blacklist. The reveal transaction is last. The public id is output 1 of the reveal, not GENESIS.

#State record

Output 0 of every protocol transaction is an OP_RETURN worth 0 grain. The script is 63 bytes: 6a 3d and a 61-byte record. The serialized output prefix is 11 bytes:

text
00 00 00 00 00 00 00 00 3f 6a 3d

The 61-byte record:

OffsetLengthField
04Tag 50 52 4c 01 (ASCII PRL, version 1)
41Kind: 00 launch, 01 transfer, 02 pool move, including harvest
54decl0 = AMT(...)
94decl1 = AMT(...)
1320Holder of slot 1. An empty slot is 20 zero bytes
334Amount of slot 1. An empty slot is AMT(0)
3720Holder of slot 2
574Amount of slot 2

An empty slot is 20 zero bytes and AMT(0) together. A holder id, for a person or for a pool script, is:

text
HASH160(0x51 0x20 || program32)

0x51 0x20 is the P2TR script without its length byte. The market leaves use the same function.

Conservation: decl0 + decl1 = slot1 amount + slot2 amount. The protocol does not burn tokens. On a kind 02 pool move, decl0 is the inventory before the move and slot 1 is the inventory the pool script still holds.

A slot that creates an output must have a holder other than 20 zero bytes and an amount other than AMT(0). On an optional slot 2, the holder is all zeros exactly when the amount is AMT(0). The pairs (all zeros, some tokens) and (a real holder, zero tokens) fail.

#Shared script rules

  • nVersion = 2. On a pool move and on harvest, every input has nSequence = 0xffffffff. Absolute nLockTime is ground until the covenant challenge fits. It is not a time lock.
  • The sighash is BIP 341 SIGHASH_DEFAULT. The message hash-type byte is 0x00, spend_type is 0x02 (script path, no annex), key_version is 0x00, and codesep_pos is 0xffffffff. The pool leaf uses input index 0. A token leaf uses its own input index, given below.
  • The challenge is e = tagged_hash("BIP0340/challenge", G.x || G.x || m). The signature is R || s with R = G and s = e + 1. The script requires the last byte b of e to satisfy 1 <= b <= 127. It ends in CHECKSIG. The spender changes nLockTime until b falls in that range. The witness carries e as 31 bytes plus that last byte. The private key is the public value 1 and the nonce is 1, so anyone can compute the same signature. The check binds the transaction that was assembled, because only the leaf's constants produce a message the node will accept.
  • SIZE followed by EQUALVERIFY locks a length. One byte too short or too long fails.
  • A stack element holds at most 520 bytes. The reconstructed previous transactions P and PP each have to fit in one element, so their non-witness serialization is at most 520 bytes.

sha_prevouts, sha_amounts, sha_scriptpubkeys, sha_sequences, and sha_outputs are a single SHA256 of the BIP 341 concatenation, not HASH256. The txid of a reconstructed P or PP is HASH256 (SHA256 twice), then used in internal byte order.

#Curve pool leaves

poolLeaf is the one template. A buy leaf writes decl1 and the sold token amount as constants, and takes the buyer's holder id from the witness. A sell leaf takes decl1, the slot 2 holder, and the slot 2 amount from the witness. Harvest does not use this leaf.

#Buy transaction

f is the number of PRL funding inputs, 1 or 2.

IndexInputOutput
0Pool, prevTxid:1, amount C[i], script P_cOutput 0, kind 02
1Inventory, prevTxid:2, 1,000 grain, token scriptC[j] paid back to the same P_c
2Funding P2TRInventory token output, 1,000 grain
3Second funding P2TR, only when f = 2Platform fee F to the fee address
4Buyer token output, 1,000 grain, amount delta = (j - i) * 1,000,000
5Change P2TR

The change program must not equal the pool program, the token program, or forbiddenChange. At genesis that blacklist is the market-pool program.

Output 0 is:

text
TAG || 02 || AMT(Y_i) || AMT(0) || HASH160(0x5120 || prog0) || AMT(Y_j) || buyer || AMT(delta)

prog0 is this pool's 32-byte program, read from the witness. The script computes the holder id. The witness does not supply it.

Grain for the change, before the builder's 1,000 grain floor: the funding inputs cover D + F, the extra 1,000 grain of the new buyer output, and the miner fee. The inventory's 1,000 grain goes back out as the new inventory output.

The wallet signs only the funding inputs, index 2, or indexes 2 and 3. buildBuyTx has already ground nLockTime.

#Sell transaction

IndexInputOutput
0Pool C[j], prevTxid:1Output 0
1Inventory Y_j, prevTxid:2, token leaf PIC[i] back to P_c
2Seller's tokens, amount a >= delta, token leaf PTInventory token output
3Seller's own P2TR, key-path signature. This input also authorizes PTPlatform fee F for the move j to i
4Seller's remaining tokens, amount a - delta, only when a > delta
LastChange

A sell always has input 3. There is no form with f = 0. The pool witness still carries f = 2: the first funding item is the seller's token output (1,000 grain, token program) and the second is the seller's PRL. The wallet signs only input 3 (signInputs = [3]). Call buildSellTx.

Slot 2 is optional. A partial sell (a > delta) writes the remaining tokens at output 4 and then the change, six outputs in all. A full sell (a = delta) sets slot 2 to 20 zero bytes and AMT(0), omits output 4, and has five outputs. The spare 1,000 grain from the token input that no longer needs an output is added to the seller's change.

text
partial change = (C[j] - C[i] - F) + funding - miner fee
full change    = (C[j] - C[i] - F) + funding + 1,000 - miner fee

The builder rejects a change below 1,000 grain.

#Witness

poolWitness is the only order. Bottom of the stack to top, without the leaf script and the control block:

text
e31 || b || lockTime || leafHash
|| changeAmount8 || changeProgram32
|| [decl1_4] [owner2_20] [amount2_4]     # only fields marked witness
|| prevTxid32 || prog0_32
|| [prevout36 || amount8 || program32]   # when f = 2, input 3 first, then input 2
|| f                                     # one byte, 1 or 2

A buy's slot witness is only the 20-byte buyer holder id. A sell's slot witness is decl1, the seller's holder id, and AMT(a - delta).

#What the leaf checks

The buy script compiled from the default table is 754 bytes. The sell script is 776 bytes. Both figures are the script only, with sample 32-byte programs, and they do not include the control block. [[n]] below means SIZE n EQUALVERIFY. Concatenation consumes the stack from the right, as the template is written.

  1. Funding count. DUP 1 3 WITHIN VERIFY TOALTSTACK. f is 1 or 2.
  2. The first funding input, which is transaction input 2. [[32]], then the prefix 22 51 20, then [[8]], then [[36]]. That builds the script, the amount, and the outpoint.
  3. When f = 2, do the same for input 3 and append both triples.
  4. Sequence hash. Every nSequence is ffffffff. The script builds 12 bytes when f = 1 and 16 bytes when f = 2, then SHA256. It does not read sequences from the witness.
  5. sha_prevouts = SHA256(prevTxid || 01000000 || prevTxid || 02000000 || the funding outpoints). prevTxid and prog0 are each [[32]]. The inventory must be output 2 of the same transaction as the pool.
  6. sha_amounts = SHA256(le64(C_s) || le64(1000) || the funding amounts). C_s is a leaf constant.
  7. sha_scriptpubkeys = SHA256(22 51 20 || prog0 || the 35-byte token script || the funding scripts).
  8. Witness fields of output 0 are checked at 4 or 20 bytes. DUP 51 20 SWAP CAT HASH160 is the pool's holder id.
  9. Assemble output 0: prefix, tag, kind 02, AMT(Y_s), decl1, holder id, AMT(Y_t), slot 2.
  10. The change program is [[32]] and must differ from prog0, the token program, and each blacklisted program. The change amount is [[8]].
  11. Hash the outputs: output 0, then le64(C_t) || 22 51 20 || prog0, then the inventory token output, then the platform fee when there is one, then the trader token output when slot 2 is used, then changeAmount || 22 51 20 || changeProgram. A buy pushes the token output once and duplicates it, so the 43-byte constant is not pushed twice. An optional slot 2 skips the trader output when the witness slot is empty.
  12. Sighash and CHECKSIG, as in the shared rules. G.x is pushed once and duplicated.

#Token leaves

There are 24 leaves. allTokenRoles() fixes the tree order.

RoleCountWhat it spendsWho authorizes it
T(m, k, t, prev)12A transfer. m is 1 or 2 authorizing inputs. k is this input's index, 0 or 1, and k < m. t is 1 or 2 token outputs. prev is X or PThe holder's 32-byte output key Q, inside this leaf
PI(m, t, prev)8The inventory, always input 1. prev is L or PInput 0, the pool leaf, which has already checked the pool
PT(t, prev)4The trader's tokens, always input 2. prev is X or PThe holder's output key Q, inside this leaf

prev = L means the tokens were born in the launch (kind 00). The script hard-codes the 36-byte GENESIS. X means the previous transaction was a transfer (kind 01). P means it was a pool move (kind 02).

witnessNames lists the items a role may need. The stack order is the order chosen by compileLeaf for that leaf. A wallet must pack the witness with tokenLeaf(role, genesis).order. Naming the items w0 through w12 in some other order will not spend.

#Checks every leaf makes

  1. Holder fields and amount fields have the right length. An amount is WITHIN the 4 bytes of AMT(0) inclusive and AMT(1,000,000,000) + 1 exclusive.
  2. Unless the source is the launch, rebuild the earlier transaction PP (at most 4 inputs and 3 intermediate P2TR outputs) and HASH256 it to a txid. An empty outpoint or amount slot takes no space. A used slot is a 36-byte outpoint or an 8-byte amount plus a 35-byte P2TR output.
  3. Rebuild P, the transaction that created this token: version, input count, inputs (a launch source's input 0 must be the hard-coded GENESIS), the opaque remainder PinRest, output count, output 0, and Ptail. HASH256 is P's txid. This input's outpoint must name that txid and the declared output index.
  4. On a transfer, the token may sit in slot 1 or slot 2. A transfer source uses output 1 or 2. A pool-move source uses output 2 or 4. Inventory is always output 2, which is slot 1.
  5. sha_prevouts covers this token input and every input before it in the same transaction.
  6. Authorization. For T and PT, HASH160(0x51 0x20 || Q) = myOwner, and Q signs this leaf with a 64-byte SIGHASH_DEFAULT signature (CHECKSIGVERIFY). That signature commits to the whole transaction. For PI, HASH160(0x51 0x20 || program of input 0) = myOwner. The pool leaf on input 0 is what authorizes the inventory.
  7. decl0 + decl1 = amount1 + amount2.
  8. Assemble output 0 and sha_outputs. The current transaction's outputs are fully listed: the token outputs the role allows, the pool and fee outputs a pool move requires, and exactly one P2TR change at the end. The change program must not be the token program. On a pool move it also must not be the pool program. An extra output fails. Ptail belongs to the previous transaction being rebuilt, and it is checked by length as part of that reconstruction.
  9. The sighash input index is k for a transfer, 1 for inventory, and 2 for the trader's tokens. The version is the constant 2. The current transaction's sequences are the constant ffffffff, assembled in the script. nLockTime and the leaf hash come from the witness.

To follow one token, walk P and then PP until kind 00, and require that kind 00 spends this pearl's GENESIS as input 0. A pool move's inventory input uses PI. Tokens the seller returns use PT.

A launch-source inventory leaf also checks the reveal outputs it was compiled with: output 1 pays C[0] to the pool program, output 2 is the 1,000 grain inventory, and output 3 pays the launch fee to the fee program.

#Launch

NameValue
GENESIScommitTxid:0. Leaves with prev = L hard-code this
tokenIdrevealTxid:1. This is the curve pool output, and it is the id an indexer and a URL use
genesisOutpointThe same outpoint as GENESIS, stored on Token.genesisOutpoint

#Commit

The commit is version 2. Its input is the creator's ordinary P2TR, spent by a key-path signature.

Output 0 is a script-path address under the unspendable internal point. Its leaf is the inscription. The amount is C[0] + 1,000 + launch fee + the reveal's miner fee.

Output 1 is an optional change. Below 333 grain it is left off. The commit itself is not a protocol event.

The inscription leaf is:

text
<creator public key> CHECKSIG
OP_0 IF
  50 52 4c 01
  OP_1
  <mime>
  OP_0
  <chunks>
ENDIF

Each chunk is 1 through 520 bytes, and every chunk except the last is exactly 520. The chunks concatenate to le32(metadata length) || UTF-8 JSON || image bytes. The JSON is {"meta": TokenMeta, "tradeFeeBps": n}. The parser accepts tradeFeeBps from 1 through 10,000. The platform indexes 100 only, as specified above.

The image is png, jpeg, webp, or gif, and the launch builder rejects a file larger than 30,000 bytes (LAUNCH_IMAGE_MAX_BYTES). The shared metadata schema names a larger image cap. The builder's 30,000 byte cap is the one that constructs a launch. A name is at most 32 characters, a symbol is 2 to 10 characters from A-Z and 0-9, and a description is at most 280 characters. Metadata JSON is at most 6,000 bytes.

#Reveal

Input 0 spends output 0 of the commit through the inscription leaf. There is no key-path spend. The first four outputs are the launch layout. The launch-fee amount is the launchFee the caller passed. The layout constant used by the checks is 5 PRL.

OutputContents
0Kind 00. Both declarations are AMT(0). Slot 1 is the pool program's holder id and AMT(1,000,000,000). Slot 2 is empty
1C[0] to P_c. This output is tokenId
21,000 grain to the token script. This is the inventory of 1,000,000,000 tokens
3Launch fee to the platform P2TR

The reveal's non-witness serialization must be at most 520 bytes, because the next buy's PI with prev = L rebuilds the whole transaction inside one stack element. There is no fifth change output. Extra grain stays in the commit.

checkGenesis also requires version 2, 1 through 4 inputs, input 0 equal to GENESIS, every nSequence equal to ffffffff, and at most 5 outputs. That describes a transaction that spends GENESIS directly. On the inscription path, the transaction that meets those checks is the reveal, not the commit.

estimateLaunch sizes the two transactions as:

text
base = 8 + CompactSize(input count) + 41 * input count + CompactSize(output count) + output bytes
vB = ceil((base * 4 + 2 + witness bytes) / 4)
commit witness bytes = input count * 66
reveal witness bytes = 1 + 65 + CompactSize(leaf length) + leaf length + 34

A commit with no change has a 43-byte output. A commit with change has 86 bytes of outputs. The reveal estimate uses 72 + 3 * 43 output bytes. Leaf length is 45 + mime length + body + push overhead. The body is 4 + metadata + image. Each full 520-byte chunk adds a 3-byte push header, and the last chunk uses a 1-byte header up to 75 bytes or a 2-byte header up to 255.

#Harvest

The only leaf that can spend C[800] is graduationLeafScript. Anyone can build the transaction. The funding inputs pay the miner fee. There is no platform-fee output.

IndexInputOutput
0Curve pool, prevTxid:1, amount C[800]Output 0, kind 02, a constant
1Inventory, prevTxid:2, leaf PIC[800] to P_a, a constant
2One or two funding P2TR inputsInventory token output. The holder is the holder id of P_a. The amount is 200,000,000 tokens. Both are constants
LastChange. It must not pay P_c, the token script, or P_a

Outputs 0, 1, and 2 are the leaf constant graduationFixedOutputs. In output 0, decl0 and the slot 1 amount are both AMT(200,000,000). decl1 and slot 2 are empty. The slot 1 holder is HASH160(0x5120 || P_a).

Witness, bottom to top, from poolWitness with no slot fields:

text
e31 b lockTime leafHash | changeAmount changeProgram | prevTxid | prog0 | [p3 a3 g3] p2 a2 g2 | f

The input-side opcodes match poolLeaf byte for byte. The script consumes the funding inputs, builds the sequence hash from 12 or 16 bytes of 0xff, starts sha_prevouts at prevTxid:1 || prevTxid:2, starts the amount hash at C[800] || 1000, starts the script hash at P_c || token script, rejects a change paid to any of the three programs, hashes the three constant outputs plus the change, then checks the sighash.

Input 0 is finalized by the harvest leaf. Input 1 is finalized by PI(1, 1) with prev = P. Funding inputs are left for the wallet. signInputs starts at 2. Call buildGraduateTx.

#Market trades

A market leaf is poolLeaf with the market table's constants: C_s becomes X_s, C_t becomes X_t, and Y_s, Y_t, and F come from the transition. A buy leaf matches a curve buy: decl1 = AMT(0), the slot 2 amount AMT(Y_s - Y_t) is constant, and the buyer's holder id comes from the witness. A sell leaf matches a curve sell: decl1 and slot 2 come from the witness, and slot 2 is optional, so selling the whole amount does not create output 4. The one constant that differs is forbiddenChange, which is empty, because a market leaf does not know P_c. The function is ammLeafScript. A buy script is 717 bytes and a sell script is 739 bytes. The tree has 159,698 leaves, and the longest control block in the current tests is 609 bytes.

IndexInputOutput
0Market pool, prevTxid:1, amount X_sOutput 0
1Inventory, prevTxid:2. A buy uses PI(1, 2, P). A sell uses PI(2, t, P)X_t back to the same market pool
2Buy: funding P2TR. Sell: the seller's tokens, PT(t, X or P)Inventory token output
3Buy: optional second funding input. Sell: the seller's own P2TR, requiredPlatform fee F
4Trader token output. Always present on a buy. Present on a sell only when slot 2 is not empty
LastOne P2TR change

Output 0 is TAG || 02 || AMT(Y_s) || decl1 || HASH160(0x5120 || pool program) || AMT(Y_t) || slot2. The trader's holder id is HASH160(0x5120 || trader program), the same function as the token leaves.

poolWitness builds the witness in the same order as the curve. The constructor is buildAmmSwapTx. It grinds nLockTime together with the token leaves. The PT signature is token.holderSign when the caller passes it. Otherwise the result lists pendingSignatures and the wallet fills them in. The wallet signs the funding inputs only.

#What is not in the protocol

The implemented protocol has no order-book leaf, no SIGHASH_SINGLE | ANYONECANPAY listing, and no on-chain order id. The design note that described a LIST transaction was withdrawn. After harvest, the secondary market is the pool in the previous section.

An indexer must not treat "a token output plus a partial signature" as an order. A wallet that wants to sell calls buildSellTx on the curve or buildAmmSwapTx on the market.

#Measured size

Virtual size is ceil(weight / 4), with weight = non-witness bytes * 3 + total bytes including the witness. The table is the local test chain run in the end-to-end report. In that run the miner fee is 3 grain per vB, so each miner-fee cell is the virtual size times 3. That rate was chosen for the run. The script does not fix it. A builder that disagrees with testmempoolaccept should trust the node.

TransactionvBPlatform fee
Launch commit1540
Launch reveal328500,000,000 grain (5 PRL)
Curve buy1,2141,922,181 grain
Curve buy1,4114,836,949 grain
Transfer8900
Curve sell2,2001,940,204 grain
Curve fill, sixteen transactions1,453 to 1,471per transaction in the report
Harvest, one funding input, PI(1, 1, P)1,3360
Market buy1,4546,003,907 grain, then 3,006,455 grain
Market sell2,1943,006,455 grain
Market sell2,1873,003,459 grain

The report lists every txid. Curve sells in that run and in the earlier local run sit above 2,000 vB and under the 3,000 vB cap. Most of the witness on a sell is PI and PT rebuilding P and PP.

Commit and reveal size moves with the image and the input count. Use estimateLaunch for a quote, then the node's virtual size for the transaction you will broadcast. A pool move the constructor measures above 3,000 vB throws before it is returned.

#What an indexer and a wallet check

An indexer does all of the following.

  1. Recognize the reveal as in the launch section. tokenId is reveal:1. GENESIS is input 0 of that reveal.
  2. Recompute C[step] and the market table from the formulas above. The PRL in the pool is enough to name the curve layer or the market state.
  3. Parse the 61 bytes in output 0. The harvest is the kind 02 transaction whose pool script changes from P_c to P_a.
  4. Follow token balances along P and PP. Do not trust a holder id in output 0 unless the authorizing input or the in-leaf signature matches. Market slot 2 uses the same holder function as every other leaf.
  5. Keep unconfirmed spends of one pool in a single chain. Input 0 of each transaction is output 1 of the previous one, and input 1 is output 2 of the previous one.
  6. Index a launch only at 100 bps, and only when the launch fee matches the canonical value. Record any other rate as rejected, not as a pearl.

A wallet does all of the following.

  1. Buy on the curve with buildBuyTx. Sign only the funding inputs, index 2, or indexes 2 and 3. nLockTime is already ground.
  2. Sell on the curve with buildSellTx. Sign only input 3.
  3. Trade on the market with buildAmmSwapTx. Sign only the funding inputs. The seller's token input is finalized by PT.
  4. Transfer with buildTransferTx. The authorizing input needs tapInternalKey, and T or PT needs the holder's 64-byte signature.
  5. Do not send change to P_c, P_a, or the token script. The 1,000 grain on a token output is not spendable as ordinary PRL. PRL sent straight to a pool or token script can only move if some leaf pays it out, and these leaves do not.

#Next

The numbers in the size table are copied from the end-to-end report. Recompute the reserves from curve-params.json and the market states from amm-table.json, then check each file's SHA-256 against this page.

NACRE · The first keyless launchpad on Pearl