Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 29쪽

iltins:** `range_check`, `bitwise`, `pedersen`, `poseidon`, `ec_op`, `segment_arena`, `keccak`. **Unsupported builtins:** `range_check96`, `add_mod`, `mul_mod`, `ecdsa`. ## Why this design * native storage model, * account abstraction signature checks (`is_valid_signature`), * shared Cairo logic between proving and verification paths. # Privacy, security, and limitations Source: https://docs.starknet.io/build/starknet-privacy/security Guarantees, fund safety, and known privacy caveats for Starknet Privacy ## Privacy (informal) What observers see (or don't) in practice: | Topic | What leaks / what’s protected | | - | - | | **Sender** | External observers see **paymaster** as sender; paymaster may see IP. | | **Receiver** | Hidden **except** when a **new channel** is opened (recipient address on-chain once per sender–recipient pair). | | **Amounts** | Encrypted in normal notes; **deposits**, **withdrawals**, and **open notes** expose amounts (and tokens) as designed. | | **Auditor** | Can decrypt registered users’ viewing keys when authorized; cannot sign spends. | ## Fund security * **Double-spend** — nullifiers are unique and recorded; proof ties nullifier to existing note. * **Unauthorized spend** — requires valid **account signature** in proof; auditor has viewing key only, not signing authority. ## Limitations 1. **New channel + deposit/withdraw in same tx or tight timing** — can link recipient to public address activity; wallets should separate these flows when possible. 2. **Deposit/withdraw heuristics** — distinctive amounts or immediate in/out weaken privacy (common to all pools). 3. **Reverted txs** — if a note slot was touched then reverted, **reusing the same note id** can link txs; mitigations include burning dummy writes to exposed ids (paper §11.3.3). For the full analysis see [IACR 2026/474](https://eprint.iacr.org/2026/474.pdf) §11. # STRK20 by Example Source: https://docs.starknet.io/build/starknet-privacy/strk20-by-example Hands-on hub of runnable examples for integrating STRK20 private transfers These docs explain **how Starknet Privacy works**. When you are ready to build, [**STRK20 by Example**](https://strk20-by-example.org/) is the hands-on companion: a hub of runnable examples for teams integrating STRK20 into their apps, built on the open-source [starknet-privacy SDK](https://github.com/starkware-libs/starknet-privacy). ## What you'll find <CardGroup> <Card title="SDK examples" icon="cube" href="https://strk20-by-example.org/sdk/getting-started"> Setup, registration, deposits, transfers, withdrawals, note discovery, proving configuration, and multi-operation batches </Card> <Card title="DeFi helpers" icon="arrows-rotate" href="https://strk20-by-example.org/helpers/privacy-invoke"> Privacy Invoke, Vesu lending, swaps, and escrow — working open-note helper integrations </Card> <Card title="Wallet integration" icon="wallet" href="https://strk20-by-example.org/starknet-wallet-api/overview"> Starknet Wallet API and starknet.js patterns for privacy-enabled dApps </Card> <Card title="Example app" icon="rocket" href="https://strk20-by-example.org/app/anonymous-airdrop"> An end-to-end anonymous airdrop application combining the pieces </Card> </CardGroup> ## How it relates to these docs | You want to... | Go to | | - | - | | Understand the protocol (notes, channels, proofs, compliance) | These docs — start with the [overview](/build/starknet-privacy/overview) | | Integrate STRK20 into your app with working code | [STRK20 by Example](https://strk20-by-example.org/) | | Read the SDK and proving stack source | [starknet-privacy repo](https://github.com/starkware-libs/starknet-privacy) | # Transaction flow Source: https://docs.starknet.io/build/starknet-privacy/transaction-flow Action compilation, ordering constraints, and per-token balance invariants ## Pipeline 1. Build client-side actions. 2. Generate proof over compiled server-side actions. 3. Submit (directly or via paymaster). 4. Contract verifies and executes. ## Why fixed ordering exists Ordering (`SetViewingKey -> OpenChannel -> OpenSubchannel -> Deposit -> UseNote -> CreateNote -> Withdraw`) reduces state-machine ambiguity and closes classes of ordering bugs where the same semantic operation could be encoded in multiple inconsistent sequences. ## Per-token temporary balance Within one transaction, each token keeps a temporary balance: * `Deposit` and `UseNote` increase it. * `CreateNote` and `Withdraw` decrease it. Invariant: * it must never go negative during execution, * and **must end at 0** at the end of transaction. "Must end at 0" means all temporary inflows are fully matched by outflows in that transaction; no unaccounted residual value remains. # Troubleshooting and FAQ Source: https://docs.starknet.io/build/starknet-privacy/troubleshooting Protocol pitfalls and where to learn more These notes are **protocol-oriented**. Build commands, version pins, and toolchain issues will be documented when the reference implementation is open sourced. ## Proof verification fails (conceptual) * **Stale anchor** — Proofs are tied to a **recent block**; regenerating is required if chain state moved materially. * **WriteOnce conflict** — Another transaction may have consumed the same nullifier or note slot; the flow may need fresh indices. ## Wallet / signature * Accounts must expose **SNIP-6** `is_valid_signature` behavior expected by the virtual execution model. See [Proof generation](/build/starknet-privacy/proving). ## Privacy UX * Avoid **opening a new channel** in the same transaction (or immediately before/after) as **public deposit or withdraw** if you want to minimize linking (see [Security](/build/starknet-privacy/security)). ## Where to learn more * **Protocol** — [IACR 2026/474](https://eprint.iacr.org/2026/474.pdf) * **Implementation** — operational troubleshooting will move to the open source repository docs when that phase ships. # API Reference Source: https://docs.starknet.io/build/starkzap/api-reference Complete API documentation for Starkzap ## StarkZap The main SDK class for initializing and managing wallet connections. ### Constructor ```typescript theme={null} new StarkZap(config: SDKConfig): StarkZap ``` ### Methods | Method | Returns | Description | | - | - | - | | `connectWallet(options)` | `Promise<Wallet>` | Connect with signer + account preset | | `connectCartridge(options?)` | `Promise<CartridgeWalletInterface>` | Connect via Cartridge Controller popup (web only) | | `onboard(options)` | `Promise<OnboardResult>` | Onboard with strategy selection | | `stakingTokens()` | `Promise<Token[]>` | Get stakeable tokens | | `getStakerPools(staker)` | `Promise<Pool[]>` | Get validator's delegation pools | | `getBridgingTokens(chain?)` | `Promise<BridgeToken[]>` | Get bridgeable tokens by source chain | | `getProvider()` | `RpcProvider` | Get the underlying RPC provider | | `callContract(call)` | `Promise<CallContractResponse>` | Call a contract read function | ### Configuration ```typescript theme={null} interface SDKConfig { network?: NetworkName | NetworkPreset; rpcUrl?: string; chainId?: ChainId; allowInsecureHttp?: boolean; // accept plain http:// off loopback; dev only paymaster?: PaymasterOptions; // { nodeUrl?: string; default?: boolean; headers?: object } explorer?: ExplorerConfig; staking?: StakingConfig; bridging?: BridgingConfig; } ``` ### ConnectWalletOptions ```typescript theme={null} interface ConnectWalletOptions { account: AccountConfig; accountAddress?: Address; feeMode?: FeeMode; timeBounds?: PaymasterTimeBounds; swapProviders?: SwapProvider[]; defaultSwapProviderId?: string; dcaProviders?: DcaProvider[]; defaultDcaProviderId?: string; } interface AccountConfig { signer: SignerInterface; accountClass?: AccountClassConfig; } ``` ## Wallet / WalletInterface The wallet interface provides access to account operations, transactions, and token management. ### Properties | Property | Type | Description | | - | - | - | | `address` | `Address` | Wallet address | ### Methods | Method | Returns | Description | | - | - | - | | `isDeployed()` | `Promise<boolean>` | Check deployment status | | `ensureReady(options?)` | `Promise<void>` | Deploy if needed | | `deploy(options?)` | `Promise<Tx>` | Deploy account contract | | `execute(calls, options?)` | `Promise<Tx>` | Execute contract calls | | `signMessage(typedData)` | `Promise<Signature>` | Sign typed data | | `preflight(options)` | `Promise<PreflightResult>` | Simulate transaction | | `tx()` | `TxBuilder` | Create a transaction builder | | `balanceOf(token)` | `Promise<Amount>` | Get token balance | | `transfer(token, transfers, options?)` | `Promise<Tx>` | Transfer ERC20 tokens | | `stake(pool, amount, options?)` | `Promise<Tx>` | Smart stake (enter or add) | | `enterPool(pool, amount, options?)` | `Promise<Tx>` | Enter staking pool | | `addToPool(pool, amount, options?)` | `Promise<Tx>` | Add to existing stake | | `claimPoolRewards(pool, options?)` | `Promise<Tx>` | Claim staking rewards | | `exitPoolIntent(pool, amount, options?)` | `Promise<Tx>` | Start exit process | | `exitPool(pool, options?)` | `Promise<Tx>` | Complete exit | | `isPoolMember(pool)` | `Promise<boolean>` | Check pool membership | | `getPoolPosition(pool)` | `Promise<PoolMember \| null>` | Get staking position | | `getPoolCommission(pool)` | `Promise<number>` | Get pool commission rate | | `estimateFee(calls)` | `Promise<EstimateFeeResponse>` | Estimate execution fee | | `getAccount()` | `Account` | Get starknet.js Account | | `getProvider()` | `RpcProvider` | Get RPC provider | | `getChainId()` | `ChainId` | Get chain ID | | `getFeeMode()` | `FeeMode` | Get default fee mode | | `erc20(token)` | `Erc20` | Get ERC20 helper for token | | `getClassHash()` | `string` | Get account class hash | | `getQuote(request)` | `Promise<SwapQuote>` | Get swap quote | | `prepareSwap(request)` | `Promise<PreparedSwap>` | Prepare swap calls | | `swap(request, options?)` | `Promise<Tx>` | Execute a token swap | | `registerSwapProvider(provider, makeDefault?)` | `void` | Register a swap provider | | `setDefaultSwapProvider(providerId)` | `void` | Set the default swap provider | | `getSwapProvider(providerId)` | `SwapProvider` | Get a registered swap provider | | `getDefaultSwapProvider()` | `SwapProvider` | Get the default swap provider | | `listSwapProviders()` | `string[]` | List registered swap provider IDs | | `dca()` | `DcaClientInterface` | Get DCA (recurring buy) client | | `lending()` | `LendingClient` | Get lending client | | `staking(poolAddress)` | `Promise<Staking>` | Get staking helper for a pool | | `stakingInStaker(stakerAddress, token)` | `Promise<Staking>` | Get staking helper from a staker | | `lstStaking(asset, options?)` | `EndurStaking` | Get Endur liquid staking helper for an asset | | `troves(options?)` | `Troves` | Get Troves strategy client | | `callContract(call)` | `Promise<CallContractResponse>` | Read-only contract call | | `disconnect()` | `Promise<void>` | Disconnect wallet | | `deposit(recipient, amount, token, externalWallet, options?)` | `Promise<{ hash: string }>` | Bridge deposit from external chain | | `getDepositBalance(token, externalWallet)` | `Promise<Amount>` | Get source-chain available balance | | `getAllowance(token, externalWallet)` | `Promise<Amount \| null>` | Get source-chain allowance (if applicable) | | `getDepositFeeEstimate(token, externalWallet, options?)` | `Promise<BridgeDepositFeeEstimation>` | Estimate bridge route fees | | `initiateWithdraw(recipient, amount, token, externalWallet, options?)` | `Promise<Tx>` | Initiate withdrawal from Starknet to external chain | | `completeWithdraw(recipient, amount, token, externalWallet, options?)` | `Promise<{ hash: string }>` | Complete withdrawal on external chain (Canonical & CCTP only) | | `getWithdrawBalance(token, externalWallet)` | `Promise<Amount>` | Get L2 balance available to withdraw | | `getInitiateWithdrawFeeEstimate(token, externalWallet, options?)` | `Promise<BridgeInitiateWithdrawFeeEstimation>` | Estimate L2 fee for initiating withdrawal | | `getCompleteWithdrawFeeEstimate(amount, recipient, token, externalWallet, options?)` | `Promise<BridgeCompleteWithdrawFeeEstimation>` | Estimate L1 gas for completing withdrawal | | `monitorDeposit(token, externalTxHash, starknetTxHash?)` | `Promise<DepositMonitorResult>` | Get full deposit status snapshot | | `monitorWithdrawal(token, snTxHash, externalTxHash?)` | `Promise<WithdrawMonitorResult>` | Get full withdrawal status snapshot (includes CCTP attestation data) | | `getDepositState(token, param)` | `Promise<DepositState>` | Simplified deposit state for UI | | `getWithdrawalState(token, param)` | `Promise<WithdrawalState>` | Simplified withdrawal state for UI | ## Tx Transaction object returned from `execute()`, `deploy()`, and `transfer()`. ### Properties | Property | Type | Description | | - | - | - | | `hash` | `string` | Transaction hash | | `explorerUrl` | `string` | Block explorer URL | ### Methods | Method | Returns | Description | | - | - | - | | `wait(options?)` | `Promise<void>` | Wait for confirmation | | `watch(callback, options?)` | `TxUnsubscribe` | Watch status changes (options: pollIntervalMs, timeoutMs, onError) | | `receipt()` | `Promise<TxReceipt>` | Get transaction receipt | ## TxBuilder Fluent API for building and executing batched transactions. ### Properties | Property | Type | Description | | - | - | - | | `length` | `number` | Number of queued call groups | | `isEmpty` | `boolean` | Whether the builder has no calls | | `isSent` | `boolean` | Whether `send()` has been called | ### Methods | Method | Returns | Description | | - | - | - | | `.add(...calls)` | `TxBuilder` | Add raw `Call` objects | | `.approve(token, spender, amount)` | `TxBuilder` | ERC20 approval | | `.transfer(token, transfers)` | `TxBuilder` | ERC20 transfer(s) | | `.stake(pool, amount)` | `TxBuilder` | Smart stake (enter or add based on membership) | | `.enterPool(pool, amount)` | `TxBuilder` | Enter pool as new member | | `.addToPool(pool, amount)` | `TxBuilder` | Add to existing pool position | | `.claimPoolRewards(pool)` | `TxBuilder` | Claim staking rewards | | `.exitPoolIntent(pool, amount)` | `TxBuilder` | Start exit process | | `.exitPool(pool)` | `TxBuilder` | Complete exit after window | | `.swap(request)` | `TxBuilder` | Provider-driven token swap | | `.lendDeposit(request)` | `TxBuilder` | Lending deposit (supply) | | `.lendWithdraw(request)` | `TxBuilder` | Lending withdraw | | `.lendWithdrawMax(request)` | `TxBuilder` | Lending max withdraw | | `.lendBorrow(request)` | `TxBuilder` | Lending borrow | | `.lendRepay(request)` | `TxBuilder` | Lending repay | | `.trovesDeposit(params)` | `TxBuilder` | Troves strategy deposit | | `.trovesWithdraw(params)` | `TxBuilder` | Troves strategy withdraw | | `.dcaCreate(request)` | `TxBuilder` | Create a DCA (recurring buy) order | | `.dcaCancel(request)` | `TxBuilder` | Cancel a DCA order | | `.confidentialFund(confidential, details)` | `TxBuilder` | Fund confidential account | | `.confidentialTransfer(confidential, details)` | `TxBuilder` | Confidential transfer | | `.confidentialWithdraw(confidential, details)` | `TxBuilder` | Withdraw from confidential to public address | | `.calls()` | `Promise<Call[]>` | Resolve all calls without sending | | `.estimateFee()` | `Promise<EstimateFeeResponse>` | Estimate gas cost | | `.preflight()` | `Promise<PreflightResult>` | Simulate the transaction | | `.send(options?)` | `Promise<Tx>` | Execute all calls atomically | ## Amount Type-safe amount handling for token values. ### Static Methods | Method | Returns | Description | | - | - | - | | `Amount.parse(value, token)` | `Amount` | From human-readable value | | `Amount.fromRaw(value, token)` | `Amount` | From raw blockchain value | ### Instance Methods | Method | Returns | Description | | - | - | - | | `toUnit()` | `string` | Human-readable string | | `toBase()` | `bigint` | Raw value for contracts | | `toFormatted(compressed?)` | `string` | Locale-formatted with symbol | | `getDecimals()` | `number` | Token decimal places | | `getSymbol()` | `string \| undefined` | Token symbol | | `add(other)` | `Amount` | Addition | | `subtract(other)` | `Amount` | Subtraction | | `multiply(scalar)` | `Amount` | Multiplication | | `divide(scalar)` | `Amount` | Division | | `eq(other)` | `boolean` | Equal | | `gt(other)` | `boolean` | Greater than | | `gte(other)` | `boolean` | Greater than or equal | | `lt(other)` | `boolean` | Less than | | `lte(other)` | `boolean` | Less than or equal | | `isZero()` | `boolean` | Is zero | | `isPositive()` | `boolean` | Is positive | ## Signers ### StarkSigner Local Stark curve signer for private key management. ```typescript theme={null} new StarkSigner(privateKey: string): StarkSigner ``` ### PrivySigner Privy server-side key management signer. ```typescript theme={null} new PrivySigner(config: { walletId: string; publicKey: string; serverUrl?: string; rawSign?: (walletId: string, hash: string) => Promise<string>; }): PrivySigner ``` ### SignerInterface Custom signer interface for implementing your own key management. ```typescript theme={null} interface SignerInterface { getPubKey(): Promise<string>; signRaw(hash: string): Promise<Signature>; } ``` ## Types ### Address Branded string type for Starknet addresses. ```typescript theme={null} type Address = string & { readonly __type: "StarknetAddress" }; // Create from BigNumberish (string, number, or bigint) fromAddress(value: BigNumberish): Address ``` ### ChainId Chain ID utilities and constants. ```typescript theme={null} class ChainId { static MAINNET: ChainId; static SEPOLIA: ChainId; static from(literal: ChainIdLiteral): ChainId; static fromFelt252(felt: string): ChainId; isMainnet(): boolean; isSepolia(): boolean; toFelt252(): string; toLiteral(): ChainIdLiteral; } ``` ### FeeMode Transaction fee payment mode. ```typescript theme={null} type FeeMode = | "user_pays" | { type: "paymaster"; gasToken?: Address } | "sponsored"; // deprecated alias for { type: "paymaster" } ``` ### DeployMode Account deployment policy. ```typescript theme={null} type DeployMode = "never" | "if_needed" | "always"; ``` ### OnboardStrategy Onboarding strategy selection. ```typescript theme={null} const OnboardStrategy = { Signer: "signer", Privy: "privy", Cartridge: "cartridge", } as const; type OnboardStrategy = (typeof OnboardStrategy)[keyof typeof OnboardStrategy]; ``` ## Interfaces ### Token ```typescript theme={null} interface Token { name: string; address: Address; decimals: number; symbol: string; metadata?: { logoUrl?: URL }; } ``` ### BridgingConfig ```typescript theme={null} interface BridgingConfig { layerZeroApiKey?: string; // required for OFT/OFT-migrated routes layerswapApiKey?: string; // required for Layerswap routes + token discovery layerswapBaseUrl?: string; // defaults to https://api.layerswap.io layerswapAllowedContracts?: readonly Address[]; // extra contracts Layerswap may call; unset = transfer only ethereumRpcUrl?: string; solanaRpcUrl?: string; } ``` ### ExternalChain ```typescript theme={null} enum ExternalChain { ETHEREUM = "ethereum", SOLANA = "solana", } ``` ### BridgeToken ```typescript theme={null} abstract class BridgeToken { id: string; name: string; symbol: string; decimals: number; chain: ExternalChain; protocol: Protocol; address: ExternalAddress; // source-chain token bridgeAddress: ExternalAddress; // source-chain bridge starknetAddress: Address; // destination token on Starknet starknetBridge: Address; // destination bridge contract } // Concrete subclasses: EthereumBridgeToken, SolanaBridgeToken ``` ### WithdrawalState Simplified withdrawal state for use in UI polling. ```typescript theme={null} type WithdrawalState = "PENDING" | "READY_TO_CLAIM" | "C
프로젝트로 돌아가기