From 5efc2312d52f0b19091bab15309421791ba518b2 Mon Sep 17 00:00:00 2001 From: stellar-terraform <55583252+stellar-terraform@users.noreply.github.com> Date: Wed, 29 Jun 2022 20:04:40 +0100 Subject: [PATCH 001/112] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d46905a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# stellar-xdr-next +Staging area for future version of Stellar XDR. From df8ddc67c80e06468f74afe76ff1d303131983f4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 29 Jun 2022 20:26:51 -0700 Subject: [PATCH 002/112] Create check.yml (#2) Defines the 'complete' status check. --- .github/workflows/check.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..3ed265c --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,30 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "complete" + complete: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: No-op + run: echo success From e633ab7872b10884ce11665fdfe78e7dbd5d1e68 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 29 Jun 2022 20:27:23 -0700 Subject: [PATCH 003/112] populate (#1) --- Stellar-SCP.x | 86 ++ Stellar-contract.x | 144 +++ Stellar-ledger-entries.x | 649 ++++++++++++++ Stellar-ledger.x | 377 ++++++++ Stellar-overlay.x | 238 +++++ Stellar-transaction.x | 1843 ++++++++++++++++++++++++++++++++++++++ Stellar-types.x | 102 +++ 7 files changed, 3439 insertions(+) create mode 100644 Stellar-SCP.x create mode 100644 Stellar-contract.x create mode 100644 Stellar-ledger-entries.x create mode 100644 Stellar-ledger.x create mode 100644 Stellar-overlay.x create mode 100644 Stellar-transaction.x create mode 100644 Stellar-types.x diff --git a/Stellar-SCP.x b/Stellar-SCP.x new file mode 100644 index 0000000..7ec9921 --- /dev/null +++ b/Stellar-SCP.x @@ -0,0 +1,86 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +%#include "xdr/Stellar-types.h" + +namespace stellar +{ + +typedef opaque Value<>; + +struct SCPBallot +{ + uint32 counter; // n + Value value; // x +}; + +enum SCPStatementType +{ + SCP_ST_PREPARE = 0, + SCP_ST_CONFIRM = 1, + SCP_ST_EXTERNALIZE = 2, + SCP_ST_NOMINATE = 3 +}; + +struct SCPNomination +{ + Hash quorumSetHash; // D + Value votes<>; // X + Value accepted<>; // Y +}; + +struct SCPStatement +{ + NodeID nodeID; // v + uint64 slotIndex; // i + + union switch (SCPStatementType type) + { + case SCP_ST_PREPARE: + struct + { + Hash quorumSetHash; // D + SCPBallot ballot; // b + SCPBallot* prepared; // p + SCPBallot* preparedPrime; // p' + uint32 nC; // c.n + uint32 nH; // h.n + } prepare; + case SCP_ST_CONFIRM: + struct + { + SCPBallot ballot; // b + uint32 nPrepared; // p.n + uint32 nCommit; // c.n + uint32 nH; // h.n + Hash quorumSetHash; // D + } confirm; + case SCP_ST_EXTERNALIZE: + struct + { + SCPBallot commit; // c + uint32 nH; // h.n + Hash commitQuorumSetHash; // D used before EXTERNALIZE + } externalize; + case SCP_ST_NOMINATE: + SCPNomination nominate; + } + pledges; +}; + +struct SCPEnvelope +{ + SCPStatement statement; + Signature signature; +}; + +// supports things like: A,B,C,(D,E,F),(G,H,(I,J,K,L)) +// only allows 2 levels of nesting +struct SCPQuorumSet +{ + uint32 threshold; + NodeID validators<>; + SCPQuorumSet innerSets<>; +}; +} diff --git a/Stellar-contract.x b/Stellar-contract.x new file mode 100644 index 0000000..c09a3a6 --- /dev/null +++ b/Stellar-contract.x @@ -0,0 +1,144 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +% #include "xdr/Stellar-types.h" +namespace stellar +{ +/* + * Smart Contracts deal in SCVals. These are a (dynamic) disjoint union + * between several possible variants, to allow storing generic SCVals in + * generic data structures and passing them in and out of languages that + * have simple or dynamic type systems. + * + * SCVals are (in WASM's case) stored in a tagged 64-bit word encoding. Most + * signed 64-bit values in Stellar are actually signed positive values + * (sequence numbers, timestamps, amounts), so we don't need the high bit + * and can get away with 1-bit tagging and store them as "unsigned 63bit", + * (u63) separate from everything else. + * + * We actually reserve the low _four_ bits, leaving 3 bits for 8 cases of + * "non-u63 values", some of which have substructure of their own. + * + * 0x_NNNN_NNNN_NNNN_NNNX - u63, for any even X + * 0x_0000_000N_NNNN_NNN1 - u32 + * 0x_0000_000N_NNNN_NNN3 - i32 + * 0x_NNNN_NNNN_NNNN_NNN5 - static: void, true, false, ... (SCS_*) + * 0x_IIII_IIII_TTTT_TTT7 - object: 32-bit index I, 28-bit type code T + * 0x_NNNN_NNNN_NNNN_NNN9 - symbol: up to 10 6-bit identifier characters + * 0x_NNNN_NNNN_NNNN_NNNb - bitset: up to 60 bits + * 0x_CCCC_CCCC_TTTT_TTTd - status: 32-bit code C, 28-bit type code T + * 0x_NNNN_NNNN_NNNN_NNNf - reserved + * + * Up here in XDR we have variable-length tagged disjoint unions but no + * bit-level packing, so we can be more explicit in their structure, at the + * cost of spending more than 64 bits to encode many cases, and also having + * to convert. It's a little non-obvious at the XDR level why there's a + * split between SCVal and SCObject given that they are both immutable types + * with value semantics; but the split reflects the split that happens in + * the implementation, and marks a place where different implementations of + * immutability (CoW, structural sharing, etc.) will likely occur. + */ + +// A symbol is up to 10 chars drawn from [a-zA-Z0-9_], which can be packed +// into 60 bits with a 6-bit-per-character code, usable as a small key type +// to specify function, argument, tx-local environment and map entries +// efficiently. +typedef string SCSymbol<10>; + +enum SCValType +{ + SCV_U63 = 0, + SCV_U32 = 1, + SCV_I32 = 2, + SCV_STATIC = 3, + SCV_OBJECT = 4, + SCV_SYMBOL = 5, + SCV_BITSET = 6, + SCV_STATUS = 7 +}; + +% struct SCObject; + +enum SCStatic +{ + SCS_VOID = 0, + SCS_TRUE = 1, + SCS_FALSE = 2, + SCS_LEDGER_KEY_CONTRACT_CODE_WASM = 3 +}; + +enum SCStatusType +{ + SST_OK = 0, + SST_UNKNOWN_ERROR = 1 + // TODO: add more +}; + +union SCStatus switch (SCStatusType type) +{ +case SST_OK: + void; +case SST_UNKNOWN_ERROR: + uint32 unknownCode; +}; + +union SCVal switch (SCValType type) +{ +case SCV_U63: + int64 u63; +case SCV_U32: + uint32 u32; +case SCV_I32: + int32 i32; +case SCV_STATIC: + SCStatic ic; +case SCV_OBJECT: + SCObject* obj; +case SCV_SYMBOL: + SCSymbol sym; +case SCV_BITSET: + uint64 bits; +case SCV_STATUS: + SCStatus status; +}; + +enum SCObjectType +{ + // We have a few objects that represent non-stellar-specific concepts + // like general-purpose maps, vectors, numbers, blobs. + + SCO_VEC = 0, + SCO_MAP = 1, + SCO_U64 = 2, + SCO_I64 = 3, + SCO_BINARY = 4 + + // TODO: add more +}; + +struct SCMapEntry +{ + SCVal key; + SCVal val; +}; + +const SCVAL_LIMIT = 256000; + +typedef SCVal SCVec; +typedef SCMapEntry SCMap; + +union SCObject switch (SCObjectType type) +{ +case SCO_VEC: + SCVec vec; +case SCO_MAP: + SCMap map; +case SCO_U64: + uint64 u64; +case SCO_I64: + int64 i64; +case SCO_BINARY: + opaque bin; +}; +} \ No newline at end of file diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x new file mode 100644 index 0000000..20c37e3 --- /dev/null +++ b/Stellar-ledger-entries.x @@ -0,0 +1,649 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +%#include "xdr/Stellar-types.h" +%#include "xdr/Stellar-contract.h" + +namespace stellar +{ + +typedef PublicKey AccountID; +typedef opaque Thresholds[4]; +typedef string string32<32>; +typedef string string64<64>; +typedef int64 SequenceNumber; +typedef uint64 TimePoint; +typedef uint64 Duration; +typedef opaque DataValue<64>; +typedef Hash PoolID; // SHA256(LiquidityPoolParameters) + +// 1-4 alphanumeric characters right-padded with 0 bytes +typedef opaque AssetCode4[4]; + +// 5-12 alphanumeric characters right-padded with 0 bytes +typedef opaque AssetCode12[12]; + +enum AssetType +{ + ASSET_TYPE_NATIVE = 0, + ASSET_TYPE_CREDIT_ALPHANUM4 = 1, + ASSET_TYPE_CREDIT_ALPHANUM12 = 2, + ASSET_TYPE_POOL_SHARE = 3 +}; + +union AssetCode switch (AssetType type) +{ +case ASSET_TYPE_CREDIT_ALPHANUM4: + AssetCode4 assetCode4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AssetCode12 assetCode12; + + // add other asset types here in the future +}; + +struct AlphaNum4 +{ + AssetCode4 assetCode; + AccountID issuer; +}; + +struct AlphaNum12 +{ + AssetCode12 assetCode; + AccountID issuer; +}; + +union Asset switch (AssetType type) +{ +case ASSET_TYPE_NATIVE: // Not credit + void; + +case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4 alphaNum4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12 alphaNum12; + + // add other asset types here in the future +}; + +// price in fractional representation +struct Price +{ + int32 n; // numerator + int32 d; // denominator +}; + +struct Liabilities +{ + int64 buying; + int64 selling; +}; + +// the 'Thresholds' type is packed uint8_t values +// defined by these indexes +enum ThresholdIndexes +{ + THRESHOLD_MASTER_WEIGHT = 0, + THRESHOLD_LOW = 1, + THRESHOLD_MED = 2, + THRESHOLD_HIGH = 3 +}; + +enum LedgerEntryType +{ + ACCOUNT = 0, + TRUSTLINE = 1, + OFFER = 2, + DATA = 3, + CLAIMABLE_BALANCE = 4, + LIQUIDITY_POOL = 5, + CONTRACT_DATA = 6, + CONFIG_SETTING = 7 +}; + +struct Signer +{ + SignerKey key; + uint32 weight; // really only need 1 byte +}; + +enum AccountFlags +{ // masks for each flag + + // Flags set on issuer accounts + // TrustLines are created with authorized set to "false" requiring + // the issuer to set it for each TrustLine + AUTH_REQUIRED_FLAG = 0x1, + // If set, the authorized flag in TrustLines can be cleared + // otherwise, authorization cannot be revoked + AUTH_REVOCABLE_FLAG = 0x2, + // Once set, causes all AUTH_* flags to be read-only + AUTH_IMMUTABLE_FLAG = 0x4, + // Trustlines are created with clawback enabled set to "true", + // and claimable balances created from those trustlines are created + // with clawback enabled set to "true" + AUTH_CLAWBACK_ENABLED_FLAG = 0x8 +}; + +// mask for all valid flags +const MASK_ACCOUNT_FLAGS = 0x7; +const MASK_ACCOUNT_FLAGS_V17 = 0xF; + +// maximum number of signers +const MAX_SIGNERS = 20; + +typedef AccountID* SponsorshipDescriptor; + +struct AccountEntryExtensionV3 +{ + // We can use this to add more fields, or because it is first, to + // change AccountEntryExtensionV3 into a union. + ExtensionPoint ext; + + // Ledger number at which `seqNum` took on its present value. + uint32 seqLedger; + + // Time at which `seqNum` took on its present value. + TimePoint seqTime; +}; + +struct AccountEntryExtensionV2 +{ + uint32 numSponsored; + uint32 numSponsoring; + SponsorshipDescriptor signerSponsoringIDs; + + union switch (int v) + { + case 0: + void; + case 3: + AccountEntryExtensionV3 v3; + } + ext; +}; + +struct AccountEntryExtensionV1 +{ + Liabilities liabilities; + + union switch (int v) + { + case 0: + void; + case 2: + AccountEntryExtensionV2 v2; + } + ext; +}; + +/* AccountEntry + + Main entry representing a user in Stellar. All transactions are + performed using an account. + + Other ledger entries created require an account. + +*/ +struct AccountEntry +{ + AccountID accountID; // master public key for this account + int64 balance; // in stroops + SequenceNumber seqNum; // last sequence number used for this account + uint32 numSubEntries; // number of sub-entries this account has + // drives the reserve + AccountID* inflationDest; // Account to vote for during inflation + uint32 flags; // see AccountFlags + + string32 homeDomain; // can be used for reverse federation and memo lookup + + // fields used for signatures + // thresholds stores unsigned bytes: [weight of master|low|medium|high] + Thresholds thresholds; + + Signer signers; // possible signers for this account + + // reserved for future use + union switch (int v) + { + case 0: + void; + case 1: + AccountEntryExtensionV1 v1; + } + ext; +}; + +/* TrustLineEntry + A trust line represents a specific trust relationship with + a credit/issuer (limit, authorization) + as well as the balance. +*/ + +enum TrustLineFlags +{ + // issuer has authorized account to perform transactions with its credit + AUTHORIZED_FLAG = 1, + // issuer has authorized account to maintain and reduce liabilities for its + // credit + AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2, + // issuer has specified that it may clawback its credit, and that claimable + // balances created with its credit may also be clawed back + TRUSTLINE_CLAWBACK_ENABLED_FLAG = 4 +}; + +// mask for all trustline flags +const MASK_TRUSTLINE_FLAGS = 1; +const MASK_TRUSTLINE_FLAGS_V13 = 3; +const MASK_TRUSTLINE_FLAGS_V17 = 7; + +enum LiquidityPoolType +{ + LIQUIDITY_POOL_CONSTANT_PRODUCT = 0 +}; + +union TrustLineAsset switch (AssetType type) +{ +case ASSET_TYPE_NATIVE: // Not credit + void; + +case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4 alphaNum4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12 alphaNum12; + +case ASSET_TYPE_POOL_SHARE: + PoolID liquidityPoolID; + + // add other asset types here in the future +}; + +struct TrustLineEntryExtensionV2 +{ + int32 liquidityPoolUseCount; + + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct TrustLineEntry +{ + AccountID accountID; // account this trustline belongs to + TrustLineAsset asset; // type of asset (with issuer) + int64 balance; // how much of this asset the user has. + // Asset defines the unit for this; + + int64 limit; // balance cannot be above this + uint32 flags; // see TrustLineFlags + + // reserved for future use + union switch (int v) + { + case 0: + void; + case 1: + struct + { + Liabilities liabilities; + + union switch (int v) + { + case 0: + void; + case 2: + TrustLineEntryExtensionV2 v2; + } + ext; + } v1; + } + ext; +}; + +enum OfferEntryFlags +{ + // an offer with this flag will not act on and take a reverse offer of equal + // price + PASSIVE_FLAG = 1 +}; + +// Mask for OfferEntry flags +const MASK_OFFERENTRY_FLAGS = 1; + +/* OfferEntry + An offer is the building block of the offer book, they are automatically + claimed by payments when the price set by the owner is met. + + For example an Offer is selling 10A where 1A is priced at 1.5B + +*/ +struct OfferEntry +{ + AccountID sellerID; + int64 offerID; + Asset selling; // A + Asset buying; // B + int64 amount; // amount of A + + /* price for this offer: + price of A in terms of B + price=AmountB/AmountA=priceNumerator/priceDenominator + price is after fees + */ + Price price; + uint32 flags; // see OfferEntryFlags + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +/* DataEntry + Data can be attached to accounts. +*/ +struct DataEntry +{ + AccountID accountID; // account this data belongs to + string64 dataName; + DataValue dataValue; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +enum ClaimPredicateType +{ + CLAIM_PREDICATE_UNCONDITIONAL = 0, + CLAIM_PREDICATE_AND = 1, + CLAIM_PREDICATE_OR = 2, + CLAIM_PREDICATE_NOT = 3, + CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME = 4, + CLAIM_PREDICATE_BEFORE_RELATIVE_TIME = 5 +}; + +union ClaimPredicate switch (ClaimPredicateType type) +{ +case CLAIM_PREDICATE_UNCONDITIONAL: + void; +case CLAIM_PREDICATE_AND: + ClaimPredicate andPredicates<2>; +case CLAIM_PREDICATE_OR: + ClaimPredicate orPredicates<2>; +case CLAIM_PREDICATE_NOT: + ClaimPredicate* notPredicate; +case CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME: + int64 absBefore; // Predicate will be true if closeTime < absBefore +case CLAIM_PREDICATE_BEFORE_RELATIVE_TIME: + int64 relBefore; // Seconds since closeTime of the ledger in which the + // ClaimableBalanceEntry was created +}; + +enum ClaimantType +{ + CLAIMANT_TYPE_V0 = 0 +}; + +union Claimant switch (ClaimantType type) +{ +case CLAIMANT_TYPE_V0: + struct + { + AccountID destination; // The account that can use this condition + ClaimPredicate predicate; // Claimable if predicate is true + } v0; +}; + +enum ClaimableBalanceIDType +{ + CLAIMABLE_BALANCE_ID_TYPE_V0 = 0 +}; + +union ClaimableBalanceID switch (ClaimableBalanceIDType type) +{ +case CLAIMABLE_BALANCE_ID_TYPE_V0: + Hash v0; +}; + +enum ClaimableBalanceFlags +{ + // If set, the issuer account of the asset held by the claimable balance may + // clawback the claimable balance + CLAIMABLE_BALANCE_CLAWBACK_ENABLED_FLAG = 0x1 +}; + +const MASK_CLAIMABLE_BALANCE_FLAGS = 0x1; + +struct ClaimableBalanceEntryExtensionV1 +{ + union switch (int v) + { + case 0: + void; + } + ext; + + uint32 flags; // see ClaimableBalanceFlags +}; + +struct ClaimableBalanceEntry +{ + // Unique identifier for this ClaimableBalanceEntry + ClaimableBalanceID balanceID; + + // List of claimants with associated predicate + Claimant claimants<10>; + + // Any asset including native + Asset asset; + + // Amount of asset + int64 amount; + + // reserved for future use + union switch (int v) + { + case 0: + void; + case 1: + ClaimableBalanceEntryExtensionV1 v1; + } + ext; +}; + +struct LiquidityPoolConstantProductParameters +{ + Asset assetA; // assetA < assetB + Asset assetB; + int32 fee; // Fee is in basis points, so the actual rate is (fee/100)% +}; + +struct LiquidityPoolEntry +{ + PoolID liquidityPoolID; + + union switch (LiquidityPoolType type) + { + case LIQUIDITY_POOL_CONSTANT_PRODUCT: + struct + { + LiquidityPoolConstantProductParameters params; + + int64 reserveA; // amount of A in the pool + int64 reserveB; // amount of B in the pool + int64 totalPoolShares; // total number of pool shares issued + int64 poolSharesTrustLineCount; // number of trust lines for the + // associated pool shares + } constantProduct; + } + body; +}; + +struct ContractDataEntry { + Hash contractID; + SCVal key; + SCVal val; +}; + +enum ConfigSettingType +{ + CONFIG_SETTING_TYPE_UINT32 = 0 +}; + +union ConfigSetting switch (ConfigSettingType type) +{ +case CONFIG_SETTING_TYPE_UINT32: + uint32 uint32Val; +}; + +enum ConfigSettingID +{ + CONFIG_SETTING_CONTRACT_MAX_SIZE = 0 +}; + +struct ConfigSettingEntry +{ + union switch (int v) + { + case 0: + void; + } + ext; + + ConfigSettingID configSettingID; + ConfigSetting setting; +}; + +struct LedgerEntryExtensionV1 +{ + SponsorshipDescriptor sponsoringID; + + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct LedgerEntry +{ + uint32 lastModifiedLedgerSeq; // ledger the LedgerEntry was last changed + + union switch (LedgerEntryType type) + { + case ACCOUNT: + AccountEntry account; + case TRUSTLINE: + TrustLineEntry trustLine; + case OFFER: + OfferEntry offer; + case DATA: + DataEntry data; + case CLAIMABLE_BALANCE: + ClaimableBalanceEntry claimableBalance; + case LIQUIDITY_POOL: + LiquidityPoolEntry liquidityPool; + case CONTRACT_DATA: + ContractDataEntry contractData; + case CONFIG_SETTING: + ConfigSettingEntry configSetting; + } + data; + + // reserved for future use + union switch (int v) + { + case 0: + void; + case 1: + LedgerEntryExtensionV1 v1; + } + ext; +}; + +union LedgerKey switch (LedgerEntryType type) +{ +case ACCOUNT: + struct + { + AccountID accountID; + } account; + +case TRUSTLINE: + struct + { + AccountID accountID; + TrustLineAsset asset; + } trustLine; + +case OFFER: + struct + { + AccountID sellerID; + int64 offerID; + } offer; + +case DATA: + struct + { + AccountID accountID; + string64 dataName; + } data; + +case CLAIMABLE_BALANCE: + struct + { + ClaimableBalanceID balanceID; + } claimableBalance; + +case LIQUIDITY_POOL: + struct + { + PoolID liquidityPoolID; + } liquidityPool; +case CONTRACT_DATA: + struct + { + Hash contractID; + SCVal key; + } contractData; +case CONFIG_SETTING: + struct + { + ConfigSettingID configSettingID; + } configSetting; +}; + +// list of all envelope types used in the application +// those are prefixes used when building signatures for +// the respective envelopes +enum EnvelopeType +{ + ENVELOPE_TYPE_TX_V0 = 0, + ENVELOPE_TYPE_SCP = 1, + ENVELOPE_TYPE_TX = 2, + ENVELOPE_TYPE_AUTH = 3, + ENVELOPE_TYPE_SCPVALUE = 4, + ENVELOPE_TYPE_TX_FEE_BUMP = 5, + ENVELOPE_TYPE_OP_ID = 6, + ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7, + ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8, + ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9 +}; +} diff --git a/Stellar-ledger.x b/Stellar-ledger.x new file mode 100644 index 0000000..49d1c3c --- /dev/null +++ b/Stellar-ledger.x @@ -0,0 +1,377 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +%#include "xdr/Stellar-SCP.h" +%#include "xdr/Stellar-transaction.h" + +namespace stellar +{ + +typedef opaque UpgradeType<128>; + +enum StellarValueType +{ + STELLAR_VALUE_BASIC = 0, + STELLAR_VALUE_SIGNED = 1 +}; + +struct LedgerCloseValueSignature +{ + NodeID nodeID; // which node introduced the value + Signature signature; // nodeID's signature +}; + +/* StellarValue is the value used by SCP to reach consensus on a given ledger + */ +struct StellarValue +{ + Hash txSetHash; // transaction set to apply to previous ledger + TimePoint closeTime; // network close time + + // upgrades to apply to the previous ledger (usually empty) + // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop + // unknown steps during consensus if needed. + // see notes below on 'LedgerUpgrade' for more detail + // max size is dictated by number of upgrade types (+ room for future) + UpgradeType upgrades<6>; + + // reserved for future use + union switch (StellarValueType v) + { + case STELLAR_VALUE_BASIC: + void; + case STELLAR_VALUE_SIGNED: + LedgerCloseValueSignature lcValueSignature; + } + ext; +}; + +const MASK_LEDGER_HEADER_FLAGS = 0x7F; + +enum LedgerHeaderFlags +{ + DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 0x1, + DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 0x2, + DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4, + DISABLE_CONTRACT_CREATE = 0x8, + DISABLE_CONTRACT_UPDATE = 0x10, + DISABLE_CONTRACT_REMOVE = 0x20, + DISABLE_CONTRACT_INVOKE = 0x40 +}; + +struct LedgerHeaderExtensionV1 +{ + uint32 flags; // LedgerHeaderFlags + + union switch (int v) + { + case 0: + void; + } + ext; +}; + +/* The LedgerHeader is the highest level structure representing the + * state of a ledger, cryptographically linked to previous ledgers. + */ +struct LedgerHeader +{ + uint32 ledgerVersion; // the protocol version of the ledger + Hash previousLedgerHash; // hash of the previous ledger header + StellarValue scpValue; // what consensus agreed to + Hash txSetResultHash; // the TransactionResultSet that led to this ledger + Hash bucketListHash; // hash of the ledger state + + uint32 ledgerSeq; // sequence number of this ledger + + int64 totalCoins; // total number of stroops in existence. + // 10,000,000 stroops in 1 XLM + + int64 feePool; // fees burned since last inflation run + uint32 inflationSeq; // inflation sequence number + + uint64 idPool; // last used global ID, used for generating objects + + uint32 baseFee; // base fee per operation in stroops + uint32 baseReserve; // account base reserve in stroops + + uint32 maxTxSetSize; // maximum size a transaction set can be + + Hash skipList[4]; // hashes of ledgers in the past. allows you to jump back + // in time without walking the chain back ledger by ledger + // each slot contains the oldest ledger that is mod of + // either 50 5000 50000 or 500000 depending on index + // skipList[0] mod(50), skipList[1] mod(5000), etc + + // reserved for future use + union switch (int v) + { + case 0: + void; + case 1: + LedgerHeaderExtensionV1 v1; + } + ext; +}; + +/* Ledger upgrades +note that the `upgrades` field from StellarValue is normalized such that +it only contains one entry per LedgerUpgradeType, and entries are sorted +in ascending order +*/ +enum LedgerUpgradeType +{ + LEDGER_UPGRADE_VERSION = 1, + LEDGER_UPGRADE_BASE_FEE = 2, + LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, + LEDGER_UPGRADE_BASE_RESERVE = 4, + LEDGER_UPGRADE_FLAGS = 5, + LEDGER_UPGRADE_CONFIG = 6 +}; + +union LedgerUpgrade switch (LedgerUpgradeType type) +{ +case LEDGER_UPGRADE_VERSION: + uint32 newLedgerVersion; // update ledgerVersion +case LEDGER_UPGRADE_BASE_FEE: + uint32 newBaseFee; // update baseFee +case LEDGER_UPGRADE_MAX_TX_SET_SIZE: + uint32 newMaxTxSetSize; // update maxTxSetSize +case LEDGER_UPGRADE_BASE_RESERVE: + uint32 newBaseReserve; // update baseReserve +case LEDGER_UPGRADE_FLAGS: + uint32 newFlags; // update flags +case LEDGER_UPGRADE_CONFIG: + struct + { + ConfigSettingID id; // id to update + ConfigSetting setting; // new value + } configSetting; +}; + +/* Entries used to define the bucket list */ +enum BucketEntryType +{ + METAENTRY = + -1, // At-and-after protocol 11: bucket metadata, should come first. + LIVEENTRY = 0, // Before protocol 11: created-or-updated; + // At-and-after protocol 11: only updated. + DEADENTRY = 1, + INITENTRY = 2 // At-and-after protocol 11: only created. +}; + +struct BucketMetadata +{ + // Indicates the protocol version used to create / merge this bucket. + uint32 ledgerVersion; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +union BucketEntry switch (BucketEntryType type) +{ +case LIVEENTRY: +case INITENTRY: + LedgerEntry liveEntry; + +case DEADENTRY: + LedgerKey deadEntry; +case METAENTRY: + BucketMetadata metaEntry; +}; + +// Transaction sets are the unit used by SCP to decide on transitions +// between ledgers +struct TransactionSet +{ + Hash previousLedgerHash; + TransactionEnvelope txs<>; +}; + +struct TransactionResultPair +{ + Hash transactionHash; + TransactionResult result; // result for the transaction +}; + +// TransactionResultSet is used to recover results between ledgers +struct TransactionResultSet +{ + TransactionResultPair results<>; +}; + +// Entries below are used in the historical subsystem + +struct TransactionHistoryEntry +{ + uint32 ledgerSeq; + TransactionSet txSet; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct TransactionHistoryResultEntry +{ + uint32 ledgerSeq; + TransactionResultSet txResultSet; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct LedgerHeaderHistoryEntry +{ + Hash hash; + LedgerHeader header; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +// historical SCP messages + +struct LedgerSCPMessages +{ + uint32 ledgerSeq; + SCPEnvelope messages<>; +}; + +// note: ledgerMessages may refer to any quorumSets encountered +// in the file so far, not just the one from this entry +struct SCPHistoryEntryV0 +{ + SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages + LedgerSCPMessages ledgerMessages; +}; + +// SCP history file is an array of these +union SCPHistoryEntry switch (int v) +{ +case 0: + SCPHistoryEntryV0 v0; +}; + +// represents the meta in the transaction table history + +// STATE is emitted every time a ledger entry is modified/deleted +// and the entry was not already modified in the current ledger + +enum LedgerEntryChangeType +{ + LEDGER_ENTRY_CREATED = 0, // entry was added to the ledger + LEDGER_ENTRY_UPDATED = 1, // entry was modified in the ledger + LEDGER_ENTRY_REMOVED = 2, // entry was removed from the ledger + LEDGER_ENTRY_STATE = 3 // value of the entry +}; + +union LedgerEntryChange switch (LedgerEntryChangeType type) +{ +case LEDGER_ENTRY_CREATED: + LedgerEntry created; +case LEDGER_ENTRY_UPDATED: + LedgerEntry updated; +case LEDGER_ENTRY_REMOVED: + LedgerKey removed; +case LEDGER_ENTRY_STATE: + LedgerEntry state; +}; + +typedef LedgerEntryChange LedgerEntryChanges<>; + +struct OperationMeta +{ + LedgerEntryChanges changes; +}; + +struct TransactionMetaV1 +{ + LedgerEntryChanges txChanges; // tx level changes if any + OperationMeta operations<>; // meta for each operation +}; + +struct TransactionMetaV2 +{ + LedgerEntryChanges txChangesBefore; // tx level changes before operations + // are applied if any + OperationMeta operations<>; // meta for each operation + LedgerEntryChanges txChangesAfter; // tx level changes after operations are + // applied if any +}; + +// this is the meta produced when applying transactions +// it does not include pre-apply updates such as fees +union TransactionMeta switch (int v) +{ +case 0: + OperationMeta operations<>; +case 1: + TransactionMetaV1 v1; +case 2: + TransactionMetaV2 v2; +}; + +// This struct groups together changes on a per transaction basis +// note however that fees and transaction application are done in separate +// phases +struct TransactionResultMeta +{ + TransactionResultPair result; + LedgerEntryChanges feeProcessing; + TransactionMeta txApplyProcessing; +}; + +// this represents a single upgrade that was performed as part of a ledger +// upgrade +struct UpgradeEntryMeta +{ + LedgerUpgrade upgrade; + LedgerEntryChanges changes; +}; + +struct LedgerCloseMetaV0 +{ + LedgerHeaderHistoryEntry ledgerHeader; + // NB: txSet is sorted in "Hash order" + TransactionSet txSet; + + // NB: transactions are sorted in apply order here + // fees for all transactions are processed first + // followed by applying transactions + TransactionResultMeta txProcessing<>; + + // upgrades are applied last + UpgradeEntryMeta upgradesProcessing<>; + + // other misc information attached to the ledger close + SCPHistoryEntry scpInfo<>; +}; + +union LedgerCloseMeta switch (int v) +{ +case 0: + LedgerCloseMetaV0 v0; +}; +} diff --git a/Stellar-overlay.x b/Stellar-overlay.x new file mode 100644 index 0000000..9e3a083 --- /dev/null +++ b/Stellar-overlay.x @@ -0,0 +1,238 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +%#include "xdr/Stellar-ledger.h" + +namespace stellar +{ + +enum ErrorCode +{ + ERR_MISC = 0, // Unspecific error + ERR_DATA = 1, // Malformed data + ERR_CONF = 2, // Misconfiguration error + ERR_AUTH = 3, // Authentication failure + ERR_LOAD = 4 // System overloaded +}; + +struct Error +{ + ErrorCode code; + string msg<100>; +}; + +struct SendMore +{ + uint32 numMessages; +}; + +struct AuthCert +{ + Curve25519Public pubkey; + uint64 expiration; + Signature sig; +}; + +struct Hello +{ + uint32 ledgerVersion; + uint32 overlayVersion; + uint32 overlayMinVersion; + Hash networkID; + string versionStr<100>; + int listeningPort; + NodeID peerID; + AuthCert cert; + uint256 nonce; +}; + +struct Auth +{ + // Empty message, just to confirm + // establishment of MAC keys. + int unused; +}; + +enum IPAddrType +{ + IPv4 = 0, + IPv6 = 1 +}; + +struct PeerAddress +{ + union switch (IPAddrType type) + { + case IPv4: + opaque ipv4[4]; + case IPv6: + opaque ipv6[16]; + } + ip; + uint32 port; + uint32 numFailures; +}; + +enum MessageType +{ + ERROR_MSG = 0, + AUTH = 2, + DONT_HAVE = 3, + + GET_PEERS = 4, // gets a list of peers this guy knows about + PEERS = 5, + + GET_TX_SET = 6, // gets a particular txset by hash + TX_SET = 7, + + TRANSACTION = 8, // pass on a tx you have heard about + + // SCP + GET_SCP_QUORUMSET = 9, + SCP_QUORUMSET = 10, + SCP_MESSAGE = 11, + GET_SCP_STATE = 12, + + // new messages + HELLO = 13, + + SURVEY_REQUEST = 14, + SURVEY_RESPONSE = 15, + + SEND_MORE = 16 +}; + +struct DontHave +{ + MessageType type; + uint256 reqHash; +}; + +enum SurveyMessageCommandType +{ + SURVEY_TOPOLOGY = 0 +}; + +struct SurveyRequestMessage +{ + NodeID surveyorPeerID; + NodeID surveyedPeerID; + uint32 ledgerNum; + Curve25519Public encryptionKey; + SurveyMessageCommandType commandType; +}; + +struct SignedSurveyRequestMessage +{ + Signature requestSignature; + SurveyRequestMessage request; +}; + +typedef opaque EncryptedBody<64000>; +struct SurveyResponseMessage +{ + NodeID surveyorPeerID; + NodeID surveyedPeerID; + uint32 ledgerNum; + SurveyMessageCommandType commandType; + EncryptedBody encryptedBody; +}; + +struct SignedSurveyResponseMessage +{ + Signature responseSignature; + SurveyResponseMessage response; +}; + +struct PeerStats +{ + NodeID id; + string versionStr<100>; + uint64 messagesRead; + uint64 messagesWritten; + uint64 bytesRead; + uint64 bytesWritten; + uint64 secondsConnected; + + uint64 uniqueFloodBytesRecv; + uint64 duplicateFloodBytesRecv; + uint64 uniqueFetchBytesRecv; + uint64 duplicateFetchBytesRecv; + + uint64 uniqueFloodMessageRecv; + uint64 duplicateFloodMessageRecv; + uint64 uniqueFetchMessageRecv; + uint64 duplicateFetchMessageRecv; +}; + +typedef PeerStats PeerStatList<25>; + +struct TopologyResponseBody +{ + PeerStatList inboundPeers; + PeerStatList outboundPeers; + + uint32 totalInboundPeerCount; + uint32 totalOutboundPeerCount; +}; + +union SurveyResponseBody switch (SurveyMessageCommandType type) +{ +case SURVEY_TOPOLOGY: + TopologyResponseBody topologyResponseBody; +}; + +union StellarMessage switch (MessageType type) +{ +case ERROR_MSG: + Error error; +case HELLO: + Hello hello; +case AUTH: + Auth auth; +case DONT_HAVE: + DontHave dontHave; +case GET_PEERS: + void; +case PEERS: + PeerAddress peers<100>; + +case GET_TX_SET: + uint256 txSetHash; +case TX_SET: + TransactionSet txSet; + +case TRANSACTION: + TransactionEnvelope transaction; + +case SURVEY_REQUEST: + SignedSurveyRequestMessage signedSurveyRequestMessage; + +case SURVEY_RESPONSE: + SignedSurveyResponseMessage signedSurveyResponseMessage; + +// SCP +case GET_SCP_QUORUMSET: + uint256 qSetHash; +case SCP_QUORUMSET: + SCPQuorumSet qSet; +case SCP_MESSAGE: + SCPEnvelope envelope; +case GET_SCP_STATE: + uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest +case SEND_MORE: + SendMore sendMoreMessage; +}; + +union AuthenticatedMessage switch (uint32 v) +{ +case 0: + struct + { + uint64 sequence; + StellarMessage message; + HmacSha256Mac mac; + } v0; +}; +} diff --git a/Stellar-transaction.x b/Stellar-transaction.x new file mode 100644 index 0000000..239609f --- /dev/null +++ b/Stellar-transaction.x @@ -0,0 +1,1843 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +%#include "xdr/Stellar-contract.h" +%#include "xdr/Stellar-ledger-entries.h" + +namespace stellar +{ + +union LiquidityPoolParameters switch (LiquidityPoolType type) +{ +case LIQUIDITY_POOL_CONSTANT_PRODUCT: + LiquidityPoolConstantProductParameters constantProduct; +}; + +// Source or destination of a payment operation +union MuxedAccount switch (CryptoKeyType type) +{ +case KEY_TYPE_ED25519: + uint256 ed25519; +case KEY_TYPE_MUXED_ED25519: + struct + { + uint64 id; + uint256 ed25519; + } med25519; +}; + +struct DecoratedSignature +{ + SignatureHint hint; // last 4 bytes of the public key, used as a hint + Signature signature; // actual signature +}; + +// Ledger key sets touched by a smart contract transaction. +struct LedgerFootprint +{ + LedgerKey readOnly<>; + LedgerKey readWrite<>; +}; + +enum OperationType +{ + CREATE_ACCOUNT = 0, + PAYMENT = 1, + PATH_PAYMENT_STRICT_RECEIVE = 2, + MANAGE_SELL_OFFER = 3, + CREATE_PASSIVE_SELL_OFFER = 4, + SET_OPTIONS = 5, + CHANGE_TRUST = 6, + ALLOW_TRUST = 7, + ACCOUNT_MERGE = 8, + INFLATION = 9, + MANAGE_DATA = 10, + BUMP_SEQUENCE = 11, + MANAGE_BUY_OFFER = 12, + PATH_PAYMENT_STRICT_SEND = 13, + CREATE_CLAIMABLE_BALANCE = 14, + CLAIM_CLAIMABLE_BALANCE = 15, + BEGIN_SPONSORING_FUTURE_RESERVES = 16, + END_SPONSORING_FUTURE_RESERVES = 17, + REVOKE_SPONSORSHIP = 18, + CLAWBACK = 19, + CLAWBACK_CLAIMABLE_BALANCE = 20, + SET_TRUST_LINE_FLAGS = 21, + LIQUIDITY_POOL_DEPOSIT = 22, + LIQUIDITY_POOL_WITHDRAW = 23, + INVOKE_HOST_FUNCTION = 24 +}; + +/* CreateAccount +Creates and funds a new account with the specified starting balance. + +Threshold: med + +Result: CreateAccountResult + +*/ +struct CreateAccountOp +{ + AccountID destination; // account to create + int64 startingBalance; // amount they end up with +}; + +/* Payment + + Send an amount in specified asset to a destination account. + + Threshold: med + + Result: PaymentResult +*/ +struct PaymentOp +{ + MuxedAccount destination; // recipient of the payment + Asset asset; // what they end up with + int64 amount; // amount they end up with +}; + +/* PathPaymentStrictReceive + +send an amount to a destination account through a path. +(up to sendMax, sendAsset) +(X0, Path[0]) .. (Xn, Path[n]) +(destAmount, destAsset) + +Threshold: med + +Result: PathPaymentStrictReceiveResult +*/ +struct PathPaymentStrictReceiveOp +{ + Asset sendAsset; // asset we pay with + int64 sendMax; // the maximum amount of sendAsset to + // send (excluding fees). + // The operation will fail if can't be met + + MuxedAccount destination; // recipient of the payment + Asset destAsset; // what they end up with + int64 destAmount; // amount they end up with + + Asset path<5>; // additional hops it must go through to get there +}; + +/* PathPaymentStrictSend + +send an amount to a destination account through a path. +(sendMax, sendAsset) +(X0, Path[0]) .. (Xn, Path[n]) +(at least destAmount, destAsset) + +Threshold: med + +Result: PathPaymentStrictSendResult +*/ +struct PathPaymentStrictSendOp +{ + Asset sendAsset; // asset we pay with + int64 sendAmount; // amount of sendAsset to send (excluding fees) + + MuxedAccount destination; // recipient of the payment + Asset destAsset; // what they end up with + int64 destMin; // the minimum amount of dest asset to + // be received + // The operation will fail if it can't be met + + Asset path<5>; // additional hops it must go through to get there +}; + +/* Creates, updates or deletes an offer + +Threshold: med + +Result: ManageSellOfferResult + +*/ +struct ManageSellOfferOp +{ + Asset selling; + Asset buying; + int64 amount; // amount being sold. if set to 0, delete the offer + Price price; // price of thing being sold in terms of what you are buying + + // 0=create a new offer, otherwise edit an existing offer + int64 offerID; +}; + +/* Creates, updates or deletes an offer with amount in terms of buying asset + +Threshold: med + +Result: ManageBuyOfferResult + +*/ +struct ManageBuyOfferOp +{ + Asset selling; + Asset buying; + int64 buyAmount; // amount being bought. if set to 0, delete the offer + Price price; // price of thing being bought in terms of what you are + // selling + + // 0=create a new offer, otherwise edit an existing offer + int64 offerID; +}; + +/* Creates an offer that doesn't take offers of the same price + +Threshold: med + +Result: CreatePassiveSellOfferResult + +*/ +struct CreatePassiveSellOfferOp +{ + Asset selling; // A + Asset buying; // B + int64 amount; // amount taker gets + Price price; // cost of A in terms of B +}; + +/* Set Account Options + + updates "AccountEntry" fields. + note: updating thresholds or signers requires high threshold + + Threshold: med or high + + Result: SetOptionsResult +*/ +struct SetOptionsOp +{ + AccountID* inflationDest; // sets the inflation destination + + uint32* clearFlags; // which flags to clear + uint32* setFlags; // which flags to set + + // account threshold manipulation + uint32* masterWeight; // weight of the master account + uint32* lowThreshold; + uint32* medThreshold; + uint32* highThreshold; + + string32* homeDomain; // sets the home domain + + // Add, update or remove a signer for the account + // signer is deleted if the weight is 0 + Signer* signer; +}; + +union ChangeTrustAsset switch (AssetType type) +{ +case ASSET_TYPE_NATIVE: // Not credit + void; + +case ASSET_TYPE_CREDIT_ALPHANUM4: + AlphaNum4 alphaNum4; + +case ASSET_TYPE_CREDIT_ALPHANUM12: + AlphaNum12 alphaNum12; + +case ASSET_TYPE_POOL_SHARE: + LiquidityPoolParameters liquidityPool; + + // add other asset types here in the future +}; + +/* Creates, updates or deletes a trust line + + Threshold: med + + Result: ChangeTrustResult + +*/ +struct ChangeTrustOp +{ + ChangeTrustAsset line; + + // if limit is set to 0, deletes the trust line + int64 limit; +}; + +/* Updates the "authorized" flag of an existing trust line + this is called by the issuer of the related asset. + + note that authorize can only be set (and not cleared) if + the issuer account does not have the AUTH_REVOCABLE_FLAG set + Threshold: low + + Result: AllowTrustResult +*/ +struct AllowTrustOp +{ + AccountID trustor; + AssetCode asset; + + // One of 0, AUTHORIZED_FLAG, or AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG + uint32 authorize; +}; + +/* Inflation + Runs inflation + +Threshold: low + +Result: InflationResult + +*/ + +/* AccountMerge + Transfers native balance to destination account. + + Threshold: high + + Result : AccountMergeResult +*/ + +/* ManageData + Adds, Updates, or Deletes a key value pair associated with a particular + account. + + Threshold: med + + Result: ManageDataResult +*/ +struct ManageDataOp +{ + string64 dataName; + DataValue* dataValue; // set to null to clear +}; + +/* Bump Sequence + + increases the sequence to a given level + + Threshold: low + + Result: BumpSequenceResult +*/ +struct BumpSequenceOp +{ + SequenceNumber bumpTo; +}; + +/* Creates a claimable balance entry + + Threshold: med + + Result: CreateClaimableBalanceResult +*/ +struct CreateClaimableBalanceOp +{ + Asset asset; + int64 amount; + Claimant claimants<10>; +}; + +/* Claims a claimable balance entry + + Threshold: low + + Result: ClaimClaimableBalanceResult +*/ +struct ClaimClaimableBalanceOp +{ + ClaimableBalanceID balanceID; +}; + +/* BeginSponsoringFutureReserves + + Establishes the is-sponsoring-future-reserves-for relationship between + the source account and sponsoredID + + Threshold: med + + Result: BeginSponsoringFutureReservesResult +*/ +struct BeginSponsoringFutureReservesOp +{ + AccountID sponsoredID; +}; + +/* EndSponsoringFutureReserves + + Terminates the current is-sponsoring-future-reserves-for relationship in + which source account is sponsored + + Threshold: med + + Result: EndSponsoringFutureReservesResult +*/ +// EndSponsoringFutureReserves is empty + +/* RevokeSponsorship + + If source account is not sponsored or is sponsored by the owner of the + specified entry or sub-entry, then attempt to revoke the sponsorship. + If source account is sponsored, then attempt to transfer the sponsorship + to the sponsor of source account. + + Threshold: med + + Result: RevokeSponsorshipResult +*/ +enum RevokeSponsorshipType +{ + REVOKE_SPONSORSHIP_LEDGER_ENTRY = 0, + REVOKE_SPONSORSHIP_SIGNER = 1 +}; + +union RevokeSponsorshipOp switch (RevokeSponsorshipType type) +{ +case REVOKE_SPONSORSHIP_LEDGER_ENTRY: + LedgerKey ledgerKey; +case REVOKE_SPONSORSHIP_SIGNER: + struct + { + AccountID accountID; + SignerKey signerKey; + } signer; +}; + +/* Claws back an amount of an asset from an account + + Threshold: med + + Result: ClawbackResult +*/ +struct ClawbackOp +{ + Asset asset; + MuxedAccount from; + int64 amount; +}; + +/* Claws back a claimable balance + + Threshold: med + + Result: ClawbackClaimableBalanceResult +*/ +struct ClawbackClaimableBalanceOp +{ + ClaimableBalanceID balanceID; +}; + +/* SetTrustLineFlagsOp + + Updates the flags of an existing trust line. + This is called by the issuer of the related asset. + + Threshold: low + + Result: SetTrustLineFlagsResult +*/ +struct SetTrustLineFlagsOp +{ + AccountID trustor; + Asset asset; + + uint32 clearFlags; // which flags to clear + uint32 setFlags; // which flags to set +}; + +const LIQUIDITY_POOL_FEE_V18 = 30; + +/* Deposit assets into a liquidity pool + + Threshold: med + + Result: LiquidityPoolDepositResult +*/ +struct LiquidityPoolDepositOp +{ + PoolID liquidityPoolID; + int64 maxAmountA; // maximum amount of first asset to deposit + int64 maxAmountB; // maximum amount of second asset to deposit + Price minPrice; // minimum depositA/depositB + Price maxPrice; // maximum depositA/depositB +}; + +/* Withdraw assets from a liquidity pool + + Threshold: med + + Result: LiquidityPoolWithdrawResult +*/ +struct LiquidityPoolWithdrawOp +{ + PoolID liquidityPoolID; + int64 amount; // amount of pool shares to withdraw + int64 minAmountA; // minimum amount of first asset to withdraw + int64 minAmountB; // minimum amount of second asset to withdraw +}; + +enum HostFunction +{ + HOST_FN_CALL = 0, + HOST_FN_CREATE_CONTRACT = 1 +}; + +struct InvokeHostFunctionOp +{ + // The host function to invoke + HostFunction function; + + // Parameters to the host function + SCVec parameters; + + // The footprint for this invocation + LedgerFootprint footprint; +}; + +/* An operation is the lowest unit of work that a transaction does */ +struct Operation +{ + // sourceAccount is the account used to run the operation + // if not set, the runtime defaults to "sourceAccount" specified at + // the transaction level + MuxedAccount* sourceAccount; + + union switch (OperationType type) + { + case CREATE_ACCOUNT: + CreateAccountOp createAccountOp; + case PAYMENT: + PaymentOp paymentOp; + case PATH_PAYMENT_STRICT_RECEIVE: + PathPaymentStrictReceiveOp pathPaymentStrictReceiveOp; + case MANAGE_SELL_OFFER: + ManageSellOfferOp manageSellOfferOp; + case CREATE_PASSIVE_SELL_OFFER: + CreatePassiveSellOfferOp createPassiveSellOfferOp; + case SET_OPTIONS: + SetOptionsOp setOptionsOp; + case CHANGE_TRUST: + ChangeTrustOp changeTrustOp; + case ALLOW_TRUST: + AllowTrustOp allowTrustOp; + case ACCOUNT_MERGE: + MuxedAccount destination; + case INFLATION: + void; + case MANAGE_DATA: + ManageDataOp manageDataOp; + case BUMP_SEQUENCE: + BumpSequenceOp bumpSequenceOp; + case MANAGE_BUY_OFFER: + ManageBuyOfferOp manageBuyOfferOp; + case PATH_PAYMENT_STRICT_SEND: + PathPaymentStrictSendOp pathPaymentStrictSendOp; + case CREATE_CLAIMABLE_BALANCE: + CreateClaimableBalanceOp createClaimableBalanceOp; + case CLAIM_CLAIMABLE_BALANCE: + ClaimClaimableBalanceOp claimClaimableBalanceOp; + case BEGIN_SPONSORING_FUTURE_RESERVES: + BeginSponsoringFutureReservesOp beginSponsoringFutureReservesOp; + case END_SPONSORING_FUTURE_RESERVES: + void; + case REVOKE_SPONSORSHIP: + RevokeSponsorshipOp revokeSponsorshipOp; + case CLAWBACK: + ClawbackOp clawbackOp; + case CLAWBACK_CLAIMABLE_BALANCE: + ClawbackClaimableBalanceOp clawbackClaimableBalanceOp; + case SET_TRUST_LINE_FLAGS: + SetTrustLineFlagsOp setTrustLineFlagsOp; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositOp liquidityPoolDepositOp; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; + case INVOKE_HOST_FUNCTION: + InvokeHostFunctionOp invokeHostFunctionOp; + } + body; +}; + +union HashIDPreimage switch (EnvelopeType type) +{ +case ENVELOPE_TYPE_OP_ID: + struct + { + AccountID sourceAccount; + SequenceNumber seqNum; + uint32 opNum; + } operationID; +case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: + struct + { + AccountID sourceAccount; + SequenceNumber seqNum; + uint32 opNum; + PoolID liquidityPoolID; + Asset asset; + } revokeID; +case ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: + struct + { + uint256 ed25519; + uint256 salt; + } contractID; +case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: + struct + { + Hash contractID; //contractID of parent contract + uint256 salt; + } childContractID; +}; + +enum MemoType +{ + MEMO_NONE = 0, + MEMO_TEXT = 1, + MEMO_ID = 2, + MEMO_HASH = 3, + MEMO_RETURN = 4 +}; + +union Memo switch (MemoType type) +{ +case MEMO_NONE: + void; +case MEMO_TEXT: + string text<28>; +case MEMO_ID: + uint64 id; +case MEMO_HASH: + Hash hash; // the hash of what to pull from the content server +case MEMO_RETURN: + Hash retHash; // the hash of the tx you are rejecting +}; + +struct TimeBounds +{ + TimePoint minTime; + TimePoint maxTime; // 0 here means no maxTime +}; + +struct LedgerBounds +{ + uint32 minLedger; + uint32 maxLedger; // 0 here means no maxLedger +}; + +struct PreconditionsV2 +{ + TimeBounds* timeBounds; + + // Transaction only valid for ledger numbers n such that + // minLedger <= n < maxLedger (if maxLedger == 0, then + // only minLedger is checked) + LedgerBounds* ledgerBounds; + + // If NULL, only valid when sourceAccount's sequence number + // is seqNum - 1. Otherwise, valid when sourceAccount's + // sequence number n satisfies minSeqNum <= n < tx.seqNum. + // Note that after execution the account's sequence number + // is always raised to tx.seqNum, and a transaction is not + // valid if tx.seqNum is too high to ensure replay protection. + SequenceNumber* minSeqNum; + + // For the transaction to be valid, the current ledger time must + // be at least minSeqAge greater than sourceAccount's seqTime. + Duration minSeqAge; + + // For the transaction to be valid, the current ledger number + // must be at least minSeqLedgerGap greater than sourceAccount's + // seqLedger. + uint32 minSeqLedgerGap; + + // For the transaction to be valid, there must be a signature + // corresponding to every Signer in this array, even if the + // signature is not otherwise required by the sourceAccount or + // operations. + SignerKey extraSigners<2>; +}; + +enum PreconditionType +{ + PRECOND_NONE = 0, + PRECOND_TIME = 1, + PRECOND_V2 = 2 +}; + +union Preconditions switch (PreconditionType type) +{ +case PRECOND_NONE: + void; +case PRECOND_TIME: + TimeBounds timeBounds; +case PRECOND_V2: + PreconditionsV2 v2; +}; + +// maximum number of operations per transaction +const MAX_OPS_PER_TX = 100; + +// TransactionV0 is a transaction with the AccountID discriminant stripped off, +// leaving a raw ed25519 public key to identify the source account. This is used +// for backwards compatibility starting from the protocol 12/13 boundary. If an +// "old-style" TransactionEnvelope containing a Transaction is parsed with this +// XDR definition, it will be parsed as a "new-style" TransactionEnvelope +// containing a TransactionV0. +struct TransactionV0 +{ + uint256 sourceAccountEd25519; + uint32 fee; + SequenceNumber seqNum; + TimeBounds* timeBounds; + Memo memo; + Operation operations; + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct TransactionV0Envelope +{ + TransactionV0 tx; + /* Each decorated signature is a signature over the SHA256 hash of + * a TransactionSignaturePayload */ + DecoratedSignature signatures<20>; +}; + +/* a transaction is a container for a set of operations + - is executed by an account + - fees are collected from the account + - operations are executed in order as one ACID transaction + either all operations are applied or none are + if any returns a failing code +*/ +struct Transaction +{ + // account used to run the transaction + MuxedAccount sourceAccount; + + // the fee the sourceAccount will pay + uint32 fee; + + // sequence number to consume in the account + SequenceNumber seqNum; + + // validity conditions + Preconditions cond; + + Memo memo; + + Operation operations; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct TransactionV1Envelope +{ + Transaction tx; + /* Each decorated signature is a signature over the SHA256 hash of + * a TransactionSignaturePayload */ + DecoratedSignature signatures<20>; +}; + +struct FeeBumpTransaction +{ + MuxedAccount feeSource; + int64 fee; + union switch (EnvelopeType type) + { + case ENVELOPE_TYPE_TX: + TransactionV1Envelope v1; + } + innerTx; + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct FeeBumpTransactionEnvelope +{ + FeeBumpTransaction tx; + /* Each decorated signature is a signature over the SHA256 hash of + * a TransactionSignaturePayload */ + DecoratedSignature signatures<20>; +}; + +/* A TransactionEnvelope wraps a transaction with signatures. */ +union TransactionEnvelope switch (EnvelopeType type) +{ +case ENVELOPE_TYPE_TX_V0: + TransactionV0Envelope v0; +case ENVELOPE_TYPE_TX: + TransactionV1Envelope v1; +case ENVELOPE_TYPE_TX_FEE_BUMP: + FeeBumpTransactionEnvelope feeBump; +}; + +struct TransactionSignaturePayload +{ + Hash networkId; + union switch (EnvelopeType type) + { + // Backwards Compatibility: Use ENVELOPE_TYPE_TX to sign ENVELOPE_TYPE_TX_V0 + case ENVELOPE_TYPE_TX: + Transaction tx; + case ENVELOPE_TYPE_TX_FEE_BUMP: + FeeBumpTransaction feeBump; + } + taggedTransaction; +}; + +/* Operation Results section */ + +enum ClaimAtomType +{ + CLAIM_ATOM_TYPE_V0 = 0, + CLAIM_ATOM_TYPE_ORDER_BOOK = 1, + CLAIM_ATOM_TYPE_LIQUIDITY_POOL = 2 +}; + +// ClaimOfferAtomV0 is a ClaimOfferAtom with the AccountID discriminant stripped +// off, leaving a raw ed25519 public key to identify the source account. This is +// used for backwards compatibility starting from the protocol 17/18 boundary. +// If an "old-style" ClaimOfferAtom is parsed with this XDR definition, it will +// be parsed as a "new-style" ClaimAtom containing a ClaimOfferAtomV0. +struct ClaimOfferAtomV0 +{ + // emitted to identify the offer + uint256 sellerEd25519; // Account that owns the offer + int64 offerID; + + // amount and asset taken from the owner + Asset assetSold; + int64 amountSold; + + // amount and asset sent to the owner + Asset assetBought; + int64 amountBought; +}; + +struct ClaimOfferAtom +{ + // emitted to identify the offer + AccountID sellerID; // Account that owns the offer + int64 offerID; + + // amount and asset taken from the owner + Asset assetSold; + int64 amountSold; + + // amount and asset sent to the owner + Asset assetBought; + int64 amountBought; +}; + +struct ClaimLiquidityAtom +{ + PoolID liquidityPoolID; + + // amount and asset taken from the pool + Asset assetSold; + int64 amountSold; + + // amount and asset sent to the pool + Asset assetBought; + int64 amountBought; +}; + +/* This result is used when offers are taken or liquidity is exchanged with a + liquidity pool during an operation +*/ +union ClaimAtom switch (ClaimAtomType type) +{ +case CLAIM_ATOM_TYPE_V0: + ClaimOfferAtomV0 v0; +case CLAIM_ATOM_TYPE_ORDER_BOOK: + ClaimOfferAtom orderBook; +case CLAIM_ATOM_TYPE_LIQUIDITY_POOL: + ClaimLiquidityAtom liquidityPool; +}; + +/******* CreateAccount Result ********/ + +enum CreateAccountResultCode +{ + // codes considered as "success" for the operation + CREATE_ACCOUNT_SUCCESS = 0, // account was created + + // codes considered as "failure" for the operation + CREATE_ACCOUNT_MALFORMED = -1, // invalid destination + CREATE_ACCOUNT_UNDERFUNDED = -2, // not enough funds in source account + CREATE_ACCOUNT_LOW_RESERVE = + -3, // would create an account below the min reserve + CREATE_ACCOUNT_ALREADY_EXIST = -4 // account already exists +}; + +union CreateAccountResult switch (CreateAccountResultCode code) +{ +case CREATE_ACCOUNT_SUCCESS: + void; +case CREATE_ACCOUNT_MALFORMED: +case CREATE_ACCOUNT_UNDERFUNDED: +case CREATE_ACCOUNT_LOW_RESERVE: +case CREATE_ACCOUNT_ALREADY_EXIST: + void; +}; + +/******* Payment Result ********/ + +enum PaymentResultCode +{ + // codes considered as "success" for the operation + PAYMENT_SUCCESS = 0, // payment successfully completed + + // codes considered as "failure" for the operation + PAYMENT_MALFORMED = -1, // bad input + PAYMENT_UNDERFUNDED = -2, // not enough funds in source account + PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account + PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer + PAYMENT_NO_DESTINATION = -5, // destination account does not exist + PAYMENT_NO_TRUST = -6, // destination missing a trust line for asset + PAYMENT_NOT_AUTHORIZED = -7, // destination not authorized to hold asset + PAYMENT_LINE_FULL = -8, // destination would go above their limit + PAYMENT_NO_ISSUER = -9 // missing issuer on asset +}; + +union PaymentResult switch (PaymentResultCode code) +{ +case PAYMENT_SUCCESS: + void; +case PAYMENT_MALFORMED: +case PAYMENT_UNDERFUNDED: +case PAYMENT_SRC_NO_TRUST: +case PAYMENT_SRC_NOT_AUTHORIZED: +case PAYMENT_NO_DESTINATION: +case PAYMENT_NO_TRUST: +case PAYMENT_NOT_AUTHORIZED: +case PAYMENT_LINE_FULL: +case PAYMENT_NO_ISSUER: + void; +}; + +/******* PathPaymentStrictReceive Result ********/ + +enum PathPaymentStrictReceiveResultCode +{ + // codes considered as "success" for the operation + PATH_PAYMENT_STRICT_RECEIVE_SUCCESS = 0, // success + + // codes considered as "failure" for the operation + PATH_PAYMENT_STRICT_RECEIVE_MALFORMED = -1, // bad input + PATH_PAYMENT_STRICT_RECEIVE_UNDERFUNDED = + -2, // not enough funds in source account + PATH_PAYMENT_STRICT_RECEIVE_SRC_NO_TRUST = + -3, // no trust line on source account + PATH_PAYMENT_STRICT_RECEIVE_SRC_NOT_AUTHORIZED = + -4, // source not authorized to transfer + PATH_PAYMENT_STRICT_RECEIVE_NO_DESTINATION = + -5, // destination account does not exist + PATH_PAYMENT_STRICT_RECEIVE_NO_TRUST = + -6, // dest missing a trust line for asset + PATH_PAYMENT_STRICT_RECEIVE_NOT_AUTHORIZED = + -7, // dest not authorized to hold asset + PATH_PAYMENT_STRICT_RECEIVE_LINE_FULL = + -8, // dest would go above their limit + PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER = -9, // missing issuer on one asset + PATH_PAYMENT_STRICT_RECEIVE_TOO_FEW_OFFERS = + -10, // not enough offers to satisfy path + PATH_PAYMENT_STRICT_RECEIVE_OFFER_CROSS_SELF = + -11, // would cross one of its own offers + PATH_PAYMENT_STRICT_RECEIVE_OVER_SENDMAX = -12 // could not satisfy sendmax +}; + +struct SimplePaymentResult +{ + AccountID destination; + Asset asset; + int64 amount; +}; + +union PathPaymentStrictReceiveResult switch ( + PathPaymentStrictReceiveResultCode code) +{ +case PATH_PAYMENT_STRICT_RECEIVE_SUCCESS: + struct + { + ClaimAtom offers<>; + SimplePaymentResult last; + } success; +case PATH_PAYMENT_STRICT_RECEIVE_MALFORMED: +case PATH_PAYMENT_STRICT_RECEIVE_UNDERFUNDED: +case PATH_PAYMENT_STRICT_RECEIVE_SRC_NO_TRUST: +case PATH_PAYMENT_STRICT_RECEIVE_SRC_NOT_AUTHORIZED: +case PATH_PAYMENT_STRICT_RECEIVE_NO_DESTINATION: +case PATH_PAYMENT_STRICT_RECEIVE_NO_TRUST: +case PATH_PAYMENT_STRICT_RECEIVE_NOT_AUTHORIZED: +case PATH_PAYMENT_STRICT_RECEIVE_LINE_FULL: + void; +case PATH_PAYMENT_STRICT_RECEIVE_NO_ISSUER: + Asset noIssuer; // the asset that caused the error +case PATH_PAYMENT_STRICT_RECEIVE_TOO_FEW_OFFERS: +case PATH_PAYMENT_STRICT_RECEIVE_OFFER_CROSS_SELF: +case PATH_PAYMENT_STRICT_RECEIVE_OVER_SENDMAX: + void; +}; + +/******* PathPaymentStrictSend Result ********/ + +enum PathPaymentStrictSendResultCode +{ + // codes considered as "success" for the operation + PATH_PAYMENT_STRICT_SEND_SUCCESS = 0, // success + + // codes considered as "failure" for the operation + PATH_PAYMENT_STRICT_SEND_MALFORMED = -1, // bad input + PATH_PAYMENT_STRICT_SEND_UNDERFUNDED = + -2, // not enough funds in source account + PATH_PAYMENT_STRICT_SEND_SRC_NO_TRUST = + -3, // no trust line on source account + PATH_PAYMENT_STRICT_SEND_SRC_NOT_AUTHORIZED = + -4, // source not authorized to transfer + PATH_PAYMENT_STRICT_SEND_NO_DESTINATION = + -5, // destination account does not exist + PATH_PAYMENT_STRICT_SEND_NO_TRUST = + -6, // dest missing a trust line for asset + PATH_PAYMENT_STRICT_SEND_NOT_AUTHORIZED = + -7, // dest not authorized to hold asset + PATH_PAYMENT_STRICT_SEND_LINE_FULL = -8, // dest would go above their limit + PATH_PAYMENT_STRICT_SEND_NO_ISSUER = -9, // missing issuer on one asset + PATH_PAYMENT_STRICT_SEND_TOO_FEW_OFFERS = + -10, // not enough offers to satisfy path + PATH_PAYMENT_STRICT_SEND_OFFER_CROSS_SELF = + -11, // would cross one of its own offers + PATH_PAYMENT_STRICT_SEND_UNDER_DESTMIN = -12 // could not satisfy destMin +}; + +union PathPaymentStrictSendResult switch (PathPaymentStrictSendResultCode code) +{ +case PATH_PAYMENT_STRICT_SEND_SUCCESS: + struct + { + ClaimAtom offers<>; + SimplePaymentResult last; + } success; +case PATH_PAYMENT_STRICT_SEND_MALFORMED: +case PATH_PAYMENT_STRICT_SEND_UNDERFUNDED: +case PATH_PAYMENT_STRICT_SEND_SRC_NO_TRUST: +case PATH_PAYMENT_STRICT_SEND_SRC_NOT_AUTHORIZED: +case PATH_PAYMENT_STRICT_SEND_NO_DESTINATION: +case PATH_PAYMENT_STRICT_SEND_NO_TRUST: +case PATH_PAYMENT_STRICT_SEND_NOT_AUTHORIZED: +case PATH_PAYMENT_STRICT_SEND_LINE_FULL: + void; +case PATH_PAYMENT_STRICT_SEND_NO_ISSUER: + Asset noIssuer; // the asset that caused the error +case PATH_PAYMENT_STRICT_SEND_TOO_FEW_OFFERS: +case PATH_PAYMENT_STRICT_SEND_OFFER_CROSS_SELF: +case PATH_PAYMENT_STRICT_SEND_UNDER_DESTMIN: + void; +}; + +/******* ManageSellOffer Result ********/ + +enum ManageSellOfferResultCode +{ + // codes considered as "success" for the operation + MANAGE_SELL_OFFER_SUCCESS = 0, + + // codes considered as "failure" for the operation + MANAGE_SELL_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_SELL_OFFER_SELL_NO_TRUST = + -2, // no trust line for what we're selling + MANAGE_SELL_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_SELL_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_SELL_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_SELL_OFFER_CROSS_SELF = + -8, // would cross an offer from the same user + MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_SELL_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying + + // update errors + MANAGE_SELL_OFFER_NOT_FOUND = + -11, // offerID does not match an existing offer + + MANAGE_SELL_OFFER_LOW_RESERVE = + -12 // not enough funds to create a new Offer +}; + +enum ManageOfferEffect +{ + MANAGE_OFFER_CREATED = 0, + MANAGE_OFFER_UPDATED = 1, + MANAGE_OFFER_DELETED = 2 +}; + +struct ManageOfferSuccessResult +{ + // offers that got claimed while creating this offer + ClaimAtom offersClaimed<>; + + union switch (ManageOfferEffect effect) + { + case MANAGE_OFFER_CREATED: + case MANAGE_OFFER_UPDATED: + OfferEntry offer; + case MANAGE_OFFER_DELETED: + void; + } + offer; +}; + +union ManageSellOfferResult switch (ManageSellOfferResultCode code) +{ +case MANAGE_SELL_OFFER_SUCCESS: + ManageOfferSuccessResult success; +case MANAGE_SELL_OFFER_MALFORMED: +case MANAGE_SELL_OFFER_SELL_NO_TRUST: +case MANAGE_SELL_OFFER_BUY_NO_TRUST: +case MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED: +case MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED: +case MANAGE_SELL_OFFER_LINE_FULL: +case MANAGE_SELL_OFFER_UNDERFUNDED: +case MANAGE_SELL_OFFER_CROSS_SELF: +case MANAGE_SELL_OFFER_SELL_NO_ISSUER: +case MANAGE_SELL_OFFER_BUY_NO_ISSUER: +case MANAGE_SELL_OFFER_NOT_FOUND: +case MANAGE_SELL_OFFER_LOW_RESERVE: + void; +}; + +/******* ManageBuyOffer Result ********/ + +enum ManageBuyOfferResultCode +{ + // codes considered as "success" for the operation + MANAGE_BUY_OFFER_SUCCESS = 0, + + // codes considered as "failure" for the operation + MANAGE_BUY_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling + MANAGE_BUY_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_BUY_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user + MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying + + // update errors + MANAGE_BUY_OFFER_NOT_FOUND = + -11, // offerID does not match an existing offer + + MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +}; + +union ManageBuyOfferResult switch (ManageBuyOfferResultCode code) +{ +case MANAGE_BUY_OFFER_SUCCESS: + ManageOfferSuccessResult success; +case MANAGE_BUY_OFFER_MALFORMED: +case MANAGE_BUY_OFFER_SELL_NO_TRUST: +case MANAGE_BUY_OFFER_BUY_NO_TRUST: +case MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED: +case MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED: +case MANAGE_BUY_OFFER_LINE_FULL: +case MANAGE_BUY_OFFER_UNDERFUNDED: +case MANAGE_BUY_OFFER_CROSS_SELF: +case MANAGE_BUY_OFFER_SELL_NO_ISSUER: +case MANAGE_BUY_OFFER_BUY_NO_ISSUER: +case MANAGE_BUY_OFFER_NOT_FOUND: +case MANAGE_BUY_OFFER_LOW_RESERVE: + void; +}; + +/******* SetOptions Result ********/ + +enum SetOptionsResultCode +{ + // codes considered as "success" for the operation + SET_OPTIONS_SUCCESS = 0, + // codes considered as "failure" for the operation + SET_OPTIONS_LOW_RESERVE = -1, // not enough funds to add a signer + SET_OPTIONS_TOO_MANY_SIGNERS = -2, // max number of signers already reached + SET_OPTIONS_BAD_FLAGS = -3, // invalid combination of clear/set flags + SET_OPTIONS_INVALID_INFLATION = -4, // inflation account does not exist + SET_OPTIONS_CANT_CHANGE = -5, // can no longer change this option + SET_OPTIONS_UNKNOWN_FLAG = -6, // can't set an unknown flag + SET_OPTIONS_THRESHOLD_OUT_OF_RANGE = -7, // bad value for weight/threshold + SET_OPTIONS_BAD_SIGNER = -8, // signer cannot be masterkey + SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain + SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = + -10 // auth revocable is required for clawback +}; + +union SetOptionsResult switch (SetOptionsResultCode code) +{ +case SET_OPTIONS_SUCCESS: + void; +case SET_OPTIONS_LOW_RESERVE: +case SET_OPTIONS_TOO_MANY_SIGNERS: +case SET_OPTIONS_BAD_FLAGS: +case SET_OPTIONS_INVALID_INFLATION: +case SET_OPTIONS_CANT_CHANGE: +case SET_OPTIONS_UNKNOWN_FLAG: +case SET_OPTIONS_THRESHOLD_OUT_OF_RANGE: +case SET_OPTIONS_BAD_SIGNER: +case SET_OPTIONS_INVALID_HOME_DOMAIN: +case SET_OPTIONS_AUTH_REVOCABLE_REQUIRED: + void; +}; + +/******* ChangeTrust Result ********/ + +enum ChangeTrustResultCode +{ + // codes considered as "success" for the operation + CHANGE_TRUST_SUCCESS = 0, + // codes considered as "failure" for the operation + CHANGE_TRUST_MALFORMED = -1, // bad input + CHANGE_TRUST_NO_ISSUER = -2, // could not find issuer + CHANGE_TRUST_INVALID_LIMIT = -3, // cannot drop limit below balance + // cannot create with a limit of 0 + CHANGE_TRUST_LOW_RESERVE = + -4, // not enough funds to create a new trust line, + CHANGE_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed + CHANGE_TRUST_TRUST_LINE_MISSING = -6, // Asset trustline is missing for pool + CHANGE_TRUST_CANNOT_DELETE = + -7, // Asset trustline is still referenced in a pool + CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES = + -8 // Asset trustline is deauthorized +}; + +union ChangeTrustResult switch (ChangeTrustResultCode code) +{ +case CHANGE_TRUST_SUCCESS: + void; +case CHANGE_TRUST_MALFORMED: +case CHANGE_TRUST_NO_ISSUER: +case CHANGE_TRUST_INVALID_LIMIT: +case CHANGE_TRUST_LOW_RESERVE: +case CHANGE_TRUST_SELF_NOT_ALLOWED: +case CHANGE_TRUST_TRUST_LINE_MISSING: +case CHANGE_TRUST_CANNOT_DELETE: +case CHANGE_TRUST_NOT_AUTH_MAINTAIN_LIABILITIES: + void; +}; + +/******* AllowTrust Result ********/ + +enum AllowTrustResultCode +{ + // codes considered as "success" for the operation + ALLOW_TRUST_SUCCESS = 0, + // codes considered as "failure" for the operation + ALLOW_TRUST_MALFORMED = -1, // asset is not ASSET_TYPE_ALPHANUM + ALLOW_TRUST_NO_TRUST_LINE = -2, // trustor does not have a trustline + // source account does not require trust + ALLOW_TRUST_TRUST_NOT_REQUIRED = -3, + ALLOW_TRUST_CANT_REVOKE = -4, // source account can't revoke trust, + ALLOW_TRUST_SELF_NOT_ALLOWED = -5, // trusting self is not allowed + ALLOW_TRUST_LOW_RESERVE = -6 // claimable balances can't be created + // on revoke due to low reserves +}; + +union AllowTrustResult switch (AllowTrustResultCode code) +{ +case ALLOW_TRUST_SUCCESS: + void; +case ALLOW_TRUST_MALFORMED: +case ALLOW_TRUST_NO_TRUST_LINE: +case ALLOW_TRUST_TRUST_NOT_REQUIRED: +case ALLOW_TRUST_CANT_REVOKE: +case ALLOW_TRUST_SELF_NOT_ALLOWED: +case ALLOW_TRUST_LOW_RESERVE: + void; +}; + +/******* AccountMerge Result ********/ + +enum AccountMergeResultCode +{ + // codes considered as "success" for the operation + ACCOUNT_MERGE_SUCCESS = 0, + // codes considered as "failure" for the operation + ACCOUNT_MERGE_MALFORMED = -1, // can't merge onto itself + ACCOUNT_MERGE_NO_ACCOUNT = -2, // destination does not exist + ACCOUNT_MERGE_IMMUTABLE_SET = -3, // source account has AUTH_IMMUTABLE set + ACCOUNT_MERGE_HAS_SUB_ENTRIES = -4, // account has trust lines/offers + ACCOUNT_MERGE_SEQNUM_TOO_FAR = -5, // sequence number is over max allowed + ACCOUNT_MERGE_DEST_FULL = -6, // can't add source balance to + // destination balance + ACCOUNT_MERGE_IS_SPONSOR = -7 // can't merge account that is a sponsor +}; + +union AccountMergeResult switch (AccountMergeResultCode code) +{ +case ACCOUNT_MERGE_SUCCESS: + int64 sourceAccountBalance; // how much got transferred from source account +case ACCOUNT_MERGE_MALFORMED: +case ACCOUNT_MERGE_NO_ACCOUNT: +case ACCOUNT_MERGE_IMMUTABLE_SET: +case ACCOUNT_MERGE_HAS_SUB_ENTRIES: +case ACCOUNT_MERGE_SEQNUM_TOO_FAR: +case ACCOUNT_MERGE_DEST_FULL: +case ACCOUNT_MERGE_IS_SPONSOR: + void; +}; + +/******* Inflation Result ********/ + +enum InflationResultCode +{ + // codes considered as "success" for the operation + INFLATION_SUCCESS = 0, + // codes considered as "failure" for the operation + INFLATION_NOT_TIME = -1 +}; + +struct InflationPayout // or use PaymentResultAtom to limit types? +{ + AccountID destination; + int64 amount; +}; + +union InflationResult switch (InflationResultCode code) +{ +case INFLATION_SUCCESS: + InflationPayout payouts<>; +case INFLATION_NOT_TIME: + void; +}; + +/******* ManageData Result ********/ + +enum ManageDataResultCode +{ + // codes considered as "success" for the operation + MANAGE_DATA_SUCCESS = 0, + // codes considered as "failure" for the operation + MANAGE_DATA_NOT_SUPPORTED_YET = + -1, // The network hasn't moved to this protocol change yet + MANAGE_DATA_NAME_NOT_FOUND = + -2, // Trying to remove a Data Entry that isn't there + MANAGE_DATA_LOW_RESERVE = -3, // not enough funds to create a new Data Entry + MANAGE_DATA_INVALID_NAME = -4 // Name not a valid string +}; + +union ManageDataResult switch (ManageDataResultCode code) +{ +case MANAGE_DATA_SUCCESS: + void; +case MANAGE_DATA_NOT_SUPPORTED_YET: +case MANAGE_DATA_NAME_NOT_FOUND: +case MANAGE_DATA_LOW_RESERVE: +case MANAGE_DATA_INVALID_NAME: + void; +}; + +/******* BumpSequence Result ********/ + +enum BumpSequenceResultCode +{ + // codes considered as "success" for the operation + BUMP_SEQUENCE_SUCCESS = 0, + // codes considered as "failure" for the operation + BUMP_SEQUENCE_BAD_SEQ = -1 // `bumpTo` is not within bounds +}; + +union BumpSequenceResult switch (BumpSequenceResultCode code) +{ +case BUMP_SEQUENCE_SUCCESS: + void; +case BUMP_SEQUENCE_BAD_SEQ: + void; +}; + +/******* CreateClaimableBalance Result ********/ + +enum CreateClaimableBalanceResultCode +{ + CREATE_CLAIMABLE_BALANCE_SUCCESS = 0, + CREATE_CLAIMABLE_BALANCE_MALFORMED = -1, + CREATE_CLAIMABLE_BALANCE_LOW_RESERVE = -2, + CREATE_CLAIMABLE_BALANCE_NO_TRUST = -3, + CREATE_CLAIMABLE_BALANCE_NOT_AUTHORIZED = -4, + CREATE_CLAIMABLE_BALANCE_UNDERFUNDED = -5 +}; + +union CreateClaimableBalanceResult switch ( + CreateClaimableBalanceResultCode code) +{ +case CREATE_CLAIMABLE_BALANCE_SUCCESS: + ClaimableBalanceID balanceID; +case CREATE_CLAIMABLE_BALANCE_MALFORMED: +case CREATE_CLAIMABLE_BALANCE_LOW_RESERVE: +case CREATE_CLAIMABLE_BALANCE_NO_TRUST: +case CREATE_CLAIMABLE_BALANCE_NOT_AUTHORIZED: +case CREATE_CLAIMABLE_BALANCE_UNDERFUNDED: + void; +}; + +/******* ClaimClaimableBalance Result ********/ + +enum ClaimClaimableBalanceResultCode +{ + CLAIM_CLAIMABLE_BALANCE_SUCCESS = 0, + CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST = -1, + CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM = -2, + CLAIM_CLAIMABLE_BALANCE_LINE_FULL = -3, + CLAIM_CLAIMABLE_BALANCE_NO_TRUST = -4, + CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED = -5 +}; + +union ClaimClaimableBalanceResult switch (ClaimClaimableBalanceResultCode code) +{ +case CLAIM_CLAIMABLE_BALANCE_SUCCESS: + void; +case CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST: +case CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM: +case CLAIM_CLAIMABLE_BALANCE_LINE_FULL: +case CLAIM_CLAIMABLE_BALANCE_NO_TRUST: +case CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED: + void; +}; + +/******* BeginSponsoringFutureReserves Result ********/ + +enum BeginSponsoringFutureReservesResultCode +{ + // codes considered as "success" for the operation + BEGIN_SPONSORING_FUTURE_RESERVES_SUCCESS = 0, + + // codes considered as "failure" for the operation + BEGIN_SPONSORING_FUTURE_RESERVES_MALFORMED = -1, + BEGIN_SPONSORING_FUTURE_RESERVES_ALREADY_SPONSORED = -2, + BEGIN_SPONSORING_FUTURE_RESERVES_RECURSIVE = -3 +}; + +union BeginSponsoringFutureReservesResult switch ( + BeginSponsoringFutureReservesResultCode code) +{ +case BEGIN_SPONSORING_FUTURE_RESERVES_SUCCESS: + void; +case BEGIN_SPONSORING_FUTURE_RESERVES_MALFORMED: +case BEGIN_SPONSORING_FUTURE_RESERVES_ALREADY_SPONSORED: +case BEGIN_SPONSORING_FUTURE_RESERVES_RECURSIVE: + void; +}; + +/******* EndSponsoringFutureReserves Result ********/ + +enum EndSponsoringFutureReservesResultCode +{ + // codes considered as "success" for the operation + END_SPONSORING_FUTURE_RESERVES_SUCCESS = 0, + + // codes considered as "failure" for the operation + END_SPONSORING_FUTURE_RESERVES_NOT_SPONSORED = -1 +}; + +union EndSponsoringFutureReservesResult switch ( + EndSponsoringFutureReservesResultCode code) +{ +case END_SPONSORING_FUTURE_RESERVES_SUCCESS: + void; +case END_SPONSORING_FUTURE_RESERVES_NOT_SPONSORED: + void; +}; + +/******* RevokeSponsorship Result ********/ + +enum RevokeSponsorshipResultCode +{ + // codes considered as "success" for the operation + REVOKE_SPONSORSHIP_SUCCESS = 0, + + // codes considered as "failure" for the operation + REVOKE_SPONSORSHIP_DOES_NOT_EXIST = -1, + REVOKE_SPONSORSHIP_NOT_SPONSOR = -2, + REVOKE_SPONSORSHIP_LOW_RESERVE = -3, + REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE = -4, + REVOKE_SPONSORSHIP_MALFORMED = -5 +}; + +union RevokeSponsorshipResult switch (RevokeSponsorshipResultCode code) +{ +case REVOKE_SPONSORSHIP_SUCCESS: + void; +case REVOKE_SPONSORSHIP_DOES_NOT_EXIST: +case REVOKE_SPONSORSHIP_NOT_SPONSOR: +case REVOKE_SPONSORSHIP_LOW_RESERVE: +case REVOKE_SPONSORSHIP_ONLY_TRANSFERABLE: +case REVOKE_SPONSORSHIP_MALFORMED: + void; +}; + +/******* Clawback Result ********/ + +enum ClawbackResultCode +{ + // codes considered as "success" for the operation + CLAWBACK_SUCCESS = 0, + + // codes considered as "failure" for the operation + CLAWBACK_MALFORMED = -1, + CLAWBACK_NOT_CLAWBACK_ENABLED = -2, + CLAWBACK_NO_TRUST = -3, + CLAWBACK_UNDERFUNDED = -4 +}; + +union ClawbackResult switch (ClawbackResultCode code) +{ +case CLAWBACK_SUCCESS: + void; +case CLAWBACK_MALFORMED: +case CLAWBACK_NOT_CLAWBACK_ENABLED: +case CLAWBACK_NO_TRUST: +case CLAWBACK_UNDERFUNDED: + void; +}; + +/******* ClawbackClaimableBalance Result ********/ + +enum ClawbackClaimableBalanceResultCode +{ + // codes considered as "success" for the operation + CLAWBACK_CLAIMABLE_BALANCE_SUCCESS = 0, + + // codes considered as "failure" for the operation + CLAWBACK_CLAIMABLE_BALANCE_DOES_NOT_EXIST = -1, + CLAWBACK_CLAIMABLE_BALANCE_NOT_ISSUER = -2, + CLAWBACK_CLAIMABLE_BALANCE_NOT_CLAWBACK_ENABLED = -3 +}; + +union ClawbackClaimableBalanceResult switch ( + ClawbackClaimableBalanceResultCode code) +{ +case CLAWBACK_CLAIMABLE_BALANCE_SUCCESS: + void; +case CLAWBACK_CLAIMABLE_BALANCE_DOES_NOT_EXIST: +case CLAWBACK_CLAIMABLE_BALANCE_NOT_ISSUER: +case CLAWBACK_CLAIMABLE_BALANCE_NOT_CLAWBACK_ENABLED: + void; +}; + +/******* SetTrustLineFlags Result ********/ + +enum SetTrustLineFlagsResultCode +{ + // codes considered as "success" for the operation + SET_TRUST_LINE_FLAGS_SUCCESS = 0, + + // codes considered as "failure" for the operation + SET_TRUST_LINE_FLAGS_MALFORMED = -1, + SET_TRUST_LINE_FLAGS_NO_TRUST_LINE = -2, + SET_TRUST_LINE_FLAGS_CANT_REVOKE = -3, + SET_TRUST_LINE_FLAGS_INVALID_STATE = -4, + SET_TRUST_LINE_FLAGS_LOW_RESERVE = -5 // claimable balances can't be created + // on revoke due to low reserves +}; + +union SetTrustLineFlagsResult switch (SetTrustLineFlagsResultCode code) +{ +case SET_TRUST_LINE_FLAGS_SUCCESS: + void; +case SET_TRUST_LINE_FLAGS_MALFORMED: +case SET_TRUST_LINE_FLAGS_NO_TRUST_LINE: +case SET_TRUST_LINE_FLAGS_CANT_REVOKE: +case SET_TRUST_LINE_FLAGS_INVALID_STATE: +case SET_TRUST_LINE_FLAGS_LOW_RESERVE: + void; +}; + +/******* LiquidityPoolDeposit Result ********/ + +enum LiquidityPoolDepositResultCode +{ + // codes considered as "success" for the operation + LIQUIDITY_POOL_DEPOSIT_SUCCESS = 0, + + // codes considered as "failure" for the operation + LIQUIDITY_POOL_DEPOSIT_MALFORMED = -1, // bad input + LIQUIDITY_POOL_DEPOSIT_NO_TRUST = -2, // no trust line for one of the + // assets + LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED = -3, // not authorized for one of the + // assets + LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED = -4, // not enough balance for one of + // the assets + LIQUIDITY_POOL_DEPOSIT_LINE_FULL = -5, // pool share trust line doesn't + // have sufficient limit + LIQUIDITY_POOL_DEPOSIT_BAD_PRICE = -6, // deposit price outside bounds + LIQUIDITY_POOL_DEPOSIT_POOL_FULL = -7 // pool reserves are full +}; + +union LiquidityPoolDepositResult switch (LiquidityPoolDepositResultCode code) +{ +case LIQUIDITY_POOL_DEPOSIT_SUCCESS: + void; +case LIQUIDITY_POOL_DEPOSIT_MALFORMED: +case LIQUIDITY_POOL_DEPOSIT_NO_TRUST: +case LIQUIDITY_POOL_DEPOSIT_NOT_AUTHORIZED: +case LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED: +case LIQUIDITY_POOL_DEPOSIT_LINE_FULL: +case LIQUIDITY_POOL_DEPOSIT_BAD_PRICE: +case LIQUIDITY_POOL_DEPOSIT_POOL_FULL: + void; +}; + +/******* LiquidityPoolWithdraw Result ********/ + +enum LiquidityPoolWithdrawResultCode +{ + // codes considered as "success" for the operation + LIQUIDITY_POOL_WITHDRAW_SUCCESS = 0, + + // codes considered as "failure" for the operation + LIQUIDITY_POOL_WITHDRAW_MALFORMED = -1, // bad input + LIQUIDITY_POOL_WITHDRAW_NO_TRUST = -2, // no trust line for one of the + // assets + LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED = -3, // not enough balance of the + // pool share + LIQUIDITY_POOL_WITHDRAW_LINE_FULL = -4, // would go above limit for one + // of the assets + LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM = -5 // didn't withdraw enough +}; + +union LiquidityPoolWithdrawResult switch (LiquidityPoolWithdrawResultCode code) +{ +case LIQUIDITY_POOL_WITHDRAW_SUCCESS: + void; +case LIQUIDITY_POOL_WITHDRAW_MALFORMED: +case LIQUIDITY_POOL_WITHDRAW_NO_TRUST: +case LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED: +case LIQUIDITY_POOL_WITHDRAW_LINE_FULL: +case LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM: + void; +}; + +enum InvokeHostFunctionResultCode +{ + // codes considered as "success" for the operation + INVOKE_HOST_FUNCTION_SUCCESS = 0, + + // codes considered as "failure" for the operation + INVOKE_HOST_FUNCTION_MALFORMED = -1, + INVOKE_HOST_FUNCTION_TRAPPED = -2 +}; + +union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) +{ +case INVOKE_HOST_FUNCTION_SUCCESS: + void; +case INVOKE_HOST_FUNCTION_MALFORMED: +case INVOKE_HOST_FUNCTION_TRAPPED: + void; +}; + +/* High level Operation Result */ +enum OperationResultCode +{ + opINNER = 0, // inner object result is valid + + opBAD_AUTH = -1, // too few valid signatures / wrong network + opNO_ACCOUNT = -2, // source account was not found + opNOT_SUPPORTED = -3, // operation not supported at this time + opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached + opEXCEEDED_WORK_LIMIT = -5, // operation did too much work + opTOO_MANY_SPONSORING = -6 // account is sponsoring too many entries +}; + +union OperationResult switch (OperationResultCode code) +{ +case opINNER: + union switch (OperationType type) + { + case CREATE_ACCOUNT: + CreateAccountResult createAccountResult; + case PAYMENT: + PaymentResult paymentResult; + case PATH_PAYMENT_STRICT_RECEIVE: + PathPaymentStrictReceiveResult pathPaymentStrictReceiveResult; + case MANAGE_SELL_OFFER: + ManageSellOfferResult manageSellOfferResult; + case CREATE_PASSIVE_SELL_OFFER: + ManageSellOfferResult createPassiveSellOfferResult; + case SET_OPTIONS: + SetOptionsResult setOptionsResult; + case CHANGE_TRUST: + ChangeTrustResult changeTrustResult; + case ALLOW_TRUST: + AllowTrustResult allowTrustResult; + case ACCOUNT_MERGE: + AccountMergeResult accountMergeResult; + case INFLATION: + InflationResult inflationResult; + case MANAGE_DATA: + ManageDataResult manageDataResult; + case BUMP_SEQUENCE: + BumpSequenceResult bumpSeqResult; + case MANAGE_BUY_OFFER: + ManageBuyOfferResult manageBuyOfferResult; + case PATH_PAYMENT_STRICT_SEND: + PathPaymentStrictSendResult pathPaymentStrictSendResult; + case CREATE_CLAIMABLE_BALANCE: + CreateClaimableBalanceResult createClaimableBalanceResult; + case CLAIM_CLAIMABLE_BALANCE: + ClaimClaimableBalanceResult claimClaimableBalanceResult; + case BEGIN_SPONSORING_FUTURE_RESERVES: + BeginSponsoringFutureReservesResult beginSponsoringFutureReservesResult; + case END_SPONSORING_FUTURE_RESERVES: + EndSponsoringFutureReservesResult endSponsoringFutureReservesResult; + case REVOKE_SPONSORSHIP: + RevokeSponsorshipResult revokeSponsorshipResult; + case CLAWBACK: + ClawbackResult clawbackResult; + case CLAWBACK_CLAIMABLE_BALANCE: + ClawbackClaimableBalanceResult clawbackClaimableBalanceResult; + case SET_TRUST_LINE_FLAGS: + SetTrustLineFlagsResult setTrustLineFlagsResult; + case LIQUIDITY_POOL_DEPOSIT: + LiquidityPoolDepositResult liquidityPoolDepositResult; + case LIQUIDITY_POOL_WITHDRAW: + LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; + case INVOKE_HOST_FUNCTION: + InvokeHostFunctionResult invokeHostFunctionResult; + } + tr; +case opBAD_AUTH: +case opNO_ACCOUNT: +case opNOT_SUPPORTED: +case opTOO_MANY_SUBENTRIES: +case opEXCEEDED_WORK_LIMIT: +case opTOO_MANY_SPONSORING: + void; +}; + +enum TransactionResultCode +{ + txFEE_BUMP_INNER_SUCCESS = 1, // fee bump inner transaction succeeded + txSUCCESS = 0, // all operations succeeded + + txFAILED = -1, // one of the operations failed (none were applied) + + txTOO_EARLY = -2, // ledger closeTime before minTime + txTOO_LATE = -3, // ledger closeTime after maxTime + txMISSING_OPERATION = -4, // no operation was specified + txBAD_SEQ = -5, // sequence number does not match source account + + txBAD_AUTH = -6, // too few valid signatures / wrong network + txINSUFFICIENT_BALANCE = -7, // fee would bring account below reserve + txNO_ACCOUNT = -8, // source account not found + txINSUFFICIENT_FEE = -9, // fee is too small + txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction + txINTERNAL_ERROR = -11, // an unknown error occurred + + txNOT_SUPPORTED = -12, // transaction type not supported + txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed + txBAD_SPONSORSHIP = -14, // sponsorship not confirmed + txBAD_MIN_SEQ_AGE_OR_GAP = + -15, // minSeqAge or minSeqLedgerGap conditions not met + txMALFORMED = -16 // precondition is invalid +}; + +// InnerTransactionResult must be binary compatible with TransactionResult +// because it is be used to represent the result of a Transaction. +struct InnerTransactionResult +{ + // Always 0. Here for binary compatibility. + int64 feeCharged; + + union switch (TransactionResultCode code) + { + // txFEE_BUMP_INNER_SUCCESS is not included + case txSUCCESS: + case txFAILED: + OperationResult results<>; + case txTOO_EARLY: + case txTOO_LATE: + case txMISSING_OPERATION: + case txBAD_SEQ: + case txBAD_AUTH: + case txINSUFFICIENT_BALANCE: + case txNO_ACCOUNT: + case txINSUFFICIENT_FEE: + case txBAD_AUTH_EXTRA: + case txINTERNAL_ERROR: + case txNOT_SUPPORTED: + // txFEE_BUMP_INNER_FAILED is not included + case txBAD_SPONSORSHIP: + case txBAD_MIN_SEQ_AGE_OR_GAP: + case txMALFORMED: + void; + } + result; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +struct InnerTransactionResultPair +{ + Hash transactionHash; // hash of the inner transaction + InnerTransactionResult result; // result for the inner transaction +}; + +struct TransactionResult +{ + int64 feeCharged; // actual fee charged for the transaction + + union switch (TransactionResultCode code) + { + case txFEE_BUMP_INNER_SUCCESS: + case txFEE_BUMP_INNER_FAILED: + InnerTransactionResultPair innerResultPair; + case txSUCCESS: + case txFAILED: + OperationResult results<>; + case txTOO_EARLY: + case txTOO_LATE: + case txMISSING_OPERATION: + case txBAD_SEQ: + case txBAD_AUTH: + case txINSUFFICIENT_BALANCE: + case txNO_ACCOUNT: + case txINSUFFICIENT_FEE: + case txBAD_AUTH_EXTRA: + case txINTERNAL_ERROR: + case txNOT_SUPPORTED: + // case txFEE_BUMP_INNER_FAILED: handled above + case txBAD_SPONSORSHIP: + case txBAD_MIN_SEQ_AGE_OR_GAP: + case txMALFORMED: + void; + } + result; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; +} diff --git a/Stellar-types.x b/Stellar-types.x new file mode 100644 index 0000000..c3a1ebe --- /dev/null +++ b/Stellar-types.x @@ -0,0 +1,102 @@ +// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +namespace stellar +{ + +typedef opaque Hash[32]; +typedef opaque uint256[32]; + +typedef unsigned int uint32; +typedef int int32; + +typedef unsigned hyper uint64; +typedef hyper int64; + +// An ExtensionPoint is always marshaled as a 32-bit 0 value. At a +// later point, it can be replaced by a different union so as to +// extend a structure. +union ExtensionPoint switch (int v) +{ +case 0: + void; +}; + +enum CryptoKeyType +{ + KEY_TYPE_ED25519 = 0, + KEY_TYPE_PRE_AUTH_TX = 1, + KEY_TYPE_HASH_X = 2, + KEY_TYPE_ED25519_SIGNED_PAYLOAD = 3, + // MUXED enum values for supported type are derived from the enum values + // above by ORing them with 0x100 + KEY_TYPE_MUXED_ED25519 = 0x100 +}; + +enum PublicKeyType +{ + PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 +}; + +enum SignerKeyType +{ + SIGNER_KEY_TYPE_ED25519 = KEY_TYPE_ED25519, + SIGNER_KEY_TYPE_PRE_AUTH_TX = KEY_TYPE_PRE_AUTH_TX, + SIGNER_KEY_TYPE_HASH_X = KEY_TYPE_HASH_X, + SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD = KEY_TYPE_ED25519_SIGNED_PAYLOAD +}; + +union PublicKey switch (PublicKeyType type) +{ +case PUBLIC_KEY_TYPE_ED25519: + uint256 ed25519; +}; + +union SignerKey switch (SignerKeyType type) +{ +case SIGNER_KEY_TYPE_ED25519: + uint256 ed25519; +case SIGNER_KEY_TYPE_PRE_AUTH_TX: + /* SHA-256 Hash of TransactionSignaturePayload structure */ + uint256 preAuthTx; +case SIGNER_KEY_TYPE_HASH_X: + /* Hash of random 256 bit preimage X */ + uint256 hashX; +case SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD: + struct + { + /* Public key that must sign the payload. */ + uint256 ed25519; + /* Payload to be raw signed by ed25519. */ + opaque payload<64>; + } ed25519SignedPayload; +}; + +// variable size as the size depends on the signature scheme used +typedef opaque Signature<64>; + +typedef opaque SignatureHint[4]; + +typedef PublicKey NodeID; + +struct Curve25519Secret +{ + opaque key[32]; +}; + +struct Curve25519Public +{ + opaque key[32]; +}; + +struct HmacSha256Key +{ + opaque key[32]; +}; + +struct HmacSha256Mac +{ + opaque mac[32]; +}; +} From c58b3d87228d5d74d49d2305c311b2422472599b Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 29 Jun 2022 20:40:51 -0700 Subject: [PATCH 004/112] Incorporate CAP-42 changes (#3) --- Stellar-ledger.x | 60 ++++++++++++++++++++++++++++++++++++++++++++++- Stellar-overlay.x | 4 ++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 49d1c3c..848b7d6 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -187,6 +187,29 @@ case METAENTRY: BucketMetadata metaEntry; }; +enum TxSetComponentType +{ + // txs with effective fee <= bid derived from a base fee (if any). + // If base fee is not specified, no discount is applied. + TXSET_COMP_TXS_MAYBE_DISCOUNTED_FEE = 0 +}; + +union TxSetComponent switch (TxSetComponentType type) +{ +case TXSET_COMP_TXS_MAYBE_DISCOUNTED_FEE: + struct + { + int64* baseFee; + TransactionEnvelope txs<>; + } txsMaybeDiscountedFee; +}; + +union TransactionPhase switch (int v) +{ +case 0: + TxSetComponent v0Components<>; +}; + // Transaction sets are the unit used by SCP to decide on transitions // between ledgers struct TransactionSet @@ -195,6 +218,19 @@ struct TransactionSet TransactionEnvelope txs<>; }; +struct TransactionSetV1 +{ + Hash previousLedgerHash; + TransactionPhase phases<>; +}; + +union GeneralizedTransactionSet switch (int v) +{ +// We consider the legacy TransactionSet to be v0. +case 1: + TransactionSetV1 v1TxSet; +}; + struct TransactionResultPair { Hash transactionHash; @@ -214,11 +250,13 @@ struct TransactionHistoryEntry uint32 ledgerSeq; TransactionSet txSet; - // reserved for future use + // when v != 0, txSet must be empty union switch (int v) { case 0: void; + case 1: + GeneralizedTransactionSet generalizedTxSet; } ext; }; @@ -369,9 +407,29 @@ struct LedgerCloseMetaV0 SCPHistoryEntry scpInfo<>; }; +struct LedgerCloseMetaV1 +{ + LedgerHeaderHistoryEntry ledgerHeader; + + GeneralizedTransactionSet txSet; + + // NB: transactions are sorted in apply order here + // fees for all transactions are processed first + // followed by applying transactions + TransactionResultMeta txProcessing<>; + + // upgrades are applied last + UpgradeEntryMeta upgradesProcessing<>; + + // other misc information attached to the ledger close + SCPHistoryEntry scpInfo<>; +}; + union LedgerCloseMeta switch (int v) { case 0: LedgerCloseMetaV0 v0; +case 1: + LedgerCloseMetaV1 v1; }; } diff --git a/Stellar-overlay.x b/Stellar-overlay.x index 9e3a083..0601a3a 100644 --- a/Stellar-overlay.x +++ b/Stellar-overlay.x @@ -74,6 +74,7 @@ struct PeerAddress uint32 numFailures; }; +// Next ID: 18 enum MessageType { ERROR_MSG = 0, @@ -85,6 +86,7 @@ enum MessageType GET_TX_SET = 6, // gets a particular txset by hash TX_SET = 7, + GENERALIZED_TX_SET = 17, TRANSACTION = 8, // pass on a tx you have heard about @@ -202,6 +204,8 @@ case GET_TX_SET: uint256 txSetHash; case TX_SET: TransactionSet txSet; +case GENERALIZED_TX_SET: + GeneralizedTransactionSet generalizedTxSet; case TRANSACTION: TransactionEnvelope transaction; From f5edc071c92bd252c2d78d0c528cfdeefce058ef Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 29 Jun 2022 20:45:20 -0700 Subject: [PATCH 005/112] Pick up Stellar-internal.x (#4) --- Stellar-internal.x | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Stellar-internal.x diff --git a/Stellar-internal.x b/Stellar-internal.x new file mode 100644 index 0000000..0fe4a98 --- /dev/null +++ b/Stellar-internal.x @@ -0,0 +1,32 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +// This is for 'internal'-only messages that are not meant to be read/written +// by any other binaries besides a single Core instance. +%#include "xdr/Stellar-ledger.h" +%#include "xdr/Stellar-SCP.h" + +namespace stellar +{ +union StoredTransactionSet switch (int v) +{ +case 0: + TransactionSet txSet; +case 1: + GeneralizedTransactionSet generalizedTxSet; +}; + +struct PersistedSCPStateV0 +{ + SCPEnvelope scpEnvelopes<>; + SCPQuorumSet quorumSets<>; + StoredTransactionSet txSets<>; +}; + +union PersistedSCPState switch (int v) +{ +case 0: + PersistedSCPStateV0 v0; +}; +} \ No newline at end of file From f0a767c5ee60586bd4ab2526960ec253f5b571a4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 29 Jun 2022 20:47:49 -0700 Subject: [PATCH 006/112] add .gitignore (#5) --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea1046b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.h +*.o From d1b194f71d1a78f52bbcd603c27ab6b1046def22 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 12 Jul 2022 16:07:07 -0700 Subject: [PATCH 007/112] Absorb changes from rs-stellar-xdr repo (#7) --- Stellar-contract-spec.x | 175 ++++++++++++++++++++++++++++++++++++++++ Stellar-contract.x | 140 +++++++++++++++++++++++++++++++- 2 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 Stellar-contract-spec.x diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x new file mode 100644 index 0000000..b33504c --- /dev/null +++ b/Stellar-contract-spec.x @@ -0,0 +1,175 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +// The contract spec XDR is highly experimental, incomplete, and still being +// iterated on. Breaking changes expected. + +% #include "xdr/Stellar-types.h" +% #include "xdr/Stellar-contract.h" +namespace stellar +{ + +enum SpecType +{ + // Types with no parameters. + SPEC_TYPE_U32 = 1, + SPEC_TYPE_I32 = 2, + SPEC_TYPE_U64 = 3, + SPEC_TYPE_I64 = 4, + SPEC_TYPE_BOOL = 5, + SPEC_TYPE_SYMBOL = 6, + SPEC_TYPE_BITSET = 7, + SPEC_TYPE_STATUS = 8, + SPEC_TYPE_BINARY = 9, + SPEC_TYPE_BIG_INT = 10, + + // Types with parameters. + SPEC_TYPE_OPTION = 1000, + SPEC_TYPE_RESULT = 1001, + SPEC_TYPE_VEC = 1002, + SPEC_TYPE_SET = 1003, + SPEC_TYPE_MAP = 1004, + SPEC_TYPE_TUPLE = 1005, + + // User defined types. + SPEC_TYPE_UDT = 2000 +}; + +struct SpecTypeOption +{ + SpecTypeDef valueType; +}; + +struct SpecTypeResult +{ + SpecTypeDef okType; + SpecTypeDef errorType; +}; + +struct SpecTypeVec +{ + SpecTypeDef elementType; +}; + +struct SpecTypeMap +{ + SpecTypeDef keyType; + SpecTypeDef valueType; +}; + +struct SpecTypeSet +{ + SpecTypeDef elementType; +}; + +struct SpecTypeTuple +{ + SpecTypeDef valueTypes<12>; +}; + +struct SpecTypeUDT +{ + string name<60>; + SpecUDTDef *udtDef; +}; + +union SpecTypeDef switch (SpecType type) +{ +case SPEC_TYPE_U64: +case SPEC_TYPE_I64: +case SPEC_TYPE_U32: +case SPEC_TYPE_I32: +case SPEC_TYPE_BOOL: +case SPEC_TYPE_SYMBOL: +case SPEC_TYPE_BITSET: +case SPEC_TYPE_STATUS: +case SPEC_TYPE_BINARY: +case SPEC_TYPE_BIG_INT: + void; +case SPEC_TYPE_OPTION: + SpecTypeOption option; +case SPEC_TYPE_RESULT: + SpecTypeResult result; +case SPEC_TYPE_VEC: + SpecTypeVec vec; +case SPEC_TYPE_MAP: + SpecTypeMap map; +case SPEC_TYPE_SET: + SpecTypeSet set; +case SPEC_TYPE_TUPLE: + SpecTypeTuple tuple; +case SPEC_TYPE_UDT: + SpecTypeUDT udt; +}; + +enum SpecUDTType +{ + SPEC_UDT_STRUCT = 0, + SPEC_UDT_UNION = 1 +}; + +struct SpecUDTStructField +{ + string name<30>; + SpecTypeDef type; +}; + +struct SpecUDTStruct +{ + SpecUDTStructField fields<40>; +}; + +struct SpecUDTUnionCase +{ + string name<60>; + SpecTypeDef *type; +}; + +struct SpecUDTUnion +{ + SpecUDTUnionCase cases<50>; +}; + +union SpecUDTDef switch (SpecUDTType type) +{ +case SPEC_UDT_STRUCT: + SpecUDTStruct struct; +case SPEC_UDT_UNION: + SpecUDTUnion union; +}; + +union SpecEntryFunction switch (int v) +{ +case 0: + struct { + SCSymbol name; + SpecTypeDef inputTypes<10>; + SpecTypeDef outputTypes<1>; + } v0; +}; + +union SpecEntryUDT switch (int v) +{ +case 0: + struct { + string name<60>; + SpecUDTDef typ; + } v0; +}; + +enum SpecEntryKind +{ + SPEC_ENTRY_FUNCTION = 0, + SPEC_ENTRY_UDT = 1 +}; + +union SpecEntry switch (SpecEntryKind kind) +{ +case SPEC_ENTRY_FUNCTION: + SpecEntryFunction function; +case SPEC_ENTRY_UDT: + SpecEntryUDT udt; +}; + +} diff --git a/Stellar-contract.x b/Stellar-contract.x index c09a3a6..7721e45 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -71,16 +71,114 @@ enum SCStatic enum SCStatusType { SST_OK = 0, - SST_UNKNOWN_ERROR = 1 + SST_UNKNOWN_ERROR = 1, + SST_HOST_VALUE_ERROR = 2, + SST_HOST_OBJECT_ERROR = 3, + SST_HOST_FUNCTION_ERROR = 4, + SST_HOST_STORAGE_ERROR = 5, + SST_HOST_CONTEXT_ERROR = 6, + SST_VM_ERROR = 7 // TODO: add more }; +enum SCHostValErrorCode +{ + HOST_VALUE_UNKNOWN_ERROR = 0, + HOST_VALUE_RESERVED_TAG_VALUE = 1, + HOST_VALUE_UNEXPECTED_VAL_TYPE = 2, + HOST_VALUE_U63_OUT_OF_RANGE = 3, + HOST_VALUE_U32_OUT_OF_RANGE = 4, + HOST_VALUE_STATIC_UNKNOWN = 5, + HOST_VALUE_MISSING_OBJECT = 6, + HOST_VALUE_SYMBOL_TOO_LONG = 7, + HOST_VALUE_SYMBOL_BAD_CHAR = 8, + HOST_VALUE_SYMBOL_CONTAINS_NON_UTF8 = 9, + HOST_VALUE_BITSET_TOO_MANY_BITS = 10, + HOST_VALUE_STATUS_UNKNOWN = 11 +}; + +enum SCHostObjErrorCode +{ + HOST_OBJECT_UNKNOWN_ERROR = 0, + HOST_OBJECT_UNKNOWN_REFERENCE = 1, + HOST_OBJECT_UNEXPECTED_TYPE = 2, + HOST_OBJECT_OBJECT_COUNT_EXCEEDS_U32_MAX = 3, + HOST_OBJECT_OBJECT_NOT_EXIST = 4, + HOST_OBJECT_VEC_INDEX_OUT_OF_BOUND = 5, + HOST_OBJECT_CONTRACT_HASH_WRONG_LENGTH = 6 +}; + +enum SCHostFnErrorCode +{ + HOST_FN_UNKNOWN_ERROR = 0, + HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION = 1, + HOST_FN_INPUT_ARGS_WRONG_LENGTH = 2, + HOST_FN_INPUT_ARGS_WRONG_TYPE = 3, + HOST_FN_INPUT_ARGS_INVALID = 4 +}; + +enum SCHostStorageErrorCode +{ + HOST_STORAGE_UNKNOWN_ERROR = 0, + HOST_STORAGE_EXPECT_CONTRACT_DATA = 1, + HOST_STORAGE_READWRITE_ACCESS_TO_READONLY_ENTRY = 2, + HOST_STORAGE_ACCESS_TO_UNKNOWN_ENTRY = 3, + HOST_STORAGE_MISSING_KEY_IN_GET = 4, + HOST_STORAGE_GET_ON_DELETED_KEY = 5 +}; + +enum SCHostContextErrorCode +{ + HOST_CONTEXT_UNKNOWN_ERROR = 0, + HOST_CONTEXT_NO_CONTRACT_RUNNING = 1 +}; + +enum SCVmErrorCode { + VM_UNKNOWN = 0, + VM_VALIDATION = 1, + VM_INSTANTIATION = 2, + VM_FUNCTION = 3, + VM_TABLE = 4, + VM_MEMORY = 5, + VM_GLOBAL = 6, + VM_VALUE = 7, + VM_TRAP_UNREACHABLE = 8, + VM_TRAP_MEMORY_ACCESS_OUT_OF_BOUNDS = 9, + VM_TRAP_TABLE_ACCESS_OUT_OF_BOUNDS = 10, + VM_TRAP_ELEM_UNINITIALIZED = 11, + VM_TRAP_DIVISION_BY_ZERO = 12, + VM_TRAP_INTEGER_OVERFLOW = 13, + VM_TRAP_INVALID_CONVERSION_TO_INT = 14, + VM_TRAP_STACK_OVERFLOW = 15, + VM_TRAP_UNEXPECTED_SIGNATURE = 16, + VM_TRAP_MEM_LIMIT_EXCEEDED = 17, + VM_TRAP_CPU_LIMIT_EXCEEDED = 18 +}; + +enum SCUnknownErrorCode +{ + UNKNOWN_ERROR_GENERAL = 0, + UNKNOWN_ERROR_XDR = 1 +}; + union SCStatus switch (SCStatusType type) { case SST_OK: void; case SST_UNKNOWN_ERROR: - uint32 unknownCode; + SCUnknownErrorCode unknownCode; +case SST_HOST_VALUE_ERROR: + SCHostValErrorCode errorCode; +case SST_HOST_OBJECT_ERROR: + SCHostObjErrorCode errorCode; +case SST_HOST_FUNCTION_ERROR: + SCHostFnErrorCode errorCode; +case SST_HOST_STORAGE_ERROR: + SCHostStorageErrorCode errorCode; +case SST_HOST_CONTEXT_ERROR: + SCHostContextErrorCode errorCode; +case SST_VM_ERROR: + SCVmErrorCode errorCode; }; union SCVal switch (SCValType type) @@ -112,7 +210,10 @@ enum SCObjectType SCO_MAP = 1, SCO_U64 = 2, SCO_I64 = 3, - SCO_BINARY = 4 + SCO_BINARY = 4, + SCO_BIG_INT = 5, + SCO_HASH = 6, + SCO_PUBLIC_KEY = 7 // TODO: add more }; @@ -128,6 +229,33 @@ const SCVAL_LIMIT = 256000; typedef SCVal SCVec; typedef SCMapEntry SCMap; +enum SCNumSign +{ + NEGATIVE = -1, + ZERO = 0, + POSITIVE = 1 +}; + +union SCBigInt switch (SCNumSign sign) +{ +case ZERO: + void; +case POSITIVE: +case NEGATIVE: + opaque magnitude<256000>; +}; + +enum SCHashType +{ + SCHASH_SHA256 = 0 +}; + +union SCHash switch (SCHashType type) +{ +case SCHASH_SHA256: + Hash sha256; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -140,5 +268,11 @@ case SCO_I64: int64 i64; case SCO_BINARY: opaque bin; +case SCO_BIG_INT: + SCBigInt bigInt; +case SCO_HASH: + SCHash hash; +case SCO_PUBLIC_KEY: + PublicKey publicKey; }; } \ No newline at end of file From f8d5bd78b960f785869fdbcb6fab53707017e4c9 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 12 Jul 2022 20:23:38 -0700 Subject: [PATCH 008/112] Flatten contract spec discriminants (#8) --- Stellar-contract-spec.x | 64 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index b33504c..717c901 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -71,7 +71,6 @@ struct SpecTypeTuple struct SpecTypeUDT { string name<60>; - SpecUDTDef *udtDef; }; union SpecTypeDef switch (SpecType type) @@ -103,73 +102,52 @@ case SPEC_TYPE_UDT: SpecTypeUDT udt; }; -enum SpecUDTType -{ - SPEC_UDT_STRUCT = 0, - SPEC_UDT_UNION = 1 -}; - -struct SpecUDTStructField +struct SpecUDTStructFieldV0 { string name<30>; SpecTypeDef type; }; -struct SpecUDTStruct +struct SpecUDTStructV0 { - SpecUDTStructField fields<40>; + string name<60>; + SpecUDTStructFieldV0 fields<40>; }; -struct SpecUDTUnionCase +struct SpecUDTUnionCaseV0 { string name<60>; SpecTypeDef *type; }; -struct SpecUDTUnion +struct SpecUDTUnionV0 { - SpecUDTUnionCase cases<50>; -}; - -union SpecUDTDef switch (SpecUDTType type) -{ -case SPEC_UDT_STRUCT: - SpecUDTStruct struct; -case SPEC_UDT_UNION: - SpecUDTUnion union; -}; - -union SpecEntryFunction switch (int v) -{ -case 0: - struct { - SCSymbol name; - SpecTypeDef inputTypes<10>; - SpecTypeDef outputTypes<1>; - } v0; + string name<60>; + SpecUDTUnionCaseV0 cases<50>; }; -union SpecEntryUDT switch (int v) +struct SpecFunctionV0 { -case 0: - struct { - string name<60>; - SpecUDTDef typ; - } v0; + SCSymbol name; + SpecTypeDef inputTypes<10>; + SpecTypeDef outputTypes<1>; }; enum SpecEntryKind { - SPEC_ENTRY_FUNCTION = 0, - SPEC_ENTRY_UDT = 1 + SPEC_ENTRY_FUNCTION_V0 = 0, + SPEC_ENTRY_UDT_STRUCT_V0 = 1, + SPEC_ENTRY_UDT_UNION_V0 = 2 }; union SpecEntry switch (SpecEntryKind kind) { -case SPEC_ENTRY_FUNCTION: - SpecEntryFunction function; -case SPEC_ENTRY_UDT: - SpecEntryUDT udt; +case SPEC_ENTRY_FUNCTION_V0: + SpecFunctionV0 functionV0; +case SPEC_ENTRY_UDT_STRUCT_V0: + SpecUDTStructV0 udtStructV0; +case SPEC_ENTRY_UDT_UNION_V0: + SpecUDTUnionV0 udtUnionV0; }; } From bd24946fcb39eca54d66f943ac54cf52599725a1 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 13 Jul 2022 11:09:21 -0700 Subject: [PATCH 009/112] Namespace the contract spec types (#9) --- Stellar-contract-meta.x | 30 ++++++++ Stellar-contract-spec.x | 166 ++++++++++++++++++++-------------------- 2 files changed, 113 insertions(+), 83 deletions(-) create mode 100644 Stellar-contract-meta.x diff --git a/Stellar-contract-meta.x b/Stellar-contract-meta.x new file mode 100644 index 0000000..08d99c8 --- /dev/null +++ b/Stellar-contract-meta.x @@ -0,0 +1,30 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +// The contract spec XDR is highly experimental, incomplete, and still being +// iterated on. Breaking changes expected. + +% #include "xdr/Stellar-types.h" +% #include "xdr/Stellar-contract.h" +namespace stellar +{ + +enum SpecEntryKind +{ + SPEC_ENTRY_FUNCTION_V0 = 0, + SPEC_ENTRY_UDT_STRUCT_V0 = 1, + SPEC_ENTRY_UDT_UNION_V0 = 2 +}; + +union SpecEntry switch (SpecEntryKind kind) +{ +case SPEC_ENTRY_FUNCTION_V0: + SpecFunctionV0 functionV0; +case SPEC_ENTRY_UDT_STRUCT_V0: + SpecUDTStructV0 udtStructV0; +case SPEC_ENTRY_UDT_UNION_V0: + SpecUDTUnionV0 udtUnionV0; +}; + +} diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 717c901..92fb5eb 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -2,7 +2,7 @@ // under the Apache License, Version 2.0. See the COPYING file at the root // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 -// The contract spec XDR is highly experimental, incomplete, and still being +// The contract Contractspec XDR is highly experimental, incomplete, and still being // iterated on. Breaking changes expected. % #include "xdr/Stellar-types.h" @@ -10,144 +10,144 @@ namespace stellar { -enum SpecType +enum SCSpecType { // Types with no parameters. - SPEC_TYPE_U32 = 1, - SPEC_TYPE_I32 = 2, - SPEC_TYPE_U64 = 3, - SPEC_TYPE_I64 = 4, - SPEC_TYPE_BOOL = 5, - SPEC_TYPE_SYMBOL = 6, - SPEC_TYPE_BITSET = 7, - SPEC_TYPE_STATUS = 8, - SPEC_TYPE_BINARY = 9, - SPEC_TYPE_BIG_INT = 10, + SC_SPEC_TYPE_U32 = 1, + SC_SPEC_TYPE_I32 = 2, + SC_SPEC_TYPE_U64 = 3, + SC_SPEC_TYPE_I64 = 4, + SC_SPEC_TYPE_BOOL = 5, + SC_SPEC_TYPE_SYMBOL = 6, + SC_SPEC_TYPE_BITSET = 7, + SC_SPEC_TYPE_STATUS = 8, + SC_SPEC_TYPE_BINARY = 9, + SC_SPEC_TYPE_BIG_INT = 10, // Types with parameters. - SPEC_TYPE_OPTION = 1000, - SPEC_TYPE_RESULT = 1001, - SPEC_TYPE_VEC = 1002, - SPEC_TYPE_SET = 1003, - SPEC_TYPE_MAP = 1004, - SPEC_TYPE_TUPLE = 1005, + SC_SPEC_TYPE_OPTION = 1000, + SC_SPEC_TYPE_RESULT = 1001, + SC_SPEC_TYPE_VEC = 1002, + SC_SPEC_TYPE_SET = 1003, + SC_SPEC_TYPE_MAP = 1004, + SC_SPEC_TYPE_TUPLE = 1005, // User defined types. - SPEC_TYPE_UDT = 2000 + SC_SPEC_TYPE_UDT = 2000 }; -struct SpecTypeOption +struct SCSpecTypeOption { - SpecTypeDef valueType; + SCSpecTypeDef valueType; }; -struct SpecTypeResult +struct SCSpecTypeResult { - SpecTypeDef okType; - SpecTypeDef errorType; + SCSpecTypeDef okType; + SCSpecTypeDef errorType; }; -struct SpecTypeVec +struct SCSpecTypeVec { - SpecTypeDef elementType; + SCSpecTypeDef elementType; }; -struct SpecTypeMap +struct SCSpecTypeMap { - SpecTypeDef keyType; - SpecTypeDef valueType; + SCSpecTypeDef keyType; + SCSpecTypeDef valueType; }; -struct SpecTypeSet +struct SCSpecTypeSet { - SpecTypeDef elementType; + SCSpecTypeDef elementType; }; -struct SpecTypeTuple +struct SCSpecTypeTuple { - SpecTypeDef valueTypes<12>; + SCSpecTypeDef valueTypes<12>; }; -struct SpecTypeUDT +struct SCSpecTypeUDT { string name<60>; }; -union SpecTypeDef switch (SpecType type) +union SCSpecTypeDef switch (SpecType type) { -case SPEC_TYPE_U64: -case SPEC_TYPE_I64: -case SPEC_TYPE_U32: -case SPEC_TYPE_I32: -case SPEC_TYPE_BOOL: -case SPEC_TYPE_SYMBOL: -case SPEC_TYPE_BITSET: -case SPEC_TYPE_STATUS: -case SPEC_TYPE_BINARY: -case SPEC_TYPE_BIG_INT: +case SC_SPEC_TYPE_U64: +case SC_SPEC_TYPE_I64: +case SC_SPEC_TYPE_U32: +case SC_SPEC_TYPE_I32: +case SC_SPEC_TYPE_BOOL: +case SC_SPEC_TYPE_SYMBOL: +case SC_SPEC_TYPE_BITSET: +case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_BINARY: +case SC_SPEC_TYPE_BIG_INT: void; -case SPEC_TYPE_OPTION: - SpecTypeOption option; -case SPEC_TYPE_RESULT: - SpecTypeResult result; -case SPEC_TYPE_VEC: - SpecTypeVec vec; -case SPEC_TYPE_MAP: - SpecTypeMap map; -case SPEC_TYPE_SET: - SpecTypeSet set; -case SPEC_TYPE_TUPLE: - SpecTypeTuple tuple; -case SPEC_TYPE_UDT: - SpecTypeUDT udt; -}; - -struct SpecUDTStructFieldV0 +case SC_SPEC_TYPE_OPTION: + SCSpecTypeOption option; +case SC_SPEC_TYPE_RESULT: + SCSpecTypeResult result; +case SC_SPEC_TYPE_VEC: + SCSpecTypeVec vec; +case SC_SPEC_TYPE_MAP: + SCSpecTypeMap map; +case SC_SPEC_TYPE_SET: + SCSpecTypeSet set; +case SC_SPEC_TYPE_TUPLE: + SCSpecTypeTuple tuple; +case SC_SPEC_TYPE_UDT: + SCSpecTypeUDT udt; +}; + +struct SCSpecUDTStructFieldV0 { string name<30>; - SpecTypeDef type; + SCSpecTypeDef type; }; -struct SpecUDTStructV0 +struct SCSpecUDTStructV0 { string name<60>; - SpecUDTStructFieldV0 fields<40>; + SCSpecUDTStructFieldV0 fields<40>; }; -struct SpecUDTUnionCaseV0 +struct SCSpecUDTUnionCaseV0 { string name<60>; - SpecTypeDef *type; + SCSpecTypeDef *type; }; -struct SpecUDTUnionV0 +struct SCSpecUDTUnionV0 { string name<60>; - SpecUDTUnionCaseV0 cases<50>; + SCSpecUDTUnionCaseV0 cases<50>; }; -struct SpecFunctionV0 +struct SCSpecFunctionV0 { SCSymbol name; - SpecTypeDef inputTypes<10>; - SpecTypeDef outputTypes<1>; + SCSpecTypeDef inputTypes<10>; + SCSpecTypeDef outputTypes<1>; }; -enum SpecEntryKind +enum SCSpecEntryKind { - SPEC_ENTRY_FUNCTION_V0 = 0, - SPEC_ENTRY_UDT_STRUCT_V0 = 1, - SPEC_ENTRY_UDT_UNION_V0 = 2 + SC_SPEC_ENTRY_FUNCTION_V0 = 0, + SC_SPEC_ENTRY_UDT_STRUCT_V0 = 1, + SC_SPEC_ENTRY_UDT_UNION_V0 = 2 }; -union SpecEntry switch (SpecEntryKind kind) +union SCSpecEntry switch (SpecEntryKind kind) { -case SPEC_ENTRY_FUNCTION_V0: - SpecFunctionV0 functionV0; -case SPEC_ENTRY_UDT_STRUCT_V0: - SpecUDTStructV0 udtStructV0; -case SPEC_ENTRY_UDT_UNION_V0: - SpecUDTUnionV0 udtUnionV0; +case SC_SPEC_ENTRY_FUNCTION_V0: + SCSpecFunctionV0 functionV0; +case SC_SPEC_ENTRY_UDT_STRUCT_V0: + SCSpecUDTStructV0 udtStructV0; +case SC_SPEC_ENTRY_UDT_UNION_V0: + SCSpecUDTUnionV0 udtUnionV0; }; } From 8880f0f32ae465ae499d2c2525854b2884028daa Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 13 Jul 2022 11:55:30 -0700 Subject: [PATCH 010/112] Delete Stellar-contract-meta.x (#12) --- Stellar-contract-meta.x | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 Stellar-contract-meta.x diff --git a/Stellar-contract-meta.x b/Stellar-contract-meta.x deleted file mode 100644 index 08d99c8..0000000 --- a/Stellar-contract-meta.x +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 Stellar Development Foundation and contributors. Licensed -// under the Apache License, Version 2.0. See the COPYING file at the root -// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 - -// The contract spec XDR is highly experimental, incomplete, and still being -// iterated on. Breaking changes expected. - -% #include "xdr/Stellar-types.h" -% #include "xdr/Stellar-contract.h" -namespace stellar -{ - -enum SpecEntryKind -{ - SPEC_ENTRY_FUNCTION_V0 = 0, - SPEC_ENTRY_UDT_STRUCT_V0 = 1, - SPEC_ENTRY_UDT_UNION_V0 = 2 -}; - -union SpecEntry switch (SpecEntryKind kind) -{ -case SPEC_ENTRY_FUNCTION_V0: - SpecFunctionV0 functionV0; -case SPEC_ENTRY_UDT_STRUCT_V0: - SpecUDTStructV0 udtStructV0; -case SPEC_ENTRY_UDT_UNION_V0: - SpecUDTUnionV0 udtUnionV0; -}; - -} From add83f62d0b1ff8cfc774152a9a74280eeba6216 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 13 Jul 2022 12:06:39 -0700 Subject: [PATCH 011/112] CAP-0047 - update names (#6) --- Stellar-transaction.x | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 239609f..74d4673 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -579,13 +579,13 @@ case ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: { uint256 ed25519; uint256 salt; - } contractID; + } ed25519ContractID; case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: struct { - Hash contractID; //contractID of parent contract + Hash contractID; uint256 salt; - } childContractID; + } contractID; }; enum MemoType From 0030d1c335919e32a0f5a6090a4a132fd15a7c11 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:25:49 -0700 Subject: [PATCH 012/112] Fix contract spec definitions after rename (#13) --- Stellar-contract-spec.x | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 92fb5eb..8a2a997 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -73,7 +73,7 @@ struct SCSpecTypeUDT string name<60>; }; -union SCSpecTypeDef switch (SpecType type) +union SCSpecTypeDef switch (SCSpecType type) { case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: @@ -140,7 +140,7 @@ enum SCSpecEntryKind SC_SPEC_ENTRY_UDT_UNION_V0 = 2 }; -union SCSpecEntry switch (SpecEntryKind kind) +union SCSpecEntry switch (SCSpecEntryKind kind) { case SC_SPEC_ENTRY_FUNCTION_V0: SCSpecFunctionV0 functionV0; From 1108047971210656d16623c8750c7f89b7da8ef0 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:28:52 -0700 Subject: [PATCH 013/112] Add contract meta types (#10) --- Stellar-contract-env-meta.x | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Stellar-contract-env-meta.x diff --git a/Stellar-contract-env-meta.x b/Stellar-contract-env-meta.x new file mode 100644 index 0000000..330726d --- /dev/null +++ b/Stellar-contract-env-meta.x @@ -0,0 +1,23 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +// The contract spec XDR is highly experimental, incomplete, and still being +// iterated on. Breaking changes expected. + +% #include "xdr/Stellar-types.h" +namespace stellar +{ + +enum SCEnvMetaKind +{ + SC_ENV_META_KIND_INTERFACE_VERSION = 0 +}; + +union SCEnvMetaEntry switch (SCEnvMetaKind kind) +{ +case SC_ENV_META_KIND_INTERFACE_VERSION: + uint64 interfaceVersion; +}; + +} From 1d9c6ecdd1c8b8acbb54d913f49edf51c1e04ee7 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:28:03 -0700 Subject: [PATCH 014/112] Rename BINARY to BYTES (#16) --- Stellar-contract-spec.x | 4 ++-- Stellar-contract.x | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 8a2a997..3365559 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -21,7 +21,7 @@ enum SCSpecType SC_SPEC_TYPE_SYMBOL = 6, SC_SPEC_TYPE_BITSET = 7, SC_SPEC_TYPE_STATUS = 8, - SC_SPEC_TYPE_BINARY = 9, + SC_SPEC_TYPE_BYTES = 9, SC_SPEC_TYPE_BIG_INT = 10, // Types with parameters. @@ -83,7 +83,7 @@ case SC_SPEC_TYPE_BOOL: case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: -case SC_SPEC_TYPE_BINARY: +case SC_SPEC_TYPE_BYTES: case SC_SPEC_TYPE_BIG_INT: void; case SC_SPEC_TYPE_OPTION: diff --git a/Stellar-contract.x b/Stellar-contract.x index 7721e45..2f47e1a 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -210,7 +210,7 @@ enum SCObjectType SCO_MAP = 1, SCO_U64 = 2, SCO_I64 = 3, - SCO_BINARY = 4, + SCO_BYTES = 4, SCO_BIG_INT = 5, SCO_HASH = 6, SCO_PUBLIC_KEY = 7 @@ -266,7 +266,7 @@ case SCO_U64: uint64 u64; case SCO_I64: int64 i64; -case SCO_BINARY: +case SCO_BYTES: opaque bin; case SCO_BIG_INT: SCBigInt bigInt; @@ -275,4 +275,4 @@ case SCO_HASH: case SCO_PUBLIC_KEY: PublicKey publicKey; }; -} \ No newline at end of file +} From b731cd6cb5a3add5e92903a932d4ab85441f2e9a Mon Sep 17 00:00:00 2001 From: jonjove <31668823+jonjove@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:37:51 -0500 Subject: [PATCH 015/112] Add SCContractCode and update related types (#17) --- Stellar-contract.x | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 2f47e1a..7a88631 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -65,7 +65,7 @@ enum SCStatic SCS_VOID = 0, SCS_TRUE = 1, SCS_FALSE = 2, - SCS_LEDGER_KEY_CONTRACT_CODE_WASM = 3 + SCS_LEDGER_KEY_CONTRACT_CODE = 3 }; enum SCStatusType @@ -213,7 +213,8 @@ enum SCObjectType SCO_BYTES = 4, SCO_BIG_INT = 5, SCO_HASH = 6, - SCO_PUBLIC_KEY = 7 + SCO_PUBLIC_KEY = 7, + SCO_CONTRACT_CODE = 8 // TODO: add more }; @@ -256,6 +257,20 @@ case SCHASH_SHA256: Hash sha256; }; +enum SCContractCodeType +{ + SCCONTRACT_CODE_WASM = 0, + SCCONTRACT_CODE_TOKEN = 1 +}; + +union SCContractCode switch (SCContractCodeType type) +{ +case SCCONTRACT_CODE_WASM: + opaque wasm; +case SCCONTRACT_CODE_TOKEN: + void; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -274,5 +289,7 @@ case SCO_HASH: SCHash hash; case SCO_PUBLIC_KEY: PublicKey publicKey; +case SCO_CONTRACT_CODE: + SCContractCode contractCode; }; } From 64f0c032ef6b972b4a85e30b757247dbafc11ba1 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 17 Aug 2022 10:25:57 -0700 Subject: [PATCH 016/112] Add names to function inputs in contract spec (#18) --- Stellar-contract-spec.x | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 3365559..4ad9aae 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -126,11 +126,17 @@ struct SCSpecUDTUnionV0 SCSpecUDTUnionCaseV0 cases<50>; }; +struct SCSpecFunctionInputV0 +{ + string name<30>; + SCSpecTypeDef type; +}; + struct SCSpecFunctionV0 { SCSymbol name; - SCSpecTypeDef inputTypes<10>; - SCSpecTypeDef outputTypes<1>; + SCSpecFunctionInputV0 inputs<10>; + SCSpecTypeDef outputs<1>; }; enum SCSpecEntryKind From 9fc46ee806f79dae560dd7bef966872ad86fdf4d Mon Sep 17 00:00:00 2001 From: mlo Date: Thu, 18 Aug 2022 13:36:56 -0700 Subject: [PATCH 017/112] Pick up persistent state changes (#19) --- Stellar-internal.x | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Stellar-internal.x b/Stellar-internal.x index 0fe4a98..73684db 100644 --- a/Stellar-internal.x +++ b/Stellar-internal.x @@ -24,9 +24,18 @@ struct PersistedSCPStateV0 StoredTransactionSet txSets<>; }; +struct PersistedSCPStateV1 +{ + // Tx sets are saved separately + SCPEnvelope scpEnvelopes<>; + SCPQuorumSet quorumSets<>; +}; + union PersistedSCPState switch (int v) { case 0: PersistedSCPStateV0 v0; +case 1: + PersistedSCPStateV1 v1; }; } \ No newline at end of file From 6e8ac4ebbef86b044f78f8851154d8094bc86433 Mon Sep 17 00:00:00 2001 From: jonjove <31668823+jonjove@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:23:34 -0500 Subject: [PATCH 018/112] Fix repeated errorCode in SCStatus (#20) --- Stellar-contract.x | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 7a88631..aa2b69e 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -168,17 +168,17 @@ case SST_OK: case SST_UNKNOWN_ERROR: SCUnknownErrorCode unknownCode; case SST_HOST_VALUE_ERROR: - SCHostValErrorCode errorCode; + SCHostValErrorCode valCode; case SST_HOST_OBJECT_ERROR: - SCHostObjErrorCode errorCode; + SCHostObjErrorCode objCode; case SST_HOST_FUNCTION_ERROR: - SCHostFnErrorCode errorCode; + SCHostFnErrorCode fnCode; case SST_HOST_STORAGE_ERROR: - SCHostStorageErrorCode errorCode; + SCHostStorageErrorCode storageCode; case SST_HOST_CONTEXT_ERROR: - SCHostContextErrorCode errorCode; + SCHostContextErrorCode contextCode; case SST_VM_ERROR: - SCVmErrorCode errorCode; + SCVmErrorCode vmCode; }; union SCVal switch (SCValType type) From 35f1e4eed2149063020feeedf9e1f139471dd052 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 23 Aug 2022 22:02:24 -0700 Subject: [PATCH 019/112] Pick up changes incorrectly committed to rs-stellar-xdr (#21) --- Stellar-ledger.x | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 848b7d6..bad1a08 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -359,6 +359,33 @@ struct TransactionMetaV2 // applied if any }; +enum ContractEventType +{ + SYSTEM = 0, + CONTRACT = 1 +}; + +struct ContractEvent +{ + // We can use this to add more fields, or because it + // is first, to change ContractEvent into a union. + ExtensionPoint ext; + + Hash* contractID; + ContractEventType type; + + union switch (int v) + { + case 0: + struct + { + SCVec topics; + SCVal data; + } v0; + } + body; +}; + // this is the meta produced when applying transactions // it does not include pre-apply updates such as fees union TransactionMeta switch (int v) From 950dcd3a992049aff44ec1b0221d66f55c7724f2 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 24 Aug 2022 15:48:11 -0700 Subject: [PATCH 020/112] Add rest of CAP-0056 (#22) --- Stellar-ledger.x | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index bad1a08..ce4d697 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -275,6 +275,32 @@ struct TransactionHistoryResultEntry ext; }; +struct TransactionResultPairV2 +{ + Hash transactionHash; + Hash hashOfMetaHashes; // hash of hashes in TransactionMetaV3 + // TransactionResult is in the meta +}; + +struct TransactionResultSetV2 +{ + TransactionResultPairV2 results<>; +}; + +struct TransactionHistoryResultEntryV2 +{ + uint32 ledgerSeq; + TransactionResultSetV2 txResultSet; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + struct LedgerHeaderHistoryEntry { Hash hash; @@ -386,6 +412,21 @@ struct ContractEvent body; }; +struct TransactionMetaV3 +{ + LedgerEntryChanges txChangesBefore; // tx level changes before operations + // are applied if any + OperationMeta operations<>; // meta for each operation + LedgerEntryChanges txChangesAfter; // tx level changes after operations are + // applied if any + ContractEvent events<>; // custom events populated by the + // contracts themselves + TransactionResult txResult; + + Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), + // sha256(events), and sha256(txResult) +}; + // this is the meta produced when applying transactions // it does not include pre-apply updates such as fees union TransactionMeta switch (int v) @@ -396,6 +437,8 @@ case 1: TransactionMetaV1 v1; case 2: TransactionMetaV2 v2; +case 3: + TransactionMetaV3 v3; }; // This struct groups together changes on a per transaction basis @@ -408,6 +451,13 @@ struct TransactionResultMeta TransactionMeta txApplyProcessing; }; +struct TransactionResultMetaV2 +{ + TransactionResultPairV2 result; + LedgerEntryChanges feeProcessing; + TransactionMeta txApplyProcessing; +}; + // this represents a single upgrade that was performed as part of a ledger // upgrade struct UpgradeEntryMeta @@ -452,11 +502,32 @@ struct LedgerCloseMetaV1 SCPHistoryEntry scpInfo<>; }; +// only difference between V1 and V2 is this uses TransactionResultMetaV2 +struct LedgerCloseMetaV2 +{ + LedgerHeaderHistoryEntry ledgerHeader; + + GeneralizedTransactionSet txSet; + + // NB: transactions are sorted in apply order here + // fees for all transactions are processed first + // followed by applying transactions + TransactionResultMetaV2 txProcessing<>; + + // upgrades are applied last + UpgradeEntryMeta upgradesProcessing<>; + + // other misc information attached to the ledger close + SCPHistoryEntry scpInfo<>; +}; + union LedgerCloseMeta switch (int v) { case 0: LedgerCloseMetaV0 v0; case 1: LedgerCloseMetaV1 v1; +case 2: + LedgerCloseMetaV2 v2; }; } From 67a36112163bc4e9124a3ae8136052642d0ec142 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:09:21 -0700 Subject: [PATCH 021/112] Add BytesN as type (#23) --- Stellar-contract-spec.x | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 4ad9aae..36675a1 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -31,6 +31,7 @@ enum SCSpecType SC_SPEC_TYPE_SET = 1003, SC_SPEC_TYPE_MAP = 1004, SC_SPEC_TYPE_TUPLE = 1005, + SC_SPEC_TYPE_BYTES_N = 1006, // User defined types. SC_SPEC_TYPE_UDT = 2000 @@ -68,6 +69,11 @@ struct SCSpecTypeTuple SCSpecTypeDef valueTypes<12>; }; +struct SCSpecTypeBytesN +{ + uint32 n; +}; + struct SCSpecTypeUDT { string name<60>; @@ -98,6 +104,8 @@ case SC_SPEC_TYPE_SET: SCSpecTypeSet set; case SC_SPEC_TYPE_TUPLE: SCSpecTypeTuple tuple; +case SC_SPEC_TYPE_BYTES_N: + SCSpecTypeBytesN bytesN; case SC_SPEC_TYPE_UDT: SCSpecTypeUDT udt; }; From bc2e59030281fc4d8823cb2d17e5fe21b2e3987b Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:36:09 -0700 Subject: [PATCH 022/112] Add Val as a spec type (#25) --- Stellar-contract-spec.x | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 36675a1..90d46a8 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -12,6 +12,8 @@ namespace stellar enum SCSpecType { + SC_SPEC_TYPE_VAL = 0, + // Types with no parameters. SC_SPEC_TYPE_U32 = 1, SC_SPEC_TYPE_I32 = 2, @@ -81,6 +83,7 @@ struct SCSpecTypeUDT union SCSpecTypeDef switch (SCSpecType type) { +case SC_SPEC_TYPE_VAL: case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: case SC_SPEC_TYPE_U32: From a05d5285e2bf4ac528beed7f386ee1e3eae43fac Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 29 Aug 2022 23:35:33 -0700 Subject: [PATCH 023/112] Add name of lib to struct and union spec entries (#26) --- Stellar-contract-spec.x | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 90d46a8..3e77593 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -121,6 +121,7 @@ struct SCSpecUDTStructFieldV0 struct SCSpecUDTStructV0 { + string lib<80>; string name<60>; SCSpecUDTStructFieldV0 fields<40>; }; @@ -133,6 +134,7 @@ struct SCSpecUDTUnionCaseV0 struct SCSpecUDTUnionV0 { + string lib<80>; string name<60>; SCSpecUDTUnionCaseV0 cases<50>; }; From 20423e4cb5a9069764f76f168d71595cc6351695 Mon Sep 17 00:00:00 2001 From: Hidenori Date: Fri, 2 Sep 2022 13:48:07 -0400 Subject: [PATCH 024/112] Add adverts & demands to StellarMessage (#24) --- Stellar-overlay.x | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/Stellar-overlay.x b/Stellar-overlay.x index 0601a3a..ac67956 100644 --- a/Stellar-overlay.x +++ b/Stellar-overlay.x @@ -47,11 +47,19 @@ struct Hello uint256 nonce; }; +// During the roll-out phrase, pull mode will be optional. +// Therefore, we need a way to communicate with other nodes +// that we want/don't want pull mode. +// However, the goal is for everyone to enable it by default, +// so we don't want to introduce a new member variable. +// For now, we'll use the `flags` field (originally named +// `unused`) in `Auth`. +// 100 is just a number that is not 0. +const AUTH_MSG_FLAG_PULL_MODE_REQUESTED = 100; + struct Auth { - // Empty message, just to confirm - // establishment of MAC keys. - int unused; + int flags; }; enum IPAddrType @@ -102,7 +110,9 @@ enum MessageType SURVEY_REQUEST = 14, SURVEY_RESPONSE = 15, - SEND_MORE = 16 + SEND_MORE = 16, + FLOOD_ADVERT = 18, + FLOOD_DEMAND = 19 }; struct DontHave @@ -179,6 +189,22 @@ struct TopologyResponseBody uint32 totalOutboundPeerCount; }; +const TX_ADVERT_VECTOR_MAX_SIZE = 1000; +typedef Hash TxAdvertVector; + +struct FloodAdvert +{ + TxAdvertVector txHashes; +}; + +const TX_DEMAND_VECTOR_MAX_SIZE = 1000; +typedef Hash TxDemandVector; + +struct FloodDemand +{ + TxDemandVector txHashes; +}; + union SurveyResponseBody switch (SurveyMessageCommandType type) { case SURVEY_TOPOLOGY: @@ -227,6 +253,12 @@ case GET_SCP_STATE: uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest case SEND_MORE: SendMore sendMoreMessage; + +// Pull mode +case FLOOD_ADVERT: + FloodAdvert floodAdvert; +case FLOOD_DEMAND: + FloodDemand floodDemand; }; union AuthenticatedMessage switch (uint32 v) From d194cc6cd79e3b368c43477556b0084e81b9dcbc Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 12 Sep 2022 10:20:34 -0700 Subject: [PATCH 025/112] Add SST_CONTRACT_ERROR to SCStatusType (#29) --- Stellar-contract.x | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index aa2b69e..4f36ab1 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -77,7 +77,8 @@ enum SCStatusType SST_HOST_FUNCTION_ERROR = 4, SST_HOST_STORAGE_ERROR = 5, SST_HOST_CONTEXT_ERROR = 6, - SST_VM_ERROR = 7 + SST_VM_ERROR = 7, + SST_CONTRACT_ERROR = 8 // TODO: add more }; @@ -179,6 +180,8 @@ case SST_HOST_CONTEXT_ERROR: SCHostContextErrorCode contextCode; case SST_VM_ERROR: SCVmErrorCode vmCode; +case SST_CONTRACT_ERROR: + uint32 contractCode; }; union SCVal switch (SCValType type) From 8f3993e2712b3661deb0f55468de0c40fb6596fd Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Tue, 13 Sep 2022 22:12:56 -0400 Subject: [PATCH 026/112] Remove `ScHash` and `PublicKey` from object type. (#31) --- Stellar-contract.x | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 4f36ab1..2908da7 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -215,9 +215,7 @@ enum SCObjectType SCO_I64 = 3, SCO_BYTES = 4, SCO_BIG_INT = 5, - SCO_HASH = 6, - SCO_PUBLIC_KEY = 7, - SCO_CONTRACT_CODE = 8 + SCO_CONTRACT_CODE = 6 // TODO: add more }; @@ -249,17 +247,6 @@ case NEGATIVE: opaque magnitude<256000>; }; -enum SCHashType -{ - SCHASH_SHA256 = 0 -}; - -union SCHash switch (SCHashType type) -{ -case SCHASH_SHA256: - Hash sha256; -}; - enum SCContractCodeType { SCCONTRACT_CODE_WASM = 0, @@ -288,10 +275,6 @@ case SCO_BYTES: opaque bin; case SCO_BIG_INT: SCBigInt bigInt; -case SCO_HASH: - SCHash hash; -case SCO_PUBLIC_KEY: - PublicKey publicKey; case SCO_CONTRACT_CODE: SCContractCode contractCode; }; From c874126037a6c6726f413f3bd1c9ddfd43702935 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 16 Sep 2022 20:22:09 -0700 Subject: [PATCH 027/112] Add enum as a contract spec type (#34) --- Stellar-contract-spec.x | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 3e77593..6f438c2 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -139,6 +139,19 @@ struct SCSpecUDTUnionV0 SCSpecUDTUnionCaseV0 cases<50>; }; +struct SCSpecUDTEnumCaseV0 +{ + string name<60>; + uint32 value; +}; + +struct SCSpecUDTEnumV0 +{ + string lib<80>; + string name<60>; + SCSpecUDTEnumCaseV0 cases<50>; +}; + struct SCSpecFunctionInputV0 { string name<30>; @@ -156,7 +169,8 @@ enum SCSpecEntryKind { SC_SPEC_ENTRY_FUNCTION_V0 = 0, SC_SPEC_ENTRY_UDT_STRUCT_V0 = 1, - SC_SPEC_ENTRY_UDT_UNION_V0 = 2 + SC_SPEC_ENTRY_UDT_UNION_V0 = 2, + SC_SPEC_ENTRY_UDT_ENUM_V0 = 3 }; union SCSpecEntry switch (SCSpecEntryKind kind) @@ -167,6 +181,8 @@ case SC_SPEC_ENTRY_UDT_STRUCT_V0: SCSpecUDTStructV0 udtStructV0; case SC_SPEC_ENTRY_UDT_UNION_V0: SCSpecUDTUnionV0 udtUnionV0; +case SC_SPEC_ENTRY_UDT_ENUM_V0: + SCSpecUDTEnumV0 udtEnumV0; }; } From 3f678ed01c167808ffc4853d47dd7c9abd8bc1de Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 19 Sep 2022 21:33:52 -0700 Subject: [PATCH 028/112] Add error enum as a distinct UDT type from enum (#35) --- Stellar-contract-spec.x | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 6f438c2..e624a77 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -152,6 +152,19 @@ struct SCSpecUDTEnumV0 SCSpecUDTEnumCaseV0 cases<50>; }; +struct SCSpecUDTErrorEnumCaseV0 +{ + string name<60>; + uint32 value; +}; + +struct SCSpecUDTErrorEnumV0 +{ + string lib<80>; + string name<60>; + SCSpecUDTErrorEnumCaseV0 cases<50>; +}; + struct SCSpecFunctionInputV0 { string name<30>; @@ -170,7 +183,8 @@ enum SCSpecEntryKind SC_SPEC_ENTRY_FUNCTION_V0 = 0, SC_SPEC_ENTRY_UDT_STRUCT_V0 = 1, SC_SPEC_ENTRY_UDT_UNION_V0 = 2, - SC_SPEC_ENTRY_UDT_ENUM_V0 = 3 + SC_SPEC_ENTRY_UDT_ENUM_V0 = 3, + SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0 = 4 }; union SCSpecEntry switch (SCSpecEntryKind kind) @@ -183,6 +197,8 @@ case SC_SPEC_ENTRY_UDT_UNION_V0: SCSpecUDTUnionV0 udtUnionV0; case SC_SPEC_ENTRY_UDT_ENUM_V0: SCSpecUDTEnumV0 udtEnumV0; +case SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0: + SCSpecUDTErrorEnumV0 udtErrorEnumV0; }; } From 7068cf03151e4bf342bea3fb9d8b2ba4b809317b Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 21 Sep 2022 12:53:37 -0700 Subject: [PATCH 029/112] Add SCVal success to INVOKE_HOST_FUNCTION_SUCCESS, fix stellar/stellar-protocol#1307 (#36) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 74d4673..4d84a44 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1642,7 +1642,7 @@ enum InvokeHostFunctionResultCode union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) { case INVOKE_HOST_FUNCTION_SUCCESS: - void; + SCVal success; case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: void; From dec57dedc5e687b54bc2b035864e2417a5599d6a Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 23 Sep 2022 10:57:51 -0700 Subject: [PATCH 030/112] Updated xdr for token wrapper and source auth (#37) * add ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET * add new HostFunction type and HashIDPreimage for using the source account in the host --- Stellar-ledger-entries.x | 4 +++- Stellar-transaction.x | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 20c37e3..25ffc87 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -644,6 +644,8 @@ enum EnvelopeType ENVELOPE_TYPE_OP_ID = 6, ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7, ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8, - ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9 + ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, + ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, + ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE = 11 }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 4d84a44..dba3778 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -586,6 +586,14 @@ case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: Hash contractID; uint256 salt; } contractID; +case ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: + Asset fromAsset; +case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE: + struct + { + AccountID sourceAccount; + uint256 salt; + } sourceContractID; }; enum MemoType From 78ddb7f2d1ca6111467fdc85c6105ce50baf1b98 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 23 Sep 2022 12:18:31 -0700 Subject: [PATCH 031/112] add missing enum value (#38) --- Stellar-transaction.x | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index dba3778..fa42501 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -477,7 +477,8 @@ struct LiquidityPoolWithdrawOp enum HostFunction { HOST_FN_CALL = 0, - HOST_FN_CREATE_CONTRACT = 1 + HOST_FN_CREATE_CONTRACT = 1, + HOST_FN_CREATE_CONTRACT_WITH_SOURCE = 2 }; struct InvokeHostFunctionOp From 3002dcfe4782272730a1e17999a3fb00218f6bac Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 23 Sep 2022 14:02:08 -0700 Subject: [PATCH 032/112] rename HOST_FN_CREATE_CONTRACT (#39) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index fa42501..428e113 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -477,7 +477,7 @@ struct LiquidityPoolWithdrawOp enum HostFunction { HOST_FN_CALL = 0, - HOST_FN_CREATE_CONTRACT = 1, + HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1, HOST_FN_CREATE_CONTRACT_WITH_SOURCE = 2 }; From 03b0967c920bcc717aef64d03d10148619bbbe30 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:19:03 -0700 Subject: [PATCH 033/112] Add invoker to contract spec (#40) --- Stellar-contract-spec.x | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index e624a77..06af029 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -25,6 +25,7 @@ enum SCSpecType SC_SPEC_TYPE_STATUS = 8, SC_SPEC_TYPE_BYTES = 9, SC_SPEC_TYPE_BIG_INT = 10, + SC_SPEC_TYPE_INVOKER = 11, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -94,6 +95,7 @@ case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: case SC_SPEC_TYPE_BIG_INT: +case SC_SPEC_TYPE_INVOKER: void; case SC_SPEC_TYPE_OPTION: SCSpecTypeOption option; From 87af5d5916e10d3479e6710786fa1db8d3403f60 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:56:57 -0700 Subject: [PATCH 034/112] Add account id as object type (#41) --- Stellar-contract.x | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 2908da7..7c5fe68 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -215,7 +215,8 @@ enum SCObjectType SCO_I64 = 3, SCO_BYTES = 4, SCO_BIG_INT = 5, - SCO_CONTRACT_CODE = 6 + SCO_CONTRACT_CODE = 6, + SCO_ACCOUNT_ID = 7 // TODO: add more }; @@ -277,5 +278,7 @@ case SCO_BIG_INT: SCBigInt bigInt; case SCO_CONTRACT_CODE: SCContractCode contractCode; +case SCO_ACCOUNT_ID: + AccountID accountID; }; } From 29051b1df75c7a7451e071bac10ca805ae247e9b Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 09:56:03 -0700 Subject: [PATCH 035/112] Rename HOST_FN_CREATE_CONTRACT_WITH_SOURCE to HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT (#42) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 428e113..e5e3af8 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -478,7 +478,7 @@ enum HostFunction { HOST_FN_CALL = 0, HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1, - HOST_FN_CREATE_CONTRACT_WITH_SOURCE = 2 + HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2 }; struct InvokeHostFunctionOp From 2f824a1bd2e81ae8950d17bb82bf2d3b196a81f1 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:28:40 -0700 Subject: [PATCH 036/112] Rename ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE to ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT (#43) --- Stellar-ledger-entries.x | 2 +- Stellar-transaction.x | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 25ffc87..046f4a5 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -646,6 +646,6 @@ enum EnvelopeType ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8, ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, - ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE = 11 + ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11 }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index e5e3af8..0a038ee 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -589,7 +589,7 @@ case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: } contractID; case ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: Asset fromAsset; -case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE: +case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: struct { AccountID sourceAccount; From 8b2c5d107714baf2e7271eee82ae91530fc41114 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:44:05 -0700 Subject: [PATCH 037/112] Rename sourceContractID to sourceAccountContractID (#44) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 0a038ee..6a581ab 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -594,7 +594,7 @@ case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: { AccountID sourceAccount; uint256 salt; - } sourceContractID; + } sourceAccountContractID; }; enum MemoType From e53c34427e6137812b04449f2c460caea057027f Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:50:52 -0700 Subject: [PATCH 038/112] Add AccountID as type to contract spec (#45) --- Stellar-contract-spec.x | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 06af029..2e18755 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -26,6 +26,7 @@ enum SCSpecType SC_SPEC_TYPE_BYTES = 9, SC_SPEC_TYPE_BIG_INT = 10, SC_SPEC_TYPE_INVOKER = 11, + SC_SPEC_TYPE_ACCOUNT_ID = 12, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -96,6 +97,7 @@ case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: case SC_SPEC_TYPE_BIG_INT: case SC_SPEC_TYPE_INVOKER: +case SC_SPEC_TYPE_ACCOUNT_ID: void; case SC_SPEC_TYPE_OPTION: SCSpecTypeOption option; From 8a8bac24489a41ae3d3468c0287261e27c84c999 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 26 Sep 2022 15:23:22 -0700 Subject: [PATCH 039/112] move AccountID to avoid circular reference (#46) --- Stellar-ledger-entries.x | 1 - Stellar-types.x | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 046f4a5..9caf8bd 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -8,7 +8,6 @@ namespace stellar { -typedef PublicKey AccountID; typedef opaque Thresholds[4]; typedef string string32<32>; typedef string string64<64>; diff --git a/Stellar-types.x b/Stellar-types.x index c3a1ebe..a6f9bf9 100644 --- a/Stellar-types.x +++ b/Stellar-types.x @@ -79,6 +79,7 @@ typedef opaque Signature<64>; typedef opaque SignatureHint[4]; typedef PublicKey NodeID; +typedef PublicKey AccountID; struct Curve25519Secret { From 161e2e5b64425a49f9ccfef7f732ae742ed5eec4 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 28 Sep 2022 08:49:49 -0700 Subject: [PATCH 040/112] Add new host functions to xdr (#47) * Add new host functions to xdr * rename --- Stellar-transaction.x | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 6a581ab..cdf108b 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -476,9 +476,11 @@ struct LiquidityPoolWithdrawOp enum HostFunction { - HOST_FN_CALL = 0, + HOST_FN_INVOKE_CONTRACT = 0, HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1, - HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2 + HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2, + HOST_FN_CREATE_TOKEN_CONTRACT_WITH_SOURCE_ACCOUNT = 3, + HOST_FN_CREATE_TOKEN_CONTRACT_WITH_ASSET = 4 }; struct InvokeHostFunctionOp From 48d5e17ae63bba0aa9725cd9d18d7438f44c07b1 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 27 Oct 2022 19:19:16 -0700 Subject: [PATCH 041/112] Trivial whitespace changes to Stellar-overlay.x to sync with curr (#50) --- Stellar-overlay.x | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Stellar-overlay.x b/Stellar-overlay.x index ac67956..64fd97a 100644 --- a/Stellar-overlay.x +++ b/Stellar-overlay.x @@ -47,6 +47,7 @@ struct Hello uint256 nonce; }; + // During the roll-out phrase, pull mode will be optional. // Therefore, we need a way to communicate with other nodes // that we want/don't want pull mode. @@ -189,6 +190,12 @@ struct TopologyResponseBody uint32 totalOutboundPeerCount; }; +union SurveyResponseBody switch (SurveyMessageCommandType type) +{ +case SURVEY_TOPOLOGY: + TopologyResponseBody topologyResponseBody; +}; + const TX_ADVERT_VECTOR_MAX_SIZE = 1000; typedef Hash TxAdvertVector; @@ -205,12 +212,6 @@ struct FloodDemand TxDemandVector txHashes; }; -union SurveyResponseBody switch (SurveyMessageCommandType type) -{ -case SURVEY_TOPOLOGY: - TopologyResponseBody topologyResponseBody; -}; - union StellarMessage switch (MessageType type) { case ERROR_MSG: @@ -256,9 +257,9 @@ case SEND_MORE: // Pull mode case FLOOD_ADVERT: - FloodAdvert floodAdvert; + FloodAdvert floodAdvert; case FLOOD_DEMAND: - FloodDemand floodDemand; + FloodDemand floodDemand; }; union AuthenticatedMessage switch (uint32 v) From 1a76201f837e5b0f4fa5aff228ee865bfc1f6361 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 10 Nov 2022 17:23:34 -0500 Subject: [PATCH 042/112] XDR side of the contract deployment changes specified in CAP-46-02. (#51) * XDR side of the contract deployment changes specified in CAP-46-02. This introduces the ledger entries to store the wasm code and also changes the host functions to support creating/installing the contracts. * Remove option to create and install contract in the same operation. This relies on the ability to include multiple Soroban operations in the transaction. We can bring this back if we decide against that. --- Stellar-contract.x | 6 +-- Stellar-ledger-entries.x | 20 +++++++++- Stellar-transaction.x | 79 ++++++++++++++++++++++++++++++++++------ 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 7c5fe68..d7f34b4 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -250,14 +250,14 @@ case NEGATIVE: enum SCContractCodeType { - SCCONTRACT_CODE_WASM = 0, + SCCONTRACT_CODE_WASM_REF = 0, SCCONTRACT_CODE_TOKEN = 1 }; union SCContractCode switch (SCContractCodeType type) { -case SCCONTRACT_CODE_WASM: - opaque wasm; +case SCCONTRACT_CODE_WASM_REF: + Hash wasm_id; case SCCONTRACT_CODE_TOKEN: void; }; diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 9caf8bd..2616d2c 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -100,7 +100,8 @@ enum LedgerEntryType CLAIMABLE_BALANCE = 4, LIQUIDITY_POOL = 5, CONTRACT_DATA = 6, - CONFIG_SETTING = 7 + CONTRACT_CODE = 7, + CONFIG_SETTING = 8 }; struct Signer @@ -499,6 +500,13 @@ struct ContractDataEntry { SCVal val; }; +struct ContractCodeEntry { + ExtensionPoint ext; + + Hash hash; + opaque code; +}; + enum ConfigSettingType { CONFIG_SETTING_TYPE_UINT32 = 0 @@ -560,6 +568,8 @@ struct LedgerEntry LiquidityPoolEntry liquidityPool; case CONTRACT_DATA: ContractDataEntry contractData; + case CONTRACT_CODE: + ContractCodeEntry contractCode; case CONFIG_SETTING: ConfigSettingEntry configSetting; } @@ -622,6 +632,11 @@ case CONTRACT_DATA: Hash contractID; SCVal key; } contractData; +case CONTRACT_CODE: + struct + { + Hash hash; + } contractCode; case CONFIG_SETTING: struct { @@ -645,6 +660,7 @@ enum EnvelopeType ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8, ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, - ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11 + ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11, + ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12 }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index cdf108b..ba291db 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -474,23 +474,66 @@ struct LiquidityPoolWithdrawOp int64 minAmountB; // minimum amount of second asset to withdraw }; -enum HostFunction +enum HostFunctionType { - HOST_FN_INVOKE_CONTRACT = 0, - HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1, - HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2, - HOST_FN_CREATE_TOKEN_CONTRACT_WITH_SOURCE_ACCOUNT = 3, - HOST_FN_CREATE_TOKEN_CONTRACT_WITH_ASSET = 4 + HOST_FUNCTION_TYPE_INVOKE_CONTRACT = 0, + HOST_FUNCTION_TYPE_CREATE_CONTRACT = 1, + HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE = 2 +}; + +enum ContractIDType +{ + CONTRACT_ID_FROM_SOURCE_ACCOUNT = 0, + CONTRACT_ID_FROM_ED25519_PUBLIC_KEY = 1, + CONTRACT_ID_FROM_ASSET = 2 +}; + +enum ContractIDPublicKeyType +{ + CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT = 0, + CONTRACT_ID_PUBLIC_KEY_ED25519 = 1 +}; + +struct InstallContractCodeArgs +{ + opaque code; +}; + +union ContractID switch (ContractIDType type) +{ +case CONTRACT_ID_FROM_SOURCE_ACCOUNT: + uint256 salt; +case CONTRACT_ID_FROM_ED25519_PUBLIC_KEY: + struct + { + uint256 key; + Signature signature; + uint256 salt; + } fromEd25519PublicKey; +case CONTRACT_ID_FROM_ASSET: + Asset asset; +}; + +struct CreateContractArgs +{ + ContractID contractID; + SCContractCode source; +}; + +union HostFunction switch (HostFunctionType type) +{ +case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: + SCVec invokeArgs; +case HOST_FUNCTION_TYPE_CREATE_CONTRACT: + CreateContractArgs createContractArgs; +case HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE: + InstallContractCodeArgs installContractCodeArgs; }; struct InvokeHostFunctionOp { // The host function to invoke HostFunction function; - - // Parameters to the host function - SCVec parameters; - // The footprint for this invocation LedgerFootprint footprint; }; @@ -580,23 +623,37 @@ case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: case ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: struct { + Hash networkID; uint256 ed25519; uint256 salt; } ed25519ContractID; case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: struct { + Hash networkID; Hash contractID; uint256 salt; } contractID; case ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: - Asset fromAsset; + struct + { + Hash networkID; + Asset asset; + } fromAsset; case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: struct { + Hash networkID; AccountID sourceAccount; uint256 salt; } sourceAccountContractID; +case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: + struct + { + Hash networkID; + SCContractCode source; + uint256 salt; + } createContractArgs; }; enum MemoType From 4a5b25085bbc65550965119cf4d66c77b60b79b2 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sun, 20 Nov 2022 15:20:25 -0800 Subject: [PATCH 043/112] Replace BigInt object with {iu}128 (#57) --- .github/workflows/check.yml | 6 +++--- Stellar-contract.x | 39 ++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3ed265c..99fb6f0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,11 +4,11 @@ name: CI # Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "main" branch + # Triggers the workflow on push or pull request events for main, curr or next. push: - branches: [ "main" ] + branches: [ "main", "curr", "next" ] pull_request: - branches: [ "main" ] + branches: [ "main", "curr", "next" ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/Stellar-contract.x b/Stellar-contract.x index d7f34b4..4dadc99 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -213,10 +213,11 @@ enum SCObjectType SCO_MAP = 1, SCO_U64 = 2, SCO_I64 = 3, - SCO_BYTES = 4, - SCO_BIG_INT = 5, - SCO_CONTRACT_CODE = 6, - SCO_ACCOUNT_ID = 7 + SCO_U128 = 4, + SCO_I128 = 5, + SCO_BYTES = 6, + SCO_CONTRACT_CODE = 7, + SCO_ACCOUNT_ID = 8 // TODO: add more }; @@ -232,22 +233,6 @@ const SCVAL_LIMIT = 256000; typedef SCVal SCVec; typedef SCMapEntry SCMap; -enum SCNumSign -{ - NEGATIVE = -1, - ZERO = 0, - POSITIVE = 1 -}; - -union SCBigInt switch (SCNumSign sign) -{ -case ZERO: - void; -case POSITIVE: -case NEGATIVE: - opaque magnitude<256000>; -}; - enum SCContractCodeType { SCCONTRACT_CODE_WASM_REF = 0, @@ -262,6 +247,14 @@ case SCCONTRACT_CODE_TOKEN: void; }; +struct Int128Parts { + // Both signed and unsigned 128-bit ints + // are transported in a pair of uint64s + // to reduce the risk of sign-extension. + uint64 lo; + uint64 hi; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -272,10 +265,12 @@ case SCO_U64: uint64 u64; case SCO_I64: int64 i64; +case SCO_U128: + Int128Parts u128; +case SCO_I128: + Int128Parts i128; case SCO_BYTES: opaque bin; -case SCO_BIG_INT: - SCBigInt bigInt; case SCO_CONTRACT_CODE: SCContractCode contractCode; case SCO_ACCOUNT_ID: From d4ac75d12b391feb014939025ab8bcde228ae292 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sun, 20 Nov 2022 16:28:41 -0800 Subject: [PATCH 044/112] Bigint to int128 cont'd -- spec changes (#58) * Migrate SC_SPEC from BIG_INT to {IU}128 --- Stellar-contract-spec.x | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 2e18755..31ce93d 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -19,14 +19,15 @@ enum SCSpecType SC_SPEC_TYPE_I32 = 2, SC_SPEC_TYPE_U64 = 3, SC_SPEC_TYPE_I64 = 4, - SC_SPEC_TYPE_BOOL = 5, - SC_SPEC_TYPE_SYMBOL = 6, - SC_SPEC_TYPE_BITSET = 7, - SC_SPEC_TYPE_STATUS = 8, - SC_SPEC_TYPE_BYTES = 9, - SC_SPEC_TYPE_BIG_INT = 10, - SC_SPEC_TYPE_INVOKER = 11, - SC_SPEC_TYPE_ACCOUNT_ID = 12, + SC_SPEC_TYPE_U128 = 5, + SC_SPEC_TYPE_I128 = 6, + SC_SPEC_TYPE_BOOL = 7, + SC_SPEC_TYPE_SYMBOL = 8, + SC_SPEC_TYPE_BITSET = 9, + SC_SPEC_TYPE_STATUS = 10, + SC_SPEC_TYPE_BYTES = 11, + SC_SPEC_TYPE_INVOKER = 12, + SC_SPEC_TYPE_ACCOUNT_ID = 13, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -88,6 +89,8 @@ union SCSpecTypeDef switch (SCSpecType type) case SC_SPEC_TYPE_VAL: case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: +case SC_SPEC_TYPE_U128: +case SC_SPEC_TYPE_I128: case SC_SPEC_TYPE_U32: case SC_SPEC_TYPE_I32: case SC_SPEC_TYPE_BOOL: @@ -95,7 +98,6 @@ case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: -case SC_SPEC_TYPE_BIG_INT: case SC_SPEC_TYPE_INVOKER: case SC_SPEC_TYPE_ACCOUNT_ID: void; From 026c9cd074bdb28ddde8ee52f2a4502d9e518a09 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 28 Nov 2022 17:08:01 +0000 Subject: [PATCH 045/112] Make events a list of lists so we can associate events with their operation (#59) * Make events a list of lists so we can associate events with their operation * Add a OperationEvents struct --- Stellar-ledger.x | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index ce4d697..eaf1e89 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -412,6 +412,11 @@ struct ContractEvent body; }; +struct OperationEvents +{ + ContractEvent events<>; +}; + struct TransactionMetaV3 { LedgerEntryChanges txChangesBefore; // tx level changes before operations @@ -419,8 +424,8 @@ struct TransactionMetaV3 OperationMeta operations<>; // meta for each operation LedgerEntryChanges txChangesAfter; // tx level changes after operations are // applied if any - ContractEvent events<>; // custom events populated by the - // contracts themselves + OperationEvents events<>; // custom events populated by the + // contracts themselves. One list per operation. TransactionResult txResult; Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), From d2acf4109bf3bb04e40a16d8cbf8b19bef989b70 Mon Sep 17 00:00:00 2001 From: mlo Date: Wed, 11 Jan 2023 14:39:16 -0800 Subject: [PATCH 046/112] Update overlay XDR (#62) --- Stellar-overlay.x | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Stellar-overlay.x b/Stellar-overlay.x index 64fd97a..8203258 100644 --- a/Stellar-overlay.x +++ b/Stellar-overlay.x @@ -127,6 +127,12 @@ enum SurveyMessageCommandType SURVEY_TOPOLOGY = 0 }; +enum SurveyMessageResponseType +{ + SURVEY_TOPOLOGY_RESPONSE_V0 = 0, + SURVEY_TOPOLOGY_RESPONSE_V1 = 1 +}; + struct SurveyRequestMessage { NodeID surveyorPeerID; @@ -181,19 +187,33 @@ struct PeerStats typedef PeerStats PeerStatList<25>; -struct TopologyResponseBody +struct TopologyResponseBodyV0 +{ + PeerStatList inboundPeers; + PeerStatList outboundPeers; + + uint32 totalInboundPeerCount; + uint32 totalOutboundPeerCount; +}; + +struct TopologyResponseBodyV1 { PeerStatList inboundPeers; PeerStatList outboundPeers; uint32 totalInboundPeerCount; uint32 totalOutboundPeerCount; + + uint32 maxInboundPeerCount; + uint32 maxOutboundPeerCount; }; -union SurveyResponseBody switch (SurveyMessageCommandType type) +union SurveyResponseBody switch (SurveyMessageResponseType type) { -case SURVEY_TOPOLOGY: - TopologyResponseBody topologyResponseBody; +case SURVEY_TOPOLOGY_RESPONSE_V0: + TopologyResponseBodyV0 topologyResponseBodyV0; +case SURVEY_TOPOLOGY_RESPONSE_V1: + TopologyResponseBodyV1 topologyResponseBodyV1; }; const TX_ADVERT_VECTOR_MAX_SIZE = 1000; From 24d5d5f196d2840f57384383c4c10546d9fe5d48 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Tue, 31 Jan 2023 15:47:09 -0500 Subject: [PATCH 047/112] XDR changes for Auth Next. (#65) - Introduce the `ScAddress` type to generically represent the address in contracts - Introduce structured authorization data and structured signature payload to use for auth in contracts --- Stellar-contract-spec.x | 5 ++--- Stellar-contract.x | 23 ++++++++++++++++++++--- Stellar-ledger-entries.x | 3 ++- Stellar-transaction.x | 32 +++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 31ce93d..6c5a574 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -27,7 +27,7 @@ enum SCSpecType SC_SPEC_TYPE_STATUS = 10, SC_SPEC_TYPE_BYTES = 11, SC_SPEC_TYPE_INVOKER = 12, - SC_SPEC_TYPE_ACCOUNT_ID = 13, + SC_SPEC_TYPE_ADDRESS = 13, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -98,8 +98,7 @@ case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: -case SC_SPEC_TYPE_INVOKER: -case SC_SPEC_TYPE_ACCOUNT_ID: +case SC_SPEC_TYPE_ADDRESS: void; case SC_SPEC_TYPE_OPTION: SCSpecTypeOption option; diff --git a/Stellar-contract.x b/Stellar-contract.x index 4dadc99..2921c93 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -217,7 +217,8 @@ enum SCObjectType SCO_I128 = 5, SCO_BYTES = 6, SCO_CONTRACT_CODE = 7, - SCO_ACCOUNT_ID = 8 + SCO_ADDRESS = 8, + SCO_NONCE_KEY = 9 // TODO: add more }; @@ -255,6 +256,20 @@ struct Int128Parts { uint64 hi; }; +enum SCAddressType +{ + SC_ADDRESS_TYPE_ACCOUNT = 0, + SC_ADDRESS_TYPE_CONTRACT = 1 +}; + +union SCAddress switch (SCAddressType type) +{ +case SC_ADDRESS_TYPE_ACCOUNT: + AccountID accountId; +case SC_ADDRESS_TYPE_CONTRACT: + Hash contractId; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -273,7 +288,9 @@ case SCO_BYTES: opaque bin; case SCO_CONTRACT_CODE: SCContractCode contractCode; -case SCO_ACCOUNT_ID: - AccountID accountID; +case SCO_ADDRESS: + SCAddress address; +case SCO_NONCE_KEY: + SCAddress nonceAddress; }; } diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 2616d2c..55bdfe8 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -661,6 +661,7 @@ enum EnvelopeType ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11, - ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12 + ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12, + ENVELOPE_TYPE_CONTRACT_AUTH = 13 }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index ba291db..9035c70 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -530,12 +530,36 @@ case HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE: InstallContractCodeArgs installContractCodeArgs; }; +struct AuthorizedInvocation +{ + Hash contractID; + SCSymbol functionName; + SCVec args; + AuthorizedInvocation subInvocations<>; +}; + +struct AddressWithNonce +{ + SCAddress address; + uint64 nonce; +}; + +struct ContractAuth +{ + AddressWithNonce* addressWithNonce; // not present for invoker + AuthorizedInvocation rootInvocation; + SCVec signatureArgs; +}; + struct InvokeHostFunctionOp { // The host function to invoke HostFunction function; // The footprint for this invocation LedgerFootprint footprint; + // Per-address authorizations for this host fn + // Currently only supported for INVOKE_CONTRACT function + ContractAuth auth<>; }; /* An operation is the lowest unit of work that a transaction does */ @@ -653,7 +677,13 @@ case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: Hash networkID; SCContractCode source; uint256 salt; - } createContractArgs; + } createContractArgs; +case ENVELOPE_TYPE_CONTRACT_AUTH: + struct + { + Hash networkID; + AuthorizedInvocation invocation; + } contractAuth; }; enum MemoType From 54435eafc25611fa0ed8d057fecd9c51d23d6560 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 2 Feb 2023 12:06:16 -0800 Subject: [PATCH 048/112] Add fields for docs to the contract spec (#66) --- Stellar-contract-spec.x | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 6c5a574..56c3adf 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -10,6 +10,8 @@ namespace stellar { +const SC_SPEC_DOC_LIMIT = 1024; + enum SCSpecType { SC_SPEC_TYPE_VAL = 0, @@ -120,12 +122,14 @@ case SC_SPEC_TYPE_UDT: struct SCSpecUDTStructFieldV0 { + string doc; string name<30>; SCSpecTypeDef type; }; struct SCSpecUDTStructV0 { + string doc; string lib<80>; string name<60>; SCSpecUDTStructFieldV0 fields<40>; @@ -133,12 +137,14 @@ struct SCSpecUDTStructV0 struct SCSpecUDTUnionCaseV0 { + string doc; string name<60>; SCSpecTypeDef *type; }; struct SCSpecUDTUnionV0 { + string doc; string lib<80>; string name<60>; SCSpecUDTUnionCaseV0 cases<50>; @@ -146,12 +152,14 @@ struct SCSpecUDTUnionV0 struct SCSpecUDTEnumCaseV0 { + string doc; string name<60>; uint32 value; }; struct SCSpecUDTEnumV0 { + string doc; string lib<80>; string name<60>; SCSpecUDTEnumCaseV0 cases<50>; @@ -159,12 +167,14 @@ struct SCSpecUDTEnumV0 struct SCSpecUDTErrorEnumCaseV0 { + string doc; string name<60>; uint32 value; }; struct SCSpecUDTErrorEnumV0 { + string doc; string lib<80>; string name<60>; SCSpecUDTErrorEnumCaseV0 cases<50>; @@ -172,12 +182,14 @@ struct SCSpecUDTErrorEnumV0 struct SCSpecFunctionInputV0 { + string doc; string name<30>; SCSpecTypeDef type; }; struct SCSpecFunctionV0 { + string doc; SCSymbol name; SCSpecFunctionInputV0 inputs<10>; SCSpecTypeDef outputs<1>; From 840518967c99f99ac43f827e6aa0d8262f3037ed Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:06:57 -0800 Subject: [PATCH 049/112] Make unit/void case explicit and support more tuples in union spec (#67) * Make unit/void case explicit and support more tuples in union spec * avoid void --- Stellar-contract-spec.x | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 56c3adf..468146a 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -135,11 +135,31 @@ struct SCSpecUDTStructV0 SCSpecUDTStructFieldV0 fields<40>; }; -struct SCSpecUDTUnionCaseV0 +struct SCSpecUDTUnionCaseVoidV0 { string doc; string name<60>; - SCSpecTypeDef *type; +}; + +struct SCSpecUDTUnionCaseTupleV0 +{ + string doc; + string name<60>; + SCSpecTypeDef type<12>; +}; + +enum SCSpecUDTUnionCaseV0Kind +{ + SC_SPEC_UDT_UNION_CASE_VOID_V0 = 0, + SC_SPEC_UDT_UNION_CASE_TUPLE_V0 = 1, +}; + +union SCSpecUDTUnionCaseV0 switch (SCSpecUDTUnionCaseV0Kind kind) +{ +case SC_SPEC_UDT_UNION_CASE_VOID_V0: + SCSpecUDTUnionCaseVoidV0 voidCase; +case SC_SPEC_UDT_UNION_CASE_TUPLE_V0: + SCSpecUDTUnionCaseTupleV0 tupleCase; }; struct SCSpecUDTUnionV0 From 700c7f0701eda6161b62a4d1c4cf8cbfe7350fb3 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:24:14 -0800 Subject: [PATCH 050/112] Fix syntax (#68) --- Stellar-contract-spec.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 468146a..47647a1 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -151,7 +151,7 @@ struct SCSpecUDTUnionCaseTupleV0 enum SCSpecUDTUnionCaseV0Kind { SC_SPEC_UDT_UNION_CASE_VOID_V0 = 0, - SC_SPEC_UDT_UNION_CASE_TUPLE_V0 = 1, + SC_SPEC_UDT_UNION_CASE_TUPLE_V0 = 1 }; union SCSpecUDTUnionCaseV0 switch (SCSpecUDTUnionCaseV0Kind kind) From dc23adf60e095a6ce626b2b09128e58a5eae0cd0 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 6 Feb 2023 14:00:54 -0800 Subject: [PATCH 051/112] Add auth errors (#69) * Add auth errors * fixup! Add auth errors --- Stellar-contract.x | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 2921c93..6a0bc7a 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -78,7 +78,8 @@ enum SCStatusType SST_HOST_STORAGE_ERROR = 5, SST_HOST_CONTEXT_ERROR = 6, SST_VM_ERROR = 7, - SST_CONTRACT_ERROR = 8 + SST_CONTRACT_ERROR = 8, + SST_HOST_AUTH_ERROR = 9 // TODO: add more }; @@ -128,6 +129,14 @@ enum SCHostStorageErrorCode HOST_STORAGE_GET_ON_DELETED_KEY = 5 }; +enum SCHostAuthErrorCode +{ + HOST_AUTH_UNKNOWN_ERROR = 0, + HOST_AUTH_NONCE_ERROR = 1, + HOST_AUTH_DUPLICATE_AUTHORIZATION = 2, + HOST_AUTH_NOT_AUTHORIZED = 3 +}; + enum SCHostContextErrorCode { HOST_CONTEXT_UNKNOWN_ERROR = 0, @@ -182,6 +191,8 @@ case SST_VM_ERROR: SCVmErrorCode vmCode; case SST_CONTRACT_ERROR: uint32 contractCode; +case SST_HOST_AUTH_ERROR: + SCHostAuthErrorCode authCode; }; union SCVal switch (SCValType type) From df18148747e807618acf4639db41c4fd6f0be9fc Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Tue, 14 Feb 2023 11:08:56 -0500 Subject: [PATCH 052/112] Add nonce to the signature payload (#71) --- Stellar-transaction.x | 1 + 1 file changed, 1 insertion(+) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 9035c70..3c98faa 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -682,6 +682,7 @@ case ENVELOPE_TYPE_CONTRACT_AUTH: struct { Hash networkID; + uint64 nonce; AuthorizedInvocation invocation; } contractAuth; }; From 32718f0a958d0ba3172af10fc8a55a5b551398b0 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 8 Mar 2023 12:57:45 -0800 Subject: [PATCH 053/112] Preliminary "remove objects from XDR" change (#70) --- Stellar-contract-spec.x | 47 ++++--- Stellar-contract.x | 285 +++++++++++++++++++++------------------ Stellar-ledger-entries.x | 2 - Stellar-transaction.x | 4 +- Stellar-types.x | 3 + 5 files changed, 184 insertions(+), 157 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 47647a1..8431e22 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -17,19 +17,23 @@ enum SCSpecType SC_SPEC_TYPE_VAL = 0, // Types with no parameters. - SC_SPEC_TYPE_U32 = 1, - SC_SPEC_TYPE_I32 = 2, - SC_SPEC_TYPE_U64 = 3, - SC_SPEC_TYPE_I64 = 4, - SC_SPEC_TYPE_U128 = 5, - SC_SPEC_TYPE_I128 = 6, - SC_SPEC_TYPE_BOOL = 7, - SC_SPEC_TYPE_SYMBOL = 8, - SC_SPEC_TYPE_BITSET = 9, - SC_SPEC_TYPE_STATUS = 10, - SC_SPEC_TYPE_BYTES = 11, - SC_SPEC_TYPE_INVOKER = 12, - SC_SPEC_TYPE_ADDRESS = 13, + SC_SPEC_TYPE_BOOL = 1, + SC_SPEC_TYPE_VOID = 2, + SC_SPEC_TYPE_STATUS = 3, + SC_SPEC_TYPE_U32 = 4, + SC_SPEC_TYPE_I32 = 5, + SC_SPEC_TYPE_U64 = 6, + SC_SPEC_TYPE_I64 = 7, + SC_SPEC_TYPE_TIMEPOINT = 8, + SC_SPEC_TYPE_DURATION = 9, + SC_SPEC_TYPE_U128 = 10, + SC_SPEC_TYPE_I128 = 11, + SC_SPEC_TYPE_U256 = 12, + SC_SPEC_TYPE_I256 = 13, + SC_SPEC_TYPE_BYTES = 14, + SC_SPEC_TYPE_STRING = 16, + SC_SPEC_TYPE_SYMBOL = 17, + SC_SPEC_TYPE_ADDRESS = 19, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -89,17 +93,22 @@ struct SCSpecTypeUDT union SCSpecTypeDef switch (SCSpecType type) { case SC_SPEC_TYPE_VAL: +case SC_SPEC_TYPE_BOOL: +case SC_SPEC_TYPE_VOID: +case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_U32: +case SC_SPEC_TYPE_I32: case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: +case SC_SPEC_TYPE_TIMEPOINT: +case SC_SPEC_TYPE_DURATION: case SC_SPEC_TYPE_U128: case SC_SPEC_TYPE_I128: -case SC_SPEC_TYPE_U32: -case SC_SPEC_TYPE_I32: -case SC_SPEC_TYPE_BOOL: -case SC_SPEC_TYPE_SYMBOL: -case SC_SPEC_TYPE_BITSET: -case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_U256: +case SC_SPEC_TYPE_I256: case SC_SPEC_TYPE_BYTES: +case SC_SPEC_TYPE_STRING: +case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_ADDRESS: void; case SC_SPEC_TYPE_OPTION: diff --git a/Stellar-contract.x b/Stellar-contract.x index 6a0bc7a..66040e2 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -5,67 +5,73 @@ % #include "xdr/Stellar-types.h" namespace stellar { -/* - * Smart Contracts deal in SCVals. These are a (dynamic) disjoint union - * between several possible variants, to allow storing generic SCVals in - * generic data structures and passing them in and out of languages that - * have simple or dynamic type systems. - * - * SCVals are (in WASM's case) stored in a tagged 64-bit word encoding. Most - * signed 64-bit values in Stellar are actually signed positive values - * (sequence numbers, timestamps, amounts), so we don't need the high bit - * and can get away with 1-bit tagging and store them as "unsigned 63bit", - * (u63) separate from everything else. - * - * We actually reserve the low _four_ bits, leaving 3 bits for 8 cases of - * "non-u63 values", some of which have substructure of their own. - * - * 0x_NNNN_NNNN_NNNN_NNNX - u63, for any even X - * 0x_0000_000N_NNNN_NNN1 - u32 - * 0x_0000_000N_NNNN_NNN3 - i32 - * 0x_NNNN_NNNN_NNNN_NNN5 - static: void, true, false, ... (SCS_*) - * 0x_IIII_IIII_TTTT_TTT7 - object: 32-bit index I, 28-bit type code T - * 0x_NNNN_NNNN_NNNN_NNN9 - symbol: up to 10 6-bit identifier characters - * 0x_NNNN_NNNN_NNNN_NNNb - bitset: up to 60 bits - * 0x_CCCC_CCCC_TTTT_TTTd - status: 32-bit code C, 28-bit type code T - * 0x_NNNN_NNNN_NNNN_NNNf - reserved - * - * Up here in XDR we have variable-length tagged disjoint unions but no - * bit-level packing, so we can be more explicit in their structure, at the - * cost of spending more than 64 bits to encode many cases, and also having - * to convert. It's a little non-obvious at the XDR level why there's a - * split between SCVal and SCObject given that they are both immutable types - * with value semantics; but the split reflects the split that happens in - * the implementation, and marks a place where different implementations of - * immutability (CoW, structural sharing, etc.) will likely occur. - */ - -// A symbol is up to 10 chars drawn from [a-zA-Z0-9_], which can be packed -// into 60 bits with a 6-bit-per-character code, usable as a small key type -// to specify function, argument, tx-local environment and map entries -// efficiently. -typedef string SCSymbol<10>; + +// We fix a maximum of 128 value types in the system for two reasons: we want to +// keep the codes relatively small (<= 8 bits) when bit-packing values into a +// u64 at the environment interface level, so that we keep many bits for +// payloads (small strings, small numeric values, object handles); and then we +// actually want to go one step further and ensure (for code-size) that our +// codes fit in a single ULEB128-code byte, which means we can only use 7 bits. +// +// We also reserve several type codes from this space because we want to _reuse_ +// the SCValType codes at the environment interface level (or at least not +// exceed its number-space) but there are more types at that level, assigned to +// optimizations/special case representations of values abstract at this level. enum SCValType { - SCV_U63 = 0, - SCV_U32 = 1, - SCV_I32 = 2, - SCV_STATIC = 3, - SCV_OBJECT = 4, - SCV_SYMBOL = 5, - SCV_BITSET = 6, - SCV_STATUS = 7 -}; + SCV_BOOL = 0, + SCV_VOID = 1, + SCV_STATUS = 2, -% struct SCObject; + // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. + SCV_U32 = 3, + SCV_I32 = 4, -enum SCStatic -{ - SCS_VOID = 0, - SCS_TRUE = 1, - SCS_FALSE = 2, - SCS_LEDGER_KEY_CONTRACT_CODE = 3 + // 64 bits is naturally supported by both WASM and XDR also. + SCV_U64 = 5, + SCV_I64 = 6, + + // Time-related u64 subtypes with their own functions and formatting. + SCV_TIMEPOINT = 7, + SCV_DURATION = 8, + + // 128 bits is naturally supported by Rust and we use it for Soroban + // fixed-point arithmetic prices / balances / similar "quantities". These + // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is + // represented as an array of 32 bytes. + SCV_U128 = 9, + SCV_I128 = 10, + + // 256 bits is the size of sha256 output, ed25519 keys, and the EVM machine + // word, so for interop use we include this even though it requires a small + // amount of Rust guest and/or host library code. + SCV_U256 = 11, + SCV_I256 = 12, + + // TODO: possibly allocate subtypes of i64, i128 and/or u256 for + // fixed-precision with a specific number of decimals. + + // Bytes come in 3 flavors, 2 of which have meaningfully different + // formatting and validity-checking / domain-restriction. + SCV_BYTES = 13, + SCV_STRING = 14, + SCV_SYMBOL = 15, + + // Vecs and maps are just polymorphic containers of other ScVals. + SCV_VEC = 16, + SCV_MAP = 17, + + // SCContractExecutable and SCAddressType are types that gets used separately from + // SCVal so we do not flatten their structures into separate SCVal cases. + SCV_CONTRACT_EXECUTABLE = 18, + SCV_ADDRESS = 19, + + // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique + // symbolic SCVals used as the key for ledger entries for a contract's code + // and an address' nonce, respectively. + SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, + SCV_LEDGER_KEY_NONCE = 21 }; enum SCStatusType @@ -195,78 +201,28 @@ case SST_HOST_AUTH_ERROR: SCHostAuthErrorCode authCode; }; -union SCVal switch (SCValType type) -{ -case SCV_U63: - int64 u63; -case SCV_U32: - uint32 u32; -case SCV_I32: - int32 i32; -case SCV_STATIC: - SCStatic ic; -case SCV_OBJECT: - SCObject* obj; -case SCV_SYMBOL: - SCSymbol sym; -case SCV_BITSET: - uint64 bits; -case SCV_STATUS: - SCStatus status; -}; - -enum SCObjectType -{ - // We have a few objects that represent non-stellar-specific concepts - // like general-purpose maps, vectors, numbers, blobs. - - SCO_VEC = 0, - SCO_MAP = 1, - SCO_U64 = 2, - SCO_I64 = 3, - SCO_U128 = 4, - SCO_I128 = 5, - SCO_BYTES = 6, - SCO_CONTRACT_CODE = 7, - SCO_ADDRESS = 8, - SCO_NONCE_KEY = 9 - - // TODO: add more -}; - -struct SCMapEntry -{ - SCVal key; - SCVal val; +struct Int128Parts { + // Both signed and unsigned 128-bit ints + // are transported in a pair of uint64s + // to reduce the risk of sign-extension. + uint64 lo; + uint64 hi; }; -const SCVAL_LIMIT = 256000; - -typedef SCVal SCVec; -typedef SCMapEntry SCMap; - -enum SCContractCodeType +enum SCContractExecutableType { - SCCONTRACT_CODE_WASM_REF = 0, - SCCONTRACT_CODE_TOKEN = 1 + SCCONTRACT_EXECUTABLE_WASM_REF = 0, + SCCONTRACT_EXECUTABLE_TOKEN = 1 }; -union SCContractCode switch (SCContractCodeType type) +union SCContractExecutable switch (SCContractExecutableType type) { -case SCCONTRACT_CODE_WASM_REF: +case SCCONTRACT_EXECUTABLE_WASM_REF: Hash wasm_id; -case SCCONTRACT_CODE_TOKEN: +case SCCONTRACT_EXECUTABLE_TOKEN: void; }; -struct Int128Parts { - // Both signed and unsigned 128-bit ints - // are transported in a pair of uint64s - // to reduce the risk of sign-extension. - uint64 lo; - uint64 hi; -}; - enum SCAddressType { SC_ADDRESS_TYPE_ACCOUNT = 0, @@ -281,27 +237,88 @@ case SC_ADDRESS_TYPE_CONTRACT: Hash contractId; }; -union SCObject switch (SCObjectType type) +%struct SCVal; +%struct SCMapEntry; + +const SCVAL_LIMIT = 256000; +const SCSYMBOL_LIMIT = 32; + +typedef SCVal SCVec; +typedef SCMapEntry SCMap; + +typedef opaque SCBytes; +typedef string SCString; +typedef string SCSymbol; + +struct SCNonceKey { + SCAddress nonce_address; +}; + +union SCVal switch (SCValType type) { -case SCO_VEC: - SCVec vec; -case SCO_MAP: - SCMap map; -case SCO_U64: + +case SCV_BOOL: + bool b; +case SCV_VOID: + void; +case SCV_STATUS: + SCStatus error; + +case SCV_U32: + uint32 u32; +case SCV_I32: + int32 i32; + +case SCV_U64: uint64 u64; -case SCO_I64: +case SCV_I64: int64 i64; -case SCO_U128: +case SCV_TIMEPOINT: + TimePoint timepoint; +case SCV_DURATION: + Duration duration; + +case SCV_U128: Int128Parts u128; -case SCO_I128: +case SCV_I128: Int128Parts i128; -case SCO_BYTES: - opaque bin; -case SCO_CONTRACT_CODE: - SCContractCode contractCode; -case SCO_ADDRESS: + +case SCV_U256: + uint256 u256; +case SCV_I256: + uint256 i256; + +case SCV_BYTES: + SCBytes bytes; +case SCV_STRING: + SCString str; +case SCV_SYMBOL: + SCSymbol sym; + +// Vec and Map are recursive so need to live +// behind an option, due to xdrpp limitations. +case SCV_VEC: + SCVec *vec; +case SCV_MAP: + SCMap *map; + +case SCV_CONTRACT_EXECUTABLE: + SCContractExecutable exec; +case SCV_ADDRESS: SCAddress address; -case SCO_NONCE_KEY: - SCAddress nonceAddress; + +// Special SCVals reserved for system-constructed contract-data +// ledger keys, not generally usable elsewhere. +case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: + void; +case SCV_LEDGER_KEY_NONCE: + SCNonceKey nonce_key; +}; + +struct SCMapEntry +{ + SCVal key; + SCVal val; }; + } diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 55bdfe8..d8f1b73 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -12,8 +12,6 @@ typedef opaque Thresholds[4]; typedef string string32<32>; typedef string string64<64>; typedef int64 SequenceNumber; -typedef uint64 TimePoint; -typedef uint64 Duration; typedef opaque DataValue<64>; typedef Hash PoolID; // SHA256(LiquidityPoolParameters) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 3c98faa..2b0b058 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -517,7 +517,7 @@ case CONTRACT_ID_FROM_ASSET: struct CreateContractArgs { ContractID contractID; - SCContractCode source; + SCContractExecutable source; }; union HostFunction switch (HostFunctionType type) @@ -675,7 +675,7 @@ case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: struct { Hash networkID; - SCContractCode source; + SCContractExecutable source; uint256 salt; } createContractArgs; case ENVELOPE_TYPE_CONTRACT_AUTH: diff --git a/Stellar-types.x b/Stellar-types.x index a6f9bf9..d71bf0d 100644 --- a/Stellar-types.x +++ b/Stellar-types.x @@ -14,6 +14,9 @@ typedef int int32; typedef unsigned hyper uint64; typedef hyper int64; +typedef uint64 TimePoint; +typedef uint64 Duration; + // An ExtensionPoint is always marshaled as a 32-bit 0 value. At a // later point, it can be replaced by a different union so as to // extend a structure. From 7356dc237ee0db5626561c129fb3fa4beaabbac6 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 13 Mar 2023 17:02:12 -0700 Subject: [PATCH 054/112] Add diagnosticEvents (#74) --- Stellar-ledger.x | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index eaf1e89..1563fb9 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -388,7 +388,8 @@ struct TransactionMetaV2 enum ContractEventType { SYSTEM = 0, - CONTRACT = 1 + CONTRACT = 1, + DIAGNOSTIC = 2 }; struct ContractEvent @@ -412,6 +413,17 @@ struct ContractEvent body; }; +struct DiagnosticEvent +{ + bool inSuccessfulContractCall; + ContractEvent event; +}; + +struct OperationDiagnosticEvents +{ + DiagnosticEvent events<>; +}; + struct OperationEvents { ContractEvent events<>; @@ -430,6 +442,11 @@ struct TransactionMetaV3 Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), // sha256(events), and sha256(txResult) + + // Diagnostics events that are not hashed. One list per operation. + // This will contain all contract and diagnostic events. Even ones + // that were emitted in a failed contract call. + OperationDiagnosticEvents diagnosticEvents<>; }; // this is the meta produced when applying transactions From eab1622f18b8101aa0cea76361c08beaeaa8d715 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 29 Mar 2023 17:03:59 -0700 Subject: [PATCH 055/112] XDR for upgradeable config entries (#75) * Generalize configuration-related XDR. The changes here are summarized in proposed updated to CAP-47 (https://github.com/stellar/stellar-protocol/pull/1291). - Use unique keys to identify settings - Only distribute a hash for config upgrades in `StellarValue` - Add SCP messages for exchanging config upgrade sets * Remove unused ConfigSetting --------- Co-authored-by: Dmytro Kozhevin --- Stellar-ledger-entries.x | 26 ++++---------------------- Stellar-ledger.x | 15 ++++++++++----- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index d8f1b73..f1547d9 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -505,33 +505,15 @@ struct ContractCodeEntry { opaque code; }; -enum ConfigSettingType -{ - CONFIG_SETTING_TYPE_UINT32 = 0 -}; - -union ConfigSetting switch (ConfigSettingType type) -{ -case CONFIG_SETTING_TYPE_UINT32: - uint32 uint32Val; -}; - enum ConfigSettingID { - CONFIG_SETTING_CONTRACT_MAX_SIZE = 0 + CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0 }; -struct ConfigSettingEntry +union ConfigSettingEntry switch (ConfigSettingID configSettingID) { - union switch (int v) - { - case 0: - void; - } - ext; - - ConfigSettingID configSettingID; - ConfigSetting setting; +case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES: + uint32 contractMaxSizeBytes; }; struct LedgerEntryExtensionV1 diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 1563fb9..79d3d45 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -130,6 +130,11 @@ enum LedgerUpgradeType LEDGER_UPGRADE_CONFIG = 6 }; +struct ConfigUpgradeSetKey { + Hash contractID; + Hash contentHash; +}; + union LedgerUpgrade switch (LedgerUpgradeType type) { case LEDGER_UPGRADE_VERSION: @@ -143,11 +148,11 @@ case LEDGER_UPGRADE_BASE_RESERVE: case LEDGER_UPGRADE_FLAGS: uint32 newFlags; // update flags case LEDGER_UPGRADE_CONFIG: - struct - { - ConfigSettingID id; // id to update - ConfigSetting setting; // new value - } configSetting; + ConfigUpgradeSetKey newConfig; +}; + +struct ConfigUpgradeSet { + ConfigSettingEntry updatedEntry<>; }; /* Entries used to define the bucket list */ From e71dd43da237d63b98a0f6c431311505daf23308 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Mon, 10 Apr 2023 23:24:54 -0400 Subject: [PATCH 056/112] Fix U/I128 and U/I256 number representation for consistent sorting (#78) * Fix 128 and 256 bits number representation * fixup! Fix 128 and 256 bits number representation --- Stellar-contract.x | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 66040e2..6084cdb 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -201,12 +201,36 @@ case SST_HOST_AUTH_ERROR: SCHostAuthErrorCode authCode; }; +struct UInt128Parts { + uint64 hi; + uint64 lo; +}; + +// A signed int128 has a high sign bit and 127 value bits. We break it into a +// signed high int64 (that carries the sign bit and the high 63 value bits) and +// a low unsigned uint64 that carries the low 64 bits. This will sort in +// generated code in the same order the underlying int128 sorts. struct Int128Parts { - // Both signed and unsigned 128-bit ints - // are transported in a pair of uint64s - // to reduce the risk of sign-extension. + int64 hi; uint64 lo; - uint64 hi; +}; + +struct UInt256Parts { + uint64 hi_hi; + uint64 hi_lo; + uint64 lo_hi; + uint64 lo_lo; +}; + +// A signed int256 has a high sign bit and 255 value bits. We break it into a +// signed high int64 (that carries the sign bit and the high 63 value bits) and +// three low unsigned `uint64`s that carry the lower bits. This will sort in +// generated code in the same order the underlying int256 sorts. +struct Int256Parts { + int64 hi_hi; + uint64 hi_lo; + uint64 lo_hi; + uint64 lo_lo; }; enum SCContractExecutableType @@ -279,14 +303,14 @@ case SCV_DURATION: Duration duration; case SCV_U128: - Int128Parts u128; + UInt128Parts u128; case SCV_I128: Int128Parts i128; case SCV_U256: - uint256 u256; + UInt256Parts u256; case SCV_I256: - uint256 i256; + Int256Parts i256; case SCV_BYTES: SCBytes bytes; From c9c50a4e728f27a413dfaa9cf3a66654c635d78a Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Mon, 10 Apr 2023 23:31:17 -0400 Subject: [PATCH 057/112] Add fee and limit-related configuration XDR based on CAP-0046-07. (#79) Co-authored-by: Graydon Hoare --- Stellar-ledger-entries.x | 99 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index f1547d9..853573a 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -505,15 +505,112 @@ struct ContractCodeEntry { opaque code; }; +// Identifiers of all the network settings. enum ConfigSettingID { - CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0 + CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0, + CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, + CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, + CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, + CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, + CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5 +}; + +// "Compute" settings for contracts (instructions and memory). +struct ConfigSettingContractComputeV0 +{ + // Maximum instructions per ledger + int64 ledgerMaxInstructions; + // Maximum instructions per transaction + int64 txMaxInstructions; + // Cost of 10000 instructions + int64 feeRatePerInstructionsIncrement; + + // Memory limit per contract/host function invocation. Unlike + // instructions, there is no fee for memory and it's not + // accumulated between operations - the same limit is applied + // to every operation. + uint32 memoryLimit; +}; + +// Ledger access settings for contracts. +struct ConfigSettingContractLedgerCostV0 +{ + // Maximum number of ledger entry read operations per ledger + uint32 ledgerMaxReadLedgerEntries; + // Maximum number of bytes that can be read per ledger + uint32 ledgerMaxReadBytes; + // Maximum number of ledger entry write operations per ledger + uint32 ledgerMaxWriteLedgerEntries; + // Maximum number of bytes that can be written per ledger + uint32 ledgerMaxWriteBytes; + + // Maximum number of ledger entry read operations per transaction + uint32 txMaxReadLedgerEntries; + // Maximum number of bytes that can be read per transaction + uint32 txMaxReadBytes; + // Maximum number of ledger entry write operations per transaction + uint32 txMaxWriteLedgerEntries; + // Maximum number of bytes that can be written per transaction + uint32 txMaxWriteBytes; + + int64 feeReadLedgerEntry; // Fee per ledger entry read + int64 feeWriteLedgerEntry; // Fee per ledger entry write + + int64 feeRead1KB; // Fee for reading 1KB + int64 feeWrite1KB; // Fee for writing 1KB + + // Bucket list fees grow slowly up to that size + int64 bucketListSizeBytes; + // Fee rate in stroops when the bucket list is empty + int64 bucketListFeeRateLow; + // Fee rate in stroops when the bucket list reached bucketListSizeBytes + int64 bucketListFeeRateHigh; + // Rate multiplier for any additional data past the first bucketListSizeBytes + uint32 bucketListGrowthFactor; +}; + +// Historical data (pushed to core archives) settings for contracts. +struct ConfigSettingContractHistoricalDataV0 +{ + int64 feeHistorical1KB; // Fee for storing 1KB in archives +}; + +// Meta data (pushed to downstream systems) settings for contracts. +struct ConfigSettingContractMetaDataV0 +{ + // Maximum size of extended meta data produced by a transaction + uint32 txMaxExtendedMetaDataSizeBytes; + // Fee for generating 1KB of extended meta data + int64 feeExtendedMetaData1KB; +}; + +// Bandwidth related data settings for contracts +struct ConfigSettingContractBandwidthV0 +{ + // Maximum size in bytes to propagate per ledger + uint32 ledgerMaxPropagateSizeBytes; + // Maximum size in bytes for a transaction + uint32 txMaxSizeBytes; + + // Fee for propagating 1KB of data + int64 feePropagateData1KB; }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) { case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES: uint32 contractMaxSizeBytes; +case CONFIG_SETTING_CONTRACT_COMPUTE_V0: + ConfigSettingContractComputeV0 contractCompute; +case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: + ConfigSettingContractLedgerCostV0 contractLedgerCost; +case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: + ConfigSettingContractHistoricalDataV0 contractHistoricalData; +case CONFIG_SETTING_CONTRACT_META_DATA_V0: + ConfigSettingContractMetaDataV0 contractMetaData; +case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: + ConfigSettingContractBandwidthV0 contractBandwidth; }; struct LedgerEntryExtensionV1 From d01024346cc0a23e155b9cbf4dbf1780adf3890d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 11 Apr 2023 15:32:17 -0700 Subject: [PATCH 058/112] add config setting for host logic version (#80) --- Stellar-ledger-entries.x | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 853573a..5a9c5d0 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -513,7 +513,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, - CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5 + CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, + CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION = 6 }; // "Compute" settings for contracts (instructions and memory). @@ -611,6 +612,8 @@ case CONFIG_SETTING_CONTRACT_META_DATA_V0: ConfigSettingContractMetaDataV0 contractMetaData; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; +case CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION: + uint32 contractHostLogicVersion; }; struct LedgerEntryExtensionV1 From c0077436fcdfe791c20b6dcd50baa50d835d1a17 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 19 Apr 2023 14:56:55 -0500 Subject: [PATCH 059/112] Meta xdr (#82) * Add XDR types for contract meta * generic * Update Stellar-contract-meta.x Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> * Update Stellar-contract-meta.x * Update Stellar-contract-meta.x --------- Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> --- Stellar-contract-meta.x | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Stellar-contract-meta.x diff --git a/Stellar-contract-meta.x b/Stellar-contract-meta.x new file mode 100644 index 0000000..16eb5f9 --- /dev/null +++ b/Stellar-contract-meta.x @@ -0,0 +1,29 @@ +// Copyright 2022 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +// The contract meta XDR is highly experimental, incomplete, and still being +// iterated on. Breaking changes expected. + +% #include "xdr/Stellar-types.h" +namespace stellar +{ + +struct SCMetaV0 +{ + string key<>; + string val<>; +}; + +enum SCMetaKind +{ + SC_META_V0 = 0 +}; + +union SCMetaEntry switch (SCMetaKind kind) +{ +case SC_META_V0: + SCMetaV0 v0; +}; + +} From 3ee2f7353424f6b0030db5001f72d0471e621003 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Fri, 21 Apr 2023 19:11:57 -0400 Subject: [PATCH 060/112] Define config settings for contract costs (#81) * Define cost parameters * fixup! Define cost parameters * Move config settings to separate file * Remove spaces * Add stellar namespace --- Stellar-contract-config-setting.x | 179 ++++++++++++++++++++++++++++++ Stellar-ledger-entries.x | 111 +----------------- 2 files changed, 180 insertions(+), 110 deletions(-) create mode 100644 Stellar-contract-config-setting.x diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x new file mode 100644 index 0000000..a6d4b7a --- /dev/null +++ b/Stellar-contract-config-setting.x @@ -0,0 +1,179 @@ +%#include "xdr/Stellar-types.h" + +namespace stellar { +// "Compute" settings for contracts (instructions and memory). +struct ConfigSettingContractComputeV0 +{ + // Maximum instructions per ledger + int64 ledgerMaxInstructions; + // Maximum instructions per transaction + int64 txMaxInstructions; + // Cost of 10000 instructions + int64 feeRatePerInstructionsIncrement; + + // Memory limit per contract/host function invocation. Unlike + // instructions, there is no fee for memory and it's not + // accumulated between operations - the same limit is applied + // to every operation. + uint32 memoryLimit; +}; + +// Ledger access settings for contracts. +struct ConfigSettingContractLedgerCostV0 +{ + // Maximum number of ledger entry read operations per ledger + uint32 ledgerMaxReadLedgerEntries; + // Maximum number of bytes that can be read per ledger + uint32 ledgerMaxReadBytes; + // Maximum number of ledger entry write operations per ledger + uint32 ledgerMaxWriteLedgerEntries; + // Maximum number of bytes that can be written per ledger + uint32 ledgerMaxWriteBytes; + + // Maximum number of ledger entry read operations per transaction + uint32 txMaxReadLedgerEntries; + // Maximum number of bytes that can be read per transaction + uint32 txMaxReadBytes; + // Maximum number of ledger entry write operations per transaction + uint32 txMaxWriteLedgerEntries; + // Maximum number of bytes that can be written per transaction + uint32 txMaxWriteBytes; + + int64 feeReadLedgerEntry; // Fee per ledger entry read + int64 feeWriteLedgerEntry; // Fee per ledger entry write + + int64 feeRead1KB; // Fee for reading 1KB + int64 feeWrite1KB; // Fee for writing 1KB + + // Bucket list fees grow slowly up to that size + int64 bucketListSizeBytes; + // Fee rate in stroops when the bucket list is empty + int64 bucketListFeeRateLow; + // Fee rate in stroops when the bucket list reached bucketListSizeBytes + int64 bucketListFeeRateHigh; + // Rate multiplier for any additional data past the first bucketListSizeBytes + uint32 bucketListGrowthFactor; +}; + +// Historical data (pushed to core archives) settings for contracts. +struct ConfigSettingContractHistoricalDataV0 +{ + int64 feeHistorical1KB; // Fee for storing 1KB in archives +}; + +// Meta data (pushed to downstream systems) settings for contracts. +struct ConfigSettingContractMetaDataV0 +{ + // Maximum size of extended meta data produced by a transaction + uint32 txMaxExtendedMetaDataSizeBytes; + // Fee for generating 1KB of extended meta data + int64 feeExtendedMetaData1KB; +}; + +// Bandwidth related data settings for contracts +struct ConfigSettingContractBandwidthV0 +{ + // Maximum size in bytes to propagate per ledger + uint32 ledgerMaxPropagateSizeBytes; + // Maximum size in bytes for a transaction + uint32 txMaxSizeBytes; + + // Fee for propagating 1KB of data + int64 feePropagateData1KB; +}; + +enum ContractCostType { + // Cost of running 1 wasm instruction + WasmInsnExec = 0, + // Cost of growing wasm linear memory by 1 page + WasmMemAlloc = 1, + // Cost of allocating a chuck of host memory (in bytes) + HostMemAlloc = 2, + // Cost of copying a chuck of bytes into a pre-allocated host memory + HostMemCpy = 3, + // Cost of comparing two slices of host memory + HostMemCmp = 4, + // Cost of a host function invocation, not including the actual work done by the function + InvokeHostFunction = 5, + // Cost of visiting a host object from the host object storage + // Only thing to make sure is the guest can't visitObject repeatly without incurring some charges elsewhere. + VisitObject = 6, + // Tracks a single Val (RawVal or primative Object like U64) <=> ScVal + // conversion cost. Most of these Val counterparts in ScVal (except e.g. + // Symbol) consumes a single int64 and therefore is a constant overhead. + ValXdrConv = 7, + // Cost of serializing an xdr object to bytes + ValSer = 8, + // Cost of deserializing an xdr object from bytes + ValDeser = 9, + // Cost of computing the sha256 hash from bytes + ComputeSha256Hash = 10, + // Cost of computing the ed25519 pubkey from bytes + ComputeEd25519PubKey = 11, + // Cost of accessing an entry in a Map. + MapEntry = 12, + // Cost of accessing an entry in a Vec + VecEntry = 13, + // Cost of guarding a frame, which involves pushing and poping a frame and capturing a rollback point. + GuardFrame = 14, + // Cost of verifying ed25519 signature of a payload. + VerifyEd25519Sig = 15, + // Cost of reading a slice of vm linear memory + VmMemRead = 16, + // Cost of writing to a slice of vm linear memory + VmMemWrite = 17, + // Cost of instantiation a VM from wasm bytes code. + VmInstantiation = 18, + // Roundtrip cost of invoking a VM function from the host. + InvokeVmFunction = 19, + // Cost of charging a value to the budgeting system. + ChargeBudget = 20 +}; + +struct ContractCostParamEntry { + int32 constTerm; + int32 linearTerm; + // use `ext` to add more terms (e.g. higher order polynomials) in the future + ExtensionPoint ext; +}; + +const CONTRACT_COST_COUNT_LIMIT = 1024; // limits the ContractCostParams size to 12kB + +typedef ContractCostParamEntry ContractCostParams; + +// Identifiers of all the network settings. +enum ConfigSettingID +{ + CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0, + CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, + CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, + CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, + CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, + CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, + CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION = 6, + CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 7, + CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 8 +}; + +union ConfigSettingEntry switch (ConfigSettingID configSettingID) +{ +case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES: + uint32 contractMaxSizeBytes; +case CONFIG_SETTING_CONTRACT_COMPUTE_V0: + ConfigSettingContractComputeV0 contractCompute; +case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: + ConfigSettingContractLedgerCostV0 contractLedgerCost; +case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: + ConfigSettingContractHistoricalDataV0 contractHistoricalData; +case CONFIG_SETTING_CONTRACT_META_DATA_V0: + ConfigSettingContractMetaDataV0 contractMetaData; +case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: + ConfigSettingContractBandwidthV0 contractBandwidth; +case CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION: + uint32 contractHostLogicVersion; +case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: + ContractCostParams contractCostParamsCpuInsns; +case CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: + ContractCostParams contractCostParamsMemBytes; +}; +} \ No newline at end of file diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 5a9c5d0..2eca637 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -4,6 +4,7 @@ %#include "xdr/Stellar-types.h" %#include "xdr/Stellar-contract.h" +%#include "xdr/Stellar-contract-config-setting.h" namespace stellar { @@ -505,116 +506,6 @@ struct ContractCodeEntry { opaque code; }; -// Identifiers of all the network settings. -enum ConfigSettingID -{ - CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0, - CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, - CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, - CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, - CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, - CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, - CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION = 6 -}; - -// "Compute" settings for contracts (instructions and memory). -struct ConfigSettingContractComputeV0 -{ - // Maximum instructions per ledger - int64 ledgerMaxInstructions; - // Maximum instructions per transaction - int64 txMaxInstructions; - // Cost of 10000 instructions - int64 feeRatePerInstructionsIncrement; - - // Memory limit per contract/host function invocation. Unlike - // instructions, there is no fee for memory and it's not - // accumulated between operations - the same limit is applied - // to every operation. - uint32 memoryLimit; -}; - -// Ledger access settings for contracts. -struct ConfigSettingContractLedgerCostV0 -{ - // Maximum number of ledger entry read operations per ledger - uint32 ledgerMaxReadLedgerEntries; - // Maximum number of bytes that can be read per ledger - uint32 ledgerMaxReadBytes; - // Maximum number of ledger entry write operations per ledger - uint32 ledgerMaxWriteLedgerEntries; - // Maximum number of bytes that can be written per ledger - uint32 ledgerMaxWriteBytes; - - // Maximum number of ledger entry read operations per transaction - uint32 txMaxReadLedgerEntries; - // Maximum number of bytes that can be read per transaction - uint32 txMaxReadBytes; - // Maximum number of ledger entry write operations per transaction - uint32 txMaxWriteLedgerEntries; - // Maximum number of bytes that can be written per transaction - uint32 txMaxWriteBytes; - - int64 feeReadLedgerEntry; // Fee per ledger entry read - int64 feeWriteLedgerEntry; // Fee per ledger entry write - - int64 feeRead1KB; // Fee for reading 1KB - int64 feeWrite1KB; // Fee for writing 1KB - - // Bucket list fees grow slowly up to that size - int64 bucketListSizeBytes; - // Fee rate in stroops when the bucket list is empty - int64 bucketListFeeRateLow; - // Fee rate in stroops when the bucket list reached bucketListSizeBytes - int64 bucketListFeeRateHigh; - // Rate multiplier for any additional data past the first bucketListSizeBytes - uint32 bucketListGrowthFactor; -}; - -// Historical data (pushed to core archives) settings for contracts. -struct ConfigSettingContractHistoricalDataV0 -{ - int64 feeHistorical1KB; // Fee for storing 1KB in archives -}; - -// Meta data (pushed to downstream systems) settings for contracts. -struct ConfigSettingContractMetaDataV0 -{ - // Maximum size of extended meta data produced by a transaction - uint32 txMaxExtendedMetaDataSizeBytes; - // Fee for generating 1KB of extended meta data - int64 feeExtendedMetaData1KB; -}; - -// Bandwidth related data settings for contracts -struct ConfigSettingContractBandwidthV0 -{ - // Maximum size in bytes to propagate per ledger - uint32 ledgerMaxPropagateSizeBytes; - // Maximum size in bytes for a transaction - uint32 txMaxSizeBytes; - - // Fee for propagating 1KB of data - int64 feePropagateData1KB; -}; - -union ConfigSettingEntry switch (ConfigSettingID configSettingID) -{ -case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES: - uint32 contractMaxSizeBytes; -case CONFIG_SETTING_CONTRACT_COMPUTE_V0: - ConfigSettingContractComputeV0 contractCompute; -case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: - ConfigSettingContractLedgerCostV0 contractLedgerCost; -case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: - ConfigSettingContractHistoricalDataV0 contractHistoricalData; -case CONFIG_SETTING_CONTRACT_META_DATA_V0: - ConfigSettingContractMetaDataV0 contractMetaData; -case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: - ConfigSettingContractBandwidthV0 contractBandwidth; -case CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION: - uint32 contractHostLogicVersion; -}; struct LedgerEntryExtensionV1 { From b721f812a353e15db286b6e1a3c095b9be9f4bd4 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 26 Apr 2023 16:04:14 -0400 Subject: [PATCH 061/112] Transaction changes to support Soroban fee model. (#84) * Transaction changes to support Soroban fee model. - Moved all the resources (including the footprint) to the transaction level. - Added host fn batching to compensate for removal of multi-operation tx support - Did some passing-by naming cleanup (as we never really have time for that) --- Stellar-contract-config-setting.x | 8 +-- Stellar-transaction.x | 95 ++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 32 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index a6d4b7a..1c71551 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -11,11 +11,9 @@ struct ConfigSettingContractComputeV0 // Cost of 10000 instructions int64 feeRatePerInstructionsIncrement; - // Memory limit per contract/host function invocation. Unlike - // instructions, there is no fee for memory and it's not - // accumulated between operations - the same limit is applied - // to every operation. - uint32 memoryLimit; + // Memory limit per transaction. Unlike instructions, there is no fee + // for memory, just the limit. + uint32 txMemoryLimit; }; // Ledger access settings for contracts. diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 2b0b058..d4ad0d9 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -8,6 +8,9 @@ namespace stellar { +// maximum number of operations per transaction +const MAX_OPS_PER_TX = 100; + union LiquidityPoolParameters switch (LiquidityPoolType type) { case LIQUIDITY_POOL_CONSTANT_PRODUCT: @@ -33,13 +36,6 @@ struct DecoratedSignature Signature signature; // actual signature }; -// Ledger key sets touched by a smart contract transaction. -struct LedgerFootprint -{ - LedgerKey readOnly<>; - LedgerKey readWrite<>; -}; - enum OperationType { CREATE_ACCOUNT = 0, @@ -478,7 +474,7 @@ enum HostFunctionType { HOST_FUNCTION_TYPE_INVOKE_CONTRACT = 0, HOST_FUNCTION_TYPE_CREATE_CONTRACT = 1, - HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE = 2 + HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM = 2 }; enum ContractIDType @@ -494,7 +490,7 @@ enum ContractIDPublicKeyType CONTRACT_ID_PUBLIC_KEY_ED25519 = 1 }; -struct InstallContractCodeArgs +struct UploadContractWasmArgs { opaque code; }; @@ -517,17 +513,17 @@ case CONTRACT_ID_FROM_ASSET: struct CreateContractArgs { ContractID contractID; - SCContractExecutable source; + SCContractExecutable executable; }; -union HostFunction switch (HostFunctionType type) +union HostFunctionArgs switch (HostFunctionType type) { case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: - SCVec invokeArgs; + SCVec invokeContract; case HOST_FUNCTION_TYPE_CREATE_CONTRACT: - CreateContractArgs createContractArgs; -case HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE: - InstallContractCodeArgs installContractCodeArgs; + CreateContractArgs createContract; +case HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: + UploadContractWasmArgs uploadContractWasm; }; struct AuthorizedInvocation @@ -551,17 +547,24 @@ struct ContractAuth SCVec signatureArgs; }; -struct InvokeHostFunctionOp -{ - // The host function to invoke - HostFunction function; - // The footprint for this invocation - LedgerFootprint footprint; +struct HostFunction { + // Arguments of the function to call defined by the function + // type. + HostFunctionArgs args; // Per-address authorizations for this host fn // Currently only supported for INVOKE_CONTRACT function ContractAuth auth<>; }; +struct InvokeHostFunctionOp +{ + // The host functions to invoke. The functions will be executed + // in the same fashion as operations: either all functions will + // be successfully applied or all fail if at least one of them + // fails. + HostFunction functions; +}; + /* An operation is the lowest unit of work that a transaction does */ struct Operation { @@ -675,7 +678,7 @@ case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: struct { Hash networkID; - SCContractExecutable source; + SCContractExecutable executable; uint256 salt; } createContractArgs; case ENVELOPE_TYPE_CONTRACT_AUTH: @@ -772,8 +775,40 @@ case PRECOND_V2: PreconditionsV2 v2; }; -// maximum number of operations per transaction -const MAX_OPS_PER_TX = 100; +// Ledger key sets touched by a smart contract transaction. +struct LedgerFootprint +{ + LedgerKey readOnly<>; + LedgerKey readWrite<>; +}; + +// Resource limits for a Soroban transaction. +// The transaction will fail if it exceeds any of these limits. +struct SorobanResources +{ + // The ledger footprint of the transaction. + LedgerFootprint footprint; + // The maximum number of instructions this transaction can use + uint32 instructions; + + // The maximum number of bytes this transaction can read from ledger + uint32 readBytes; + // The maximum number of bytes this transaction can write to ledger + uint32 writeBytes; + + // Maximum size of dynamic metadata produced by this contract ( + // currently only includes the events). + uint32 extendedMetaDataSizeBytes; +}; + +// The transaction extension for Soroban. +struct SorobanTransactionData +{ + SorobanResources resources; + // Portion of transaction `fee` allocated to refundable fees. + int64 refundableFee; + ExtensionPoint ext; +}; // TransactionV0 is a transaction with the AccountID discriminant stripped off, // leaving a raw ed25519 public key to identify the source account. This is used @@ -835,6 +870,8 @@ struct Transaction { case 0: void; + case 1: + SorobanTransactionData sorobanData; } ext; }; @@ -1735,15 +1772,17 @@ enum InvokeHostFunctionResultCode // codes considered as "failure" for the operation INVOKE_HOST_FUNCTION_MALFORMED = -1, - INVOKE_HOST_FUNCTION_TRAPPED = -2 + INVOKE_HOST_FUNCTION_TRAPPED = -2, + INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 }; union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) { case INVOKE_HOST_FUNCTION_SUCCESS: - SCVal success; + SCVal success; case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: +case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: void; }; @@ -1850,7 +1889,9 @@ enum TransactionResultCode txBAD_SPONSORSHIP = -14, // sponsorship not confirmed txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met - txMALFORMED = -16 // precondition is invalid + txMALFORMED = -16, // precondition is invalid + // declared Soroban resource usage exceeds the network limit + txSOROBAN_RESOURCE_LIMIT_EXCEEDED = -17 }; // InnerTransactionResult must be binary compatible with TransactionResult From 5e132b2a6c6c2107b04ed11a00a0040e124b7ee0 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 26 Apr 2023 13:34:15 -0700 Subject: [PATCH 062/112] Back out the host logic version config setting, will not use it (#85) --- Stellar-contract-config-setting.x | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 1c71551..82eb8ea 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -148,9 +148,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, - CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION = 6, - CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 7, - CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 8 + CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, + CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -167,8 +166,6 @@ case CONFIG_SETTING_CONTRACT_META_DATA_V0: ConfigSettingContractMetaDataV0 contractMetaData; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; -case CONFIG_SETTING_CONTRACT_HOST_LOGIC_VERSION: - uint32 contractHostLogicVersion; case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: ContractCostParams contractCostParamsCpuInsns; case CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: From 4f83bee2447390dd98f2bd8ca17420597a078c6e Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Fri, 28 Apr 2023 14:05:27 -0400 Subject: [PATCH 063/112] Change cost param type to int64 (#87) --- Stellar-contract-config-setting.x | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 82eb8ea..0c52c8c 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -129,13 +129,14 @@ enum ContractCostType { }; struct ContractCostParamEntry { - int32 constTerm; - int32 linearTerm; + int64 constTerm; + int64 linearTerm; // use `ext` to add more terms (e.g. higher order polynomials) in the future ExtensionPoint ext; }; -const CONTRACT_COST_COUNT_LIMIT = 1024; // limits the ContractCostParams size to 12kB +// limits the ContractCostParams size to 20kB +const CONTRACT_COST_COUNT_LIMIT = 1024; typedef ContractCostParamEntry ContractCostParams; From e288e22081552bd711c62bc888bbeade87acb83c Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Fri, 28 Apr 2023 18:13:00 -0400 Subject: [PATCH 064/112] Add config settings for contract data limits (#90) --- Stellar-contract-config-setting.x | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 0c52c8c..04e28d2 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -150,7 +150,9 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, - CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7 + CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, + CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES = 8, + CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -170,6 +172,10 @@ case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: ContractCostParams contractCostParamsCpuInsns; case CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: - ContractCostParams contractCostParamsMemBytes; + ContractCostParams contractCostParamsMemBytes; +case CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: + uint32 contractDataKeySizeBytes; +case CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: + uint32 contractDataEntrySizeBytes; }; } \ No newline at end of file From 2f16687fdf6f4bcfb56805e2035f69997f4b34c4 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Mon, 1 May 2023 12:16:21 -0400 Subject: [PATCH 065/112] Add `txSOROBAN_RESOURCE_LIMIT_EXCEEDED` to the respective structs. (#91) --- Stellar-transaction.x | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index d4ad0d9..ec1538a 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1922,6 +1922,7 @@ struct InnerTransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: + case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: void; } result; @@ -1968,6 +1969,7 @@ struct TransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: + case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: void; } result; From 318c36b0cf4edd3f3d993263504857199c18ee52 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 8 May 2023 13:43:28 -0500 Subject: [PATCH 066/112] Remove all TransactionResultSetV2 related changes and puts the hash of the events and return values in InvokeHostFunctionResult (#83) * Remove all TransactionResultSetV2 related changes and puts the hash of TxHashOfMetaHashesSet in the new LedgerHeaderExtensionV2 * Remove hashing of tx meta components * Remove nested events now that we only have one op per tx * Return hash of events and return values in InvokeHostFunctionResult --- Stellar-ledger.x | 84 +++++++------------------------------------ Stellar-transaction.x | 2 +- 2 files changed, 13 insertions(+), 73 deletions(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 79d3d45..8c9458e 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -280,32 +280,6 @@ struct TransactionHistoryResultEntry ext; }; -struct TransactionResultPairV2 -{ - Hash transactionHash; - Hash hashOfMetaHashes; // hash of hashes in TransactionMetaV3 - // TransactionResult is in the meta -}; - -struct TransactionResultSetV2 -{ - TransactionResultPairV2 results<>; -}; - -struct TransactionHistoryResultEntryV2 -{ - uint32 ledgerSeq; - TransactionResultSetV2 txResultSet; - - // reserved for future use - union switch (int v) - { - case 0: - void; - } - ext; -}; - struct LedgerHeaderHistoryEntry { Hash hash; @@ -424,16 +398,6 @@ struct DiagnosticEvent ContractEvent event; }; -struct OperationDiagnosticEvents -{ - DiagnosticEvent events<>; -}; - -struct OperationEvents -{ - ContractEvent events<>; -}; - struct TransactionMetaV3 { LedgerEntryChanges txChangesBefore; // tx level changes before operations @@ -441,17 +405,21 @@ struct TransactionMetaV3 OperationMeta operations<>; // meta for each operation LedgerEntryChanges txChangesAfter; // tx level changes after operations are // applied if any - OperationEvents events<>; // custom events populated by the - // contracts themselves. One list per operation. - TransactionResult txResult; + ContractEvent events<>; // custom events populated by the + // contracts themselves. + SCVal returnValues; // return values of each invocation. - Hash hashes[3]; // stores sha256(txChangesBefore, operations, txChangesAfter), - // sha256(events), and sha256(txResult) - - // Diagnostics events that are not hashed. One list per operation. + // Diagnostics events that are not hashed. // This will contain all contract and diagnostic events. Even ones // that were emitted in a failed contract call. - OperationDiagnosticEvents diagnosticEvents<>; + DiagnosticEvent diagnosticEvents<>; +}; + +// This is in Stellar-ledger.x to due to a circular dependency +struct InvokeHostFunctionSuccessPreImage +{ + SCVal returnValues; + ContractEvent events<>; }; // this is the meta produced when applying transactions @@ -478,13 +446,6 @@ struct TransactionResultMeta TransactionMeta txApplyProcessing; }; -struct TransactionResultMetaV2 -{ - TransactionResultPairV2 result; - LedgerEntryChanges feeProcessing; - TransactionMeta txApplyProcessing; -}; - // this represents a single upgrade that was performed as part of a ledger // upgrade struct UpgradeEntryMeta @@ -529,32 +490,11 @@ struct LedgerCloseMetaV1 SCPHistoryEntry scpInfo<>; }; -// only difference between V1 and V2 is this uses TransactionResultMetaV2 -struct LedgerCloseMetaV2 -{ - LedgerHeaderHistoryEntry ledgerHeader; - - GeneralizedTransactionSet txSet; - - // NB: transactions are sorted in apply order here - // fees for all transactions are processed first - // followed by applying transactions - TransactionResultMetaV2 txProcessing<>; - - // upgrades are applied last - UpgradeEntryMeta upgradesProcessing<>; - - // other misc information attached to the ledger close - SCPHistoryEntry scpInfo<>; -}; - union LedgerCloseMeta switch (int v) { case 0: LedgerCloseMetaV0 v0; case 1: LedgerCloseMetaV1 v1; -case 2: - LedgerCloseMetaV2 v2; }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index ec1538a..127625b 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1779,7 +1779,7 @@ enum InvokeHostFunctionResultCode union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) { case INVOKE_HOST_FUNCTION_SUCCESS: - SCVal success; + Hash success; // sha256(InvokeHostFunctionSuccessPreImage) case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: From c2e702c70951ff59a1eff257f08cf38d47210e5f Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 16 May 2023 22:15:45 -0700 Subject: [PATCH 067/112] Err reform (#92) * Remove comment with improbable suggestion * Simplify error codes --- Stellar-contract-spec.x | 4 +- Stellar-contract.x | 152 ++++++++-------------------------------- 2 files changed, 30 insertions(+), 126 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 8431e22..a314589 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -19,7 +19,7 @@ enum SCSpecType // Types with no parameters. SC_SPEC_TYPE_BOOL = 1, SC_SPEC_TYPE_VOID = 2, - SC_SPEC_TYPE_STATUS = 3, + SC_SPEC_TYPE_ERROR = 3, SC_SPEC_TYPE_U32 = 4, SC_SPEC_TYPE_I32 = 5, SC_SPEC_TYPE_U64 = 6, @@ -95,7 +95,7 @@ union SCSpecTypeDef switch (SCSpecType type) case SC_SPEC_TYPE_VAL: case SC_SPEC_TYPE_BOOL: case SC_SPEC_TYPE_VOID: -case SC_SPEC_TYPE_STATUS: +case SC_SPEC_TYPE_ERROR: case SC_SPEC_TYPE_U32: case SC_SPEC_TYPE_I32: case SC_SPEC_TYPE_U64: diff --git a/Stellar-contract.x b/Stellar-contract.x index 6084cdb..bad9539 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -22,7 +22,7 @@ enum SCValType { SCV_BOOL = 0, SCV_VOID = 1, - SCV_STATUS = 2, + SCV_ERROR = 2, // 32 bits is the smallest type in WASM or XDR; no need for u8/u16. SCV_U32 = 3, @@ -49,9 +49,6 @@ enum SCValType SCV_U256 = 11, SCV_I256 = 12, - // TODO: possibly allocate subtypes of i64, i128 and/or u256 for - // fixed-precision with a specific number of decimals. - // Bytes come in 3 flavors, 2 of which have meaningfully different // formatting and validity-checking / domain-restriction. SCV_BYTES = 13, @@ -74,131 +71,38 @@ enum SCValType SCV_LEDGER_KEY_NONCE = 21 }; -enum SCStatusType -{ - SST_OK = 0, - SST_UNKNOWN_ERROR = 1, - SST_HOST_VALUE_ERROR = 2, - SST_HOST_OBJECT_ERROR = 3, - SST_HOST_FUNCTION_ERROR = 4, - SST_HOST_STORAGE_ERROR = 5, - SST_HOST_CONTEXT_ERROR = 6, - SST_VM_ERROR = 7, - SST_CONTRACT_ERROR = 8, - SST_HOST_AUTH_ERROR = 9 - // TODO: add more -}; - -enum SCHostValErrorCode -{ - HOST_VALUE_UNKNOWN_ERROR = 0, - HOST_VALUE_RESERVED_TAG_VALUE = 1, - HOST_VALUE_UNEXPECTED_VAL_TYPE = 2, - HOST_VALUE_U63_OUT_OF_RANGE = 3, - HOST_VALUE_U32_OUT_OF_RANGE = 4, - HOST_VALUE_STATIC_UNKNOWN = 5, - HOST_VALUE_MISSING_OBJECT = 6, - HOST_VALUE_SYMBOL_TOO_LONG = 7, - HOST_VALUE_SYMBOL_BAD_CHAR = 8, - HOST_VALUE_SYMBOL_CONTAINS_NON_UTF8 = 9, - HOST_VALUE_BITSET_TOO_MANY_BITS = 10, - HOST_VALUE_STATUS_UNKNOWN = 11 -}; - -enum SCHostObjErrorCode -{ - HOST_OBJECT_UNKNOWN_ERROR = 0, - HOST_OBJECT_UNKNOWN_REFERENCE = 1, - HOST_OBJECT_UNEXPECTED_TYPE = 2, - HOST_OBJECT_OBJECT_COUNT_EXCEEDS_U32_MAX = 3, - HOST_OBJECT_OBJECT_NOT_EXIST = 4, - HOST_OBJECT_VEC_INDEX_OUT_OF_BOUND = 5, - HOST_OBJECT_CONTRACT_HASH_WRONG_LENGTH = 6 -}; - -enum SCHostFnErrorCode -{ - HOST_FN_UNKNOWN_ERROR = 0, - HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION = 1, - HOST_FN_INPUT_ARGS_WRONG_LENGTH = 2, - HOST_FN_INPUT_ARGS_WRONG_TYPE = 3, - HOST_FN_INPUT_ARGS_INVALID = 4 -}; - -enum SCHostStorageErrorCode +enum SCErrorType { - HOST_STORAGE_UNKNOWN_ERROR = 0, - HOST_STORAGE_EXPECT_CONTRACT_DATA = 1, - HOST_STORAGE_READWRITE_ACCESS_TO_READONLY_ENTRY = 2, - HOST_STORAGE_ACCESS_TO_UNKNOWN_ENTRY = 3, - HOST_STORAGE_MISSING_KEY_IN_GET = 4, - HOST_STORAGE_GET_ON_DELETED_KEY = 5 + SCE_CONTRACT = 0, + SCE_WASM_VM = 1, + SCE_CONTEXT = 2, + SCE_STORAGE = 3, + SCE_OBJECT = 4, + SCE_CRYPTO = 5, + SCE_EVENTS = 6, + SCE_BUDGET = 7, + SCE_VALUE = 8, + SCE_AUTH = 9 }; -enum SCHostAuthErrorCode +enum SCErrorCode { - HOST_AUTH_UNKNOWN_ERROR = 0, - HOST_AUTH_NONCE_ERROR = 1, - HOST_AUTH_DUPLICATE_AUTHORIZATION = 2, - HOST_AUTH_NOT_AUTHORIZED = 3 + SCEC_ARITH_DOMAIN = 0, // some arithmetic wasn't defined (overflow, divide-by-zero) + SCEC_INDEX_BOUNDS = 1, // something was indexed beyond its bounds + SCEC_INVALID_INPUT = 2, // user provided some otherwise-bad data + SCEC_MISSING_VALUE = 3, // some value was required but not provided + SCEC_EXISTING_VALUE = 4, // some value was provided where not allowed + SCEC_EXCEEDED_LIMIT = 5, // some arbitrary limit -- gas or otherwise -- was hit + SCEC_INVALID_ACTION = 6, // data was valid but action requested was not + SCEC_INTERNAL_ERROR = 7, // the internal state of the host was otherwise-bad + SCEC_UNEXPECTED_TYPE = 8, // some type wasn't as expected + SCEC_UNEXPECTED_SIZE = 9 // something's size wasn't as expected }; -enum SCHostContextErrorCode +struct SCError { - HOST_CONTEXT_UNKNOWN_ERROR = 0, - HOST_CONTEXT_NO_CONTRACT_RUNNING = 1 -}; - -enum SCVmErrorCode { - VM_UNKNOWN = 0, - VM_VALIDATION = 1, - VM_INSTANTIATION = 2, - VM_FUNCTION = 3, - VM_TABLE = 4, - VM_MEMORY = 5, - VM_GLOBAL = 6, - VM_VALUE = 7, - VM_TRAP_UNREACHABLE = 8, - VM_TRAP_MEMORY_ACCESS_OUT_OF_BOUNDS = 9, - VM_TRAP_TABLE_ACCESS_OUT_OF_BOUNDS = 10, - VM_TRAP_ELEM_UNINITIALIZED = 11, - VM_TRAP_DIVISION_BY_ZERO = 12, - VM_TRAP_INTEGER_OVERFLOW = 13, - VM_TRAP_INVALID_CONVERSION_TO_INT = 14, - VM_TRAP_STACK_OVERFLOW = 15, - VM_TRAP_UNEXPECTED_SIGNATURE = 16, - VM_TRAP_MEM_LIMIT_EXCEEDED = 17, - VM_TRAP_CPU_LIMIT_EXCEEDED = 18 -}; - -enum SCUnknownErrorCode -{ - UNKNOWN_ERROR_GENERAL = 0, - UNKNOWN_ERROR_XDR = 1 -}; - -union SCStatus switch (SCStatusType type) -{ -case SST_OK: - void; -case SST_UNKNOWN_ERROR: - SCUnknownErrorCode unknownCode; -case SST_HOST_VALUE_ERROR: - SCHostValErrorCode valCode; -case SST_HOST_OBJECT_ERROR: - SCHostObjErrorCode objCode; -case SST_HOST_FUNCTION_ERROR: - SCHostFnErrorCode fnCode; -case SST_HOST_STORAGE_ERROR: - SCHostStorageErrorCode storageCode; -case SST_HOST_CONTEXT_ERROR: - SCHostContextErrorCode contextCode; -case SST_VM_ERROR: - SCVmErrorCode vmCode; -case SST_CONTRACT_ERROR: - uint32 contractCode; -case SST_HOST_AUTH_ERROR: - SCHostAuthErrorCode authCode; + SCErrorType type; + SCErrorCode code; }; struct UInt128Parts { @@ -285,8 +189,8 @@ case SCV_BOOL: bool b; case SCV_VOID: void; -case SCV_STATUS: - SCStatus error; +case SCV_ERROR: + SCError error; case SCV_U32: uint32 u32; From 076061abeb158cb7c91ec80228c560126bc2baa7 Mon Sep 17 00:00:00 2001 From: mlo Date: Fri, 19 May 2023 15:41:27 -0700 Subject: [PATCH 068/112] update overlay xdr (#94) * update overlay xdr * Add comment --- Stellar-overlay.x | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Stellar-overlay.x b/Stellar-overlay.x index 8203258..4c96473 100644 --- a/Stellar-overlay.x +++ b/Stellar-overlay.x @@ -27,6 +27,12 @@ struct SendMore uint32 numMessages; }; +struct SendMoreExtended +{ + uint32 numMessages; + uint32 numBytes; +}; + struct AuthCert { Curve25519Public pubkey; @@ -47,16 +53,14 @@ struct Hello uint256 nonce; }; - -// During the roll-out phrase, pull mode will be optional. +// During the roll-out phrase, nodes can disable flow control in bytes. // Therefore, we need a way to communicate with other nodes -// that we want/don't want pull mode. -// However, the goal is for everyone to enable it by default, -// so we don't want to introduce a new member variable. -// For now, we'll use the `flags` field (originally named -// `unused`) in `Auth`. -// 100 is just a number that is not 0. -const AUTH_MSG_FLAG_PULL_MODE_REQUESTED = 100; +// that we want/don't want flow control in bytes. +// We use the `flags` field in the Auth message with a special value +// set to communicate this. Note that AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED != 0 +// AND AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED != 100 (as previously +// that value was used for other purposes). +const AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED = 200; struct Auth { @@ -83,7 +87,7 @@ struct PeerAddress uint32 numFailures; }; -// Next ID: 18 +// Next ID: 21 enum MessageType { ERROR_MSG = 0, @@ -112,6 +116,8 @@ enum MessageType SURVEY_RESPONSE = 15, SEND_MORE = 16, + SEND_MORE_EXTENDED = 20, + FLOOD_ADVERT = 18, FLOOD_DEMAND = 19 }; @@ -274,7 +280,8 @@ case GET_SCP_STATE: uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest case SEND_MORE: SendMore sendMoreMessage; - +case SEND_MORE_EXTENDED: + SendMoreExtended sendMoreExtendedMessage; // Pull mode case FLOOD_ADVERT: FloodAdvert floodAdvert; From a9feddf49722bb6e5ed54e04715098955f70b9e8 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 23 May 2023 09:34:51 -0700 Subject: [PATCH 069/112] Replace ContractAuth addressWithNonce option with explicit union (#88) --- Stellar-transaction.x | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 127625b..b65b28c 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -540,9 +540,23 @@ struct AddressWithNonce uint64 nonce; }; +enum AuthorizerType +{ + AUTHORIZER_SOURCE_ACCOUNT = 0, + AUTHORIZER_ADDRESS = 1, +}; + +union Authorizer switch (AuthorizerType type) +{ +case AUTHORIZER_SOURCE_ACCOUNT: + void; +case AUTHORIZER_ADDRESS: + AddressWithNonce address; +}; + struct ContractAuth { - AddressWithNonce* addressWithNonce; // not present for invoker + Authorizer authorizer; AuthorizedInvocation rootInvocation; SCVec signatureArgs; }; From aeea15354db95fb9a35c957b24625f268d59f7bb Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 23 May 2023 09:35:06 -0700 Subject: [PATCH 070/112] Replace ContractAuth addressWithNonce option with explicit union (#88) From 404c42e5fee3c2dd552ba4ed91bf02cfa86bb0d3 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 23 May 2023 10:07:29 -0700 Subject: [PATCH 071/112] Move ContractAuth signatureArgs into Authorization (#89) --- Stellar-transaction.x | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index b65b28c..e154b6b 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -534,31 +534,31 @@ struct AuthorizedInvocation AuthorizedInvocation subInvocations<>; }; -struct AddressWithNonce +struct AddressAuthorization { SCAddress address; uint64 nonce; + SCVec signatureArgs; }; -enum AuthorizerType +enum AuthorizationType { - AUTHORIZER_SOURCE_ACCOUNT = 0, - AUTHORIZER_ADDRESS = 1, + AUTHORIZATION_SOURCE_ACCOUNT = 0, + AUTHORIZATION_ADDRESS = 1, }; -union Authorizer switch (AuthorizerType type) +union Authorization switch (AuthorizationType type) { -case AUTHORIZER_SOURCE_ACCOUNT: +case AUTHORIZATION_SOURCE_ACCOUNT: void; -case AUTHORIZER_ADDRESS: - AddressWithNonce address; +case AUTHORIZATION_ADDRESS: + AddressAuthorization address; }; struct ContractAuth { - Authorizer authorizer; + Authorization authorizer; AuthorizedInvocation rootInvocation; - SCVec signatureArgs; }; struct HostFunction { From 48540f24b4d2a6be67e3afb8ebe5ca73c027b2bc Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 May 2023 13:53:05 -0700 Subject: [PATCH 072/112] Remove trailing , (#97) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index e154b6b..8575659 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -544,7 +544,7 @@ struct AddressAuthorization enum AuthorizationType { AUTHORIZATION_SOURCE_ACCOUNT = 0, - AUTHORIZATION_ADDRESS = 1, + AUTHORIZATION_ADDRESS = 1 }; union Authorization switch (AuthorizationType type) From 077fe707303edb20358c3d6484ccfe2fe587ad4e Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Tue, 30 May 2023 21:21:43 -0400 Subject: [PATCH 073/112] Changes to auth-related XDR and a bit of cleanup. (#95) * Changes to auth-related XDR and a bit of cleanup. - Prepare create contract host fn for using auth next - Get rid of unnecessary envelopes - Passing-by cleanup: get rid of `SCVAL_LIMIT`. * Rename `HostFunctionArgs` back to just `HostFunction`. * Use `ScAddress` to identify contracts in auth payload. --- Stellar-contract.x | 9 ++- Stellar-ledger-entries.x | 10 +-- Stellar-transaction.x | 151 ++++++++++++++++----------------------- 3 files changed, 68 insertions(+), 102 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index bad9539..54a0364 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -168,14 +168,13 @@ case SC_ADDRESS_TYPE_CONTRACT: %struct SCVal; %struct SCMapEntry; -const SCVAL_LIMIT = 256000; const SCSYMBOL_LIMIT = 32; -typedef SCVal SCVec; -typedef SCMapEntry SCMap; +typedef SCVal SCVec<>; +typedef SCMapEntry SCMap<>; -typedef opaque SCBytes; -typedef string SCString; +typedef opaque SCBytes<>; +typedef string SCString<>; typedef string SCSymbol; struct SCNonceKey { diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 2eca637..dea2c69 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -503,7 +503,7 @@ struct ContractCodeEntry { ExtensionPoint ext; Hash hash; - opaque code; + opaque code<>; }; @@ -628,11 +628,7 @@ enum EnvelopeType ENVELOPE_TYPE_TX_FEE_BUMP = 5, ENVELOPE_TYPE_OP_ID = 6, ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519 = 8, - ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, - ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11, - ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12, - ENVELOPE_TYPE_CONTRACT_AUTH = 13 + ENVELOPE_TYPE_CONTRACT_ID = 8, + ENVELOPE_TYPE_SOROBAN_AUTHORIZATION = 9 }; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 8575659..0a571b5 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -477,106 +477,105 @@ enum HostFunctionType HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM = 2 }; -enum ContractIDType +enum ContractIDPreimageType { - CONTRACT_ID_FROM_SOURCE_ACCOUNT = 0, - CONTRACT_ID_FROM_ED25519_PUBLIC_KEY = 1, - CONTRACT_ID_FROM_ASSET = 2 + CONTRACT_ID_PREIMAGE_FROM_ADDRESS = 0, + CONTRACT_ID_PREIMAGE_FROM_ASSET = 1 }; -enum ContractIDPublicKeyType +union ContractIDPreimage switch (ContractIDPreimageType type) { - CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT = 0, - CONTRACT_ID_PUBLIC_KEY_ED25519 = 1 -}; - -struct UploadContractWasmArgs -{ - opaque code; -}; - -union ContractID switch (ContractIDType type) -{ -case CONTRACT_ID_FROM_SOURCE_ACCOUNT: - uint256 salt; -case CONTRACT_ID_FROM_ED25519_PUBLIC_KEY: - struct +case CONTRACT_ID_PREIMAGE_FROM_ADDRESS: + struct { - uint256 key; - Signature signature; + SCAddress address; uint256 salt; - } fromEd25519PublicKey; -case CONTRACT_ID_FROM_ASSET: - Asset asset; + } fromAddress; +case CONTRACT_ID_PREIMAGE_FROM_ASSET: + Asset fromAsset; }; struct CreateContractArgs { - ContractID contractID; + ContractIDPreimage contractIDPreimage; SCContractExecutable executable; }; -union HostFunctionArgs switch (HostFunctionType type) +union HostFunction switch (HostFunctionType type) { case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: SCVec invokeContract; case HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs createContract; case HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: - UploadContractWasmArgs uploadContractWasm; + opaque wasm<>; +}; + +enum SorobanAuthorizedFunctionType +{ + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN = 0, + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN = 1 }; -struct AuthorizedInvocation +struct SorobanAuthorizedContractFunction { - Hash contractID; + SCAddress contractAddress; SCSymbol functionName; SCVec args; - AuthorizedInvocation subInvocations<>; }; -struct AddressAuthorization +union SorobanAuthorizedFunction switch (SorobanAuthorizedFunctionType type) +{ +case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: + SorobanAuthorizedContractFunction contractFn; +case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: + CreateContractArgs createContractHostFn; +}; + +struct SorobanAuthorizedInvocation +{ + SorobanAuthorizedFunction function; + SorobanAuthorizedInvocation subInvocations<>; +}; + +struct SorobanAddressCredentials { SCAddress address; uint64 nonce; SCVec signatureArgs; }; -enum AuthorizationType +enum SorobanCredentialsType { - AUTHORIZATION_SOURCE_ACCOUNT = 0, - AUTHORIZATION_ADDRESS = 1 + SOROBAN_CREDENTIALS_SOURCE_ACCOUNT = 0, + SOROBAN_CREDENTIALS_ADDRESS = 1 }; -union Authorization switch (AuthorizationType type) +union SorobanCredentials switch (SorobanCredentialsType type) { -case AUTHORIZATION_SOURCE_ACCOUNT: +case SOROBAN_CREDENTIALS_SOURCE_ACCOUNT: void; -case AUTHORIZATION_ADDRESS: - AddressAuthorization address; +case SOROBAN_CREDENTIALS_ADDRESS: + SorobanAddressCredentials address; }; -struct ContractAuth -{ - Authorization authorizer; - AuthorizedInvocation rootInvocation; -}; +/* Unit of authorization data for Soroban. -struct HostFunction { - // Arguments of the function to call defined by the function - // type. - HostFunctionArgs args; - // Per-address authorizations for this host fn - // Currently only supported for INVOKE_CONTRACT function - ContractAuth auth<>; + Represents an authorization for executing the tree of authorized contract + and/or host function calls by the user defined by `credentials`. +*/ +struct SorobanAuthorizationEntry +{ + SorobanCredentials credentials; + SorobanAuthorizedInvocation rootInvocation; }; struct InvokeHostFunctionOp { - // The host functions to invoke. The functions will be executed - // in the same fashion as operations: either all functions will - // be successfully applied or all fail if at least one of them - // fails. - HostFunction functions; + // Host function to invoke. + HostFunction hostFunction; + // Per-address authorizations for this host function. + SorobanAuthorizationEntry auth<>; }; /* An operation is the lowest unit of work that a transaction does */ @@ -656,52 +655,24 @@ case ENVELOPE_TYPE_POOL_REVOKE_OP_ID: struct { AccountID sourceAccount; - SequenceNumber seqNum; + SequenceNumber seqNum; uint32 opNum; PoolID liquidityPoolID; Asset asset; } revokeID; -case ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: - struct - { - Hash networkID; - uint256 ed25519; - uint256 salt; - } ed25519ContractID; -case ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: +case ENVELOPE_TYPE_CONTRACT_ID: struct { Hash networkID; - Hash contractID; - uint256 salt; + ContractIDPreimage contractIDPreimage; } contractID; -case ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: - struct - { - Hash networkID; - Asset asset; - } fromAsset; -case ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: - struct - { - Hash networkID; - AccountID sourceAccount; - uint256 salt; - } sourceAccountContractID; -case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: - struct - { - Hash networkID; - SCContractExecutable executable; - uint256 salt; - } createContractArgs; -case ENVELOPE_TYPE_CONTRACT_AUTH: +case ENVELOPE_TYPE_SOROBAN_AUTHORIZATION: struct { Hash networkID; uint64 nonce; - AuthorizedInvocation invocation; - } contractAuth; + SorobanAuthorizedInvocation invocation; + } sorobanAuthorization; }; enum MemoType From a5f448b746f242bb96391a44932cd6d5abbdb6b9 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 31 May 2023 19:42:44 -0400 Subject: [PATCH 074/112] Revert invoke host fn return value to be a single value. (#98) --- Stellar-ledger.x | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 8c9458e..d38dfd3 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -405,9 +405,9 @@ struct TransactionMetaV3 OperationMeta operations<>; // meta for each operation LedgerEntryChanges txChangesAfter; // tx level changes after operations are // applied if any - ContractEvent events<>; // custom events populated by the + ContractEvent events<>; // custom events populated by the // contracts themselves. - SCVal returnValues; // return values of each invocation. + SCVal returnValue; // return value of the invocation. // Diagnostics events that are not hashed. // This will contain all contract and diagnostic events. Even ones From de264d81ea87dfaa19e089b60fed8eb0219b2ab4 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 31 May 2023 20:03:24 -0400 Subject: [PATCH 075/112] One more update to return value. (#99) --- Stellar-ledger.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index d38dfd3..7b0e04a 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -418,7 +418,7 @@ struct TransactionMetaV3 // This is in Stellar-ledger.x to due to a circular dependency struct InvokeHostFunctionSuccessPreImage { - SCVal returnValues; + SCVal returnValue; ContractEvent events<>; }; From 956da0a0d6020efd539f3adbc6f7a0d4876478e4 Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Thu, 1 Jun 2023 13:27:25 -1000 Subject: [PATCH 076/112] State expiration (#93) * Adds support for state expiration * Cleanup and refactoring * Added rent fees and revert footprint changes * Get rid of floating point math for rent fees * Add changes for env * Adapt names to recent consensus on state expiration terminology * Add state expiration related entries to LedgerCloseMeta as v2 * Move extension point to front of structure. --------- Co-authored-by: Graydon Hoare Co-authored-by: Siddharth Suresh --- Stellar-contract-config-setting.x | 22 +++++++++++++++- Stellar-contract.x | 14 ++++++++++- Stellar-ledger-entries.x | 42 +++++++++++++++++++++++++++++-- Stellar-ledger.x | 35 ++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 04e28d2..db8a462 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -135,6 +135,23 @@ struct ContractCostParamEntry { ExtensionPoint ext; }; +struct StateExpirationSettings { + uint32 maxEntryExpiration; + uint32 minTempEntryExpiration; + uint32 minRestorableEntryExpiration; + uint32 autoBumpLedgers; + + // rent_fee = wfee_rate_average / rent_rate_denominator_for_type + int64 restorableRentRateDenominator; + int64 tempRentRateDenominator; + + union switch (int v) + { + case 0: + void; + } ext; +}; + // limits the ContractCostParams size to 20kB const CONTRACT_COST_COUNT_LIMIT = 1024; @@ -152,7 +169,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES = 8, - CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9 + CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, + CONFIG_SETTING_STATE_EXPIRATION = 10 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -177,5 +195,7 @@ case CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: uint32 contractDataKeySizeBytes; case CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: uint32 contractDataEntrySizeBytes; +case CONFIG_SETTING_STATE_EXPIRATION: + StateExpirationSettings stateExpirationSettings; }; } \ No newline at end of file diff --git a/Stellar-contract.x b/Stellar-contract.x index 54a0364..a8353ac 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -68,7 +68,9 @@ enum SCValType // symbolic SCVals used as the key for ledger entries for a contract's code // and an address' nonce, respectively. SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, - SCV_LEDGER_KEY_NONCE = 21 + SCV_LEDGER_KEY_NONCE = 21, + + SCV_STORAGE_TYPE = 22 }; enum SCErrorType @@ -165,6 +167,13 @@ case SC_ADDRESS_TYPE_CONTRACT: Hash contractId; }; +// Here due to circular dependency +enum ContractDataType { + TEMPORARY = 0, + MERGEABLE = 1, + EXCLUSIVE = 2 +}; + %struct SCVal; %struct SCMapEntry; @@ -240,6 +249,9 @@ case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: void; case SCV_LEDGER_KEY_NONCE: SCNonceKey nonce_key; + +case SCV_STORAGE_TYPE: + ContractDataType storageType; }; struct SCMapEntry diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index dea2c69..fb781ab 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -493,17 +493,52 @@ struct LiquidityPoolEntry body; }; +enum ContractLedgerEntryType { + DATA_ENTRY = 0, + EXPIRATION_EXTENSION = 1 +}; + +const MASK_CONTRACT_DATA_FLAGS_V20 = 0x1; + +enum ContractDataFlags { + // When set, the given entry does not recieve automatic expiration bumps + // on access. Note that entries can still be bumped manually via the footprint. + NO_AUTOBUMP = 0x1 +}; + struct ContractDataEntry { Hash contractID; SCVal key; - SCVal val; + ContractDataType type; + + union switch (ContractLedgerEntryType leType) + { + case DATA_ENTRY: + struct + { + uint32 flags; + SCVal val; + } data; + case EXPIRATION_EXTENSION: + void; + } body; + + uint32 expirationLedgerSeq; }; struct ContractCodeEntry { ExtensionPoint ext; Hash hash; - opaque code<>; + union switch (ContractLedgerEntryType leType) + { + case DATA_ENTRY: + opaque code<>; + case EXPIRATION_EXTENSION: + void; + } body; + + uint32 expirationLedgerSeq; }; @@ -602,11 +637,14 @@ case CONTRACT_DATA: { Hash contractID; SCVal key; + ContractDataType type; + ContractLedgerEntryType leType; } contractData; case CONTRACT_CODE: struct { Hash hash; + ContractLedgerEntryType leType; } contractCode; case CONFIG_SETTING: struct diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 7b0e04a..ba99a6b 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -490,11 +490,46 @@ struct LedgerCloseMetaV1 SCPHistoryEntry scpInfo<>; }; +struct LedgerCloseMetaV2 +{ + // We forgot to add an ExtensionPoint in v1 but at least + // we can add one now in v2. + ExtensionPoint ext; + + LedgerHeaderHistoryEntry ledgerHeader; + + GeneralizedTransactionSet txSet; + + // NB: transactions are sorted in apply order here + // fees for all transactions are processed first + // followed by applying transactions + TransactionResultMeta txProcessing<>; + + // upgrades are applied last + UpgradeEntryMeta upgradesProcessing<>; + + // other misc information attached to the ledger close + SCPHistoryEntry scpInfo<>; + + // Size in bytes of BucketList, to support downstream + // systems calculating storage fees correctly. + uint64 totalByteSizeOfBucketList; + + // Expired temp keys that are being evicted at this ledger. + LedgerKey evictedTemporaryLedgerKeys<>; + + // Expired restorable ledger entries that are being + // evicted at this ledger. + LedgerEntry evictedRestorableLedgerEntries<>; +}; + union LedgerCloseMeta switch (int v) { case 0: LedgerCloseMetaV0 v0; case 1: LedgerCloseMetaV1 v1; +case 2: + LedgerCloseMetaV2 v2; }; } From 5b1ab56a30f9fc091e24ffd6bb8ac17f3073fc41 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 8 Jun 2023 12:40:58 -0400 Subject: [PATCH 077/112] Make `returnValue` optional in meta. (#100) * Make `returnValue` optional in meta. This is meaningless for non-Soroban txs. * Make whole soroban tx meta optional. Also did some small extension point cleanup. --- Stellar-contract-config-setting.x | 5 +++-- Stellar-ledger.x | 24 +++++++++++++++++------- Stellar-transaction.x | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index db8a462..9b50678 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -129,10 +129,11 @@ enum ContractCostType { }; struct ContractCostParamEntry { - int64 constTerm; - int64 linearTerm; // use `ext` to add more terms (e.g. higher order polynomials) in the future ExtensionPoint ext; + + int64 constTerm; + int64 linearTerm; }; struct StateExpirationSettings { diff --git a/Stellar-ledger.x b/Stellar-ledger.x index ba99a6b..dd943d0 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -398,21 +398,31 @@ struct DiagnosticEvent ContractEvent event; }; -struct TransactionMetaV3 +struct SorobanTransactionMeta { - LedgerEntryChanges txChangesBefore; // tx level changes before operations - // are applied if any - OperationMeta operations<>; // meta for each operation - LedgerEntryChanges txChangesAfter; // tx level changes after operations are - // applied if any + ExtensionPoint ext; + ContractEvent events<>; // custom events populated by the // contracts themselves. - SCVal returnValue; // return value of the invocation. + SCVal returnValue; // return value of the host fn invocation // Diagnostics events that are not hashed. // This will contain all contract and diagnostic events. Even ones // that were emitted in a failed contract call. DiagnosticEvent diagnosticEvents<>; +} + +struct TransactionMetaV3 +{ + ExtensionPoint ext; + + LedgerEntryChanges txChangesBefore; // tx level changes before operations + // are applied if any + OperationMeta operations<>; // meta for each operation + LedgerEntryChanges txChangesAfter; // tx level changes after operations are + // applied if any + SorobanTransactionMeta* sorobanMeta; // Soroban-specific meta (only for + // Soroban transactions). }; // This is in Stellar-ledger.x to due to a circular dependency diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 0a571b5..d084585 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -789,10 +789,10 @@ struct SorobanResources // The transaction extension for Soroban. struct SorobanTransactionData { + ExtensionPoint ext; SorobanResources resources; // Portion of transaction `fee` allocated to refundable fees. int64 refundableFee; - ExtensionPoint ext; }; // TransactionV0 is a transaction with the AccountID discriminant stripped off, From 1d2fd904afde94936ba22b5e1764c4a289409607 Mon Sep 17 00:00:00 2001 From: mlo Date: Thu, 8 Jun 2023 14:41:57 -0700 Subject: [PATCH 078/112] Add execution lanes config (#101) * Add tx limit * Minor naming tweak --- Stellar-contract-config-setting.x | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 9b50678..af59d71 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -1,6 +1,13 @@ %#include "xdr/Stellar-types.h" namespace stellar { +// General “Soroban execution lane” settings +struct ConfigSettingContractExecutionLanesV0 +{ + // maximum number of Soroban transactions per ledger + uint32 ledgerMaxTxCount; +}; + // "Compute" settings for contracts (instructions and memory). struct ConfigSettingContractComputeV0 { @@ -171,7 +178,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES = 8, CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, - CONFIG_SETTING_STATE_EXPIRATION = 10 + CONFIG_SETTING_STATE_EXPIRATION = 10, + CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -198,5 +206,7 @@ case CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: uint32 contractDataEntrySizeBytes; case CONFIG_SETTING_STATE_EXPIRATION: StateExpirationSettings stateExpirationSettings; +case CONFIG_SETTING_CONTRACT_EXECUTION_LANES: + ConfigSettingContractExecutionLanesV0 contractExecutionLanes; }; } \ No newline at end of file From 72c85fd191a460bad69926024d76b18db55d381b Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 8 Jun 2023 19:29:24 -0400 Subject: [PATCH 079/112] Small XDR fix. (#102) --- Stellar-ledger.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index dd943d0..3853267 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -410,7 +410,7 @@ struct SorobanTransactionMeta // This will contain all contract and diagnostic events. Even ones // that were emitted in a failed contract call. DiagnosticEvent diagnosticEvents<>; -} +}; struct TransactionMetaV3 { From 0f5e556bb8778a2da8930bc81d0ed21f08c14b80 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 12 Jun 2023 22:42:58 -0700 Subject: [PATCH 080/112] Add costs for new cryptography host functions (#105) --- Stellar-contract-config-setting.x | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index af59d71..dfb5ef5 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -132,7 +132,17 @@ enum ContractCostType { // Roundtrip cost of invoking a VM function from the host. InvokeVmFunction = 19, // Cost of charging a value to the budgeting system. - ChargeBudget = 20 + ChargeBudget = 20, + // Cost of computing a keccak256 hash from bytes. + ComputeKeccak256Hash = 21, + // Cost of computing an ECDSA secp256k1 pubkey from bytes. + ComputeEcdsaSecp256k1Key = 22, + // Cost of computing an ECDSA secp256k1 signature from bytes. + ComputeEcdsaSecp256k1Sig = 23, + // Cost of verifying an ECDSA secp256k1 signature. + VerifyEcdsaSecp256k1Sig = 24, + // Cost of recovering an ECDSA secp256k1 key from a signature. + RecoverEcdsaSecp256k1Key = 25 }; struct ContractCostParamEntry { From 1c32b6b2347fb116a1d40badcb5be2b7a41354e2 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Tue, 13 Jun 2023 18:06:12 -0400 Subject: [PATCH 081/112] Switch Soroban nonces from autoincrement to random values with signature expiration. (#103) --- Stellar-contract.x | 2 +- Stellar-ledger-entries.x | 4 ++-- Stellar-transaction.x | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index a8353ac..901e074 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -187,7 +187,7 @@ typedef string SCString<>; typedef string SCSymbol; struct SCNonceKey { - SCAddress nonce_address; + int64 nonce; }; union SCVal switch (SCValType type) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index fb781ab..059e64e 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -507,7 +507,7 @@ enum ContractDataFlags { }; struct ContractDataEntry { - Hash contractID; + SCAddress contract; SCVal key; ContractDataType type; @@ -635,7 +635,7 @@ case LIQUIDITY_POOL: case CONTRACT_DATA: struct { - Hash contractID; + SCAddress contract; SCVal key; ContractDataType type; ContractLedgerEntryType leType; diff --git a/Stellar-transaction.x b/Stellar-transaction.x index d084585..7f6584f 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -541,7 +541,8 @@ struct SorobanAuthorizedInvocation struct SorobanAddressCredentials { SCAddress address; - uint64 nonce; + int64 nonce; + uint32 signatureExpirationLedger; SCVec signatureArgs; }; @@ -670,7 +671,8 @@ case ENVELOPE_TYPE_SOROBAN_AUTHORIZATION: struct { Hash networkID; - uint64 nonce; + int64 nonce; + uint32 signatureExpirationLedger; SorobanAuthorizedInvocation invocation; } sorobanAuthorization; }; From 9e5ddb5be6c25819a82a97220f46f265eeba7095 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 13 Jun 2023 20:02:05 -0500 Subject: [PATCH 082/112] Expiration bump op (#106) * bump op * Update thresholds --- Stellar-transaction.x | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 7f6584f..3b24b73 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -62,7 +62,8 @@ enum OperationType SET_TRUST_LINE_FLAGS = 21, LIQUIDITY_POOL_DEPOSIT = 22, LIQUIDITY_POOL_WITHDRAW = 23, - INVOKE_HOST_FUNCTION = 24 + INVOKE_HOST_FUNCTION = 24, + BUMP_EXPIRATION = 25 }; /* CreateAccount @@ -571,6 +572,11 @@ struct SorobanAuthorizationEntry SorobanAuthorizedInvocation rootInvocation; }; +/* Upload WASM, create, and invoke contracts in Soroban. + + Threshold: med + Result: InvokeHostFunctionResult +*/ struct InvokeHostFunctionOp { // Host function to invoke. @@ -579,6 +585,23 @@ struct InvokeHostFunctionOp SorobanAuthorizationEntry auth<>; }; +enum BumpExpirationType +{ + BUMP_EXPIRATION_UNIFORM = 0 +}; + +/* Bump the expiration ledger of the entries specified in the readOnly footprint + so they'll expire at least ledgersToExpire ledgers from lcl. + + Threshold: med + Result: BumpExpirationResult +*/ +union BumpExpirationOp switch (BumpExpirationType type) +{ +case BUMP_EXPIRATION_UNIFORM: + uint32 ledgersToExpire; +}; + /* An operation is the lowest unit of work that a transaction does */ struct Operation { @@ -639,6 +662,8 @@ struct Operation LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; case INVOKE_HOST_FUNCTION: InvokeHostFunctionOp invokeHostFunctionOp; + case BUMP_EXPIRATION: + BumpExpirationOp bumpExpirationOp; } body; }; @@ -1773,6 +1798,24 @@ case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: void; }; +enum BumpExpirationOpResultCode +{ + // codes considered as "success" for the operation + BUMP_EXPIRATION_SUCCESS = 0, + + // codes considered as "failure" for the operation + BUMP_EXPIRATION_MALFORMED = -1, + BUMP_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 +}; + +union BumpExpirationResult switch (BumpExpirationOpResultCode code) +{ +case BUMP_EXPIRATION_SUCCESS: + void; +case BUMP_EXPIRATION_MALFORMED: + void; +}; + /* High level Operation Result */ enum OperationResultCode { @@ -1841,6 +1884,8 @@ case opINNER: LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; case INVOKE_HOST_FUNCTION: InvokeHostFunctionResult invokeHostFunctionResult; + case BUMP_EXPIRATION: + BumpExpirationResult bumpExpirationResult; } tr; case opBAD_AUTH: From 5d6b3b9e444ee35e711dadb3b52fae63dbc74585 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 15 Jun 2023 16:12:27 -0500 Subject: [PATCH 083/112] Remove mergeable (#108) --- Stellar-contract.x | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 901e074..10eaba6 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -170,8 +170,7 @@ case SC_ADDRESS_TYPE_CONTRACT: // Here due to circular dependency enum ContractDataType { TEMPORARY = 0, - MERGEABLE = 1, - EXCLUSIVE = 2 + PERSISTENT = 1 }; %struct SCVal; From 25363a72e9bbbb6621d888dde3b36c0a196fb84d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 15 Jun 2023 16:52:47 -0700 Subject: [PATCH 084/112] back out ContractCostType::VerifyEcdsaSecp256k1Sig, keeping Recover (#109) --- Stellar-contract-config-setting.x | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index dfb5ef5..c2725e0 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -139,10 +139,8 @@ enum ContractCostType { ComputeEcdsaSecp256k1Key = 22, // Cost of computing an ECDSA secp256k1 signature from bytes. ComputeEcdsaSecp256k1Sig = 23, - // Cost of verifying an ECDSA secp256k1 signature. - VerifyEcdsaSecp256k1Sig = 24, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 25 + RecoverEcdsaSecp256k1Key = 24 }; struct ContractCostParamEntry { From 18437a90b3b9962b22b99ce153bd5abfe3688fba Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Fri, 16 Jun 2023 11:29:32 -0400 Subject: [PATCH 085/112] Add cost types for int256 arithmetics (#110) --- Stellar-contract-config-setting.x | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index c2725e0..4dc0a2d 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -140,7 +140,17 @@ enum ContractCostType { // Cost of computing an ECDSA secp256k1 signature from bytes. ComputeEcdsaSecp256k1Sig = 23, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 24 + RecoverEcdsaSecp256k1Key = 24, + // Cost of int256 addition (`+`) and subtraction (`-`) operations + Int256AddSub = 25, + // Cost of int256 multiplication (`*`) operation + Int256Mul = 26, + // Cost of int256 division (`/`) operation + Int256Div = 27, + // Cost of int256 power (`exp`) operation + Int256Pow = 28, + // Cost of int256 shift (`shl`, `shr`) operation + Int256Shift = 29 }; struct ContractCostParamEntry { From fe27674a4ea6bac33f0539366718beb44d4a2780 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 16 Jun 2023 17:35:01 -0500 Subject: [PATCH 086/112] Add footprint to bump expiration name (#111) --- Stellar-transaction.x | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 3b24b73..8754ba5 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -63,7 +63,7 @@ enum OperationType LIQUIDITY_POOL_DEPOSIT = 22, LIQUIDITY_POOL_WITHDRAW = 23, INVOKE_HOST_FUNCTION = 24, - BUMP_EXPIRATION = 25 + BUMP_FOOTPRINT_EXPIRATION = 25 }; /* CreateAccount @@ -585,20 +585,20 @@ struct InvokeHostFunctionOp SorobanAuthorizationEntry auth<>; }; -enum BumpExpirationType +enum BumpFootprintExpirationType { - BUMP_EXPIRATION_UNIFORM = 0 + BUMP_FOOTPRINT_EXPIRATION_UNIFORM = 0 }; /* Bump the expiration ledger of the entries specified in the readOnly footprint so they'll expire at least ledgersToExpire ledgers from lcl. Threshold: med - Result: BumpExpirationResult + Result: BumpFootprintExpirationResult */ -union BumpExpirationOp switch (BumpExpirationType type) +union BumpFootprintExpirationOp switch (BumpFootprintExpirationType type) { -case BUMP_EXPIRATION_UNIFORM: +case BUMP_FOOTPRINT_EXPIRATION_UNIFORM: uint32 ledgersToExpire; }; @@ -662,8 +662,8 @@ struct Operation LiquidityPoolWithdrawOp liquidityPoolWithdrawOp; case INVOKE_HOST_FUNCTION: InvokeHostFunctionOp invokeHostFunctionOp; - case BUMP_EXPIRATION: - BumpExpirationOp bumpExpirationOp; + case BUMP_FOOTPRINT_EXPIRATION: + BumpFootprintExpirationOp bumpFootprintExpirationOp; } body; }; @@ -1798,21 +1798,21 @@ case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: void; }; -enum BumpExpirationOpResultCode +enum BumpFootprintExpirationOpResultCode { // codes considered as "success" for the operation - BUMP_EXPIRATION_SUCCESS = 0, + BUMP_FOOTPRINT_EXPIRATION_SUCCESS = 0, // codes considered as "failure" for the operation - BUMP_EXPIRATION_MALFORMED = -1, - BUMP_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 + BUMP_FOOTPRINT_EXPIRATION_MALFORMED = -1, + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 }; -union BumpExpirationResult switch (BumpExpirationOpResultCode code) +union BumpFootprintExpirationResult switch (BumpFootprintExpirationOpResultCode code) { -case BUMP_EXPIRATION_SUCCESS: +case BUMP_FOOTPRINT_EXPIRATION_SUCCESS: void; -case BUMP_EXPIRATION_MALFORMED: +case BUMP_FOOTPRINT_EXPIRATION_MALFORMED: void; }; @@ -1884,8 +1884,8 @@ case opINNER: LiquidityPoolWithdrawResult liquidityPoolWithdrawResult; case INVOKE_HOST_FUNCTION: InvokeHostFunctionResult invokeHostFunctionResult; - case BUMP_EXPIRATION: - BumpExpirationResult bumpExpirationResult; + case BUMP_FOOTPRINT_EXPIRATION: + BumpFootprintExpirationResult bumpFootprintExpirationResult; } tr; case opBAD_AUTH: From 0769d7a5581265da6f270f5bfd1ff7018f176c75 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 20 Jun 2023 11:12:12 -0500 Subject: [PATCH 087/112] Remove Op postfix for result code (#113) --- Stellar-transaction.x | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 8754ba5..f8213df 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1798,7 +1798,7 @@ case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: void; }; -enum BumpFootprintExpirationOpResultCode +enum BumpFootprintExpirationResultCode { // codes considered as "success" for the operation BUMP_FOOTPRINT_EXPIRATION_SUCCESS = 0, @@ -1808,7 +1808,7 @@ enum BumpFootprintExpirationOpResultCode BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 }; -union BumpFootprintExpirationResult switch (BumpFootprintExpirationOpResultCode code) +union BumpFootprintExpirationResult switch (BumpFootprintExpirationResultCode code) { case BUMP_FOOTPRINT_EXPIRATION_SUCCESS: void; From 7b403105788e33044e089c4c2f957df8ddabaca8 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 21 Jun 2023 15:15:42 -0400 Subject: [PATCH 088/112] Add support for contract instance storage. (#115) - Store contract instance that includes executable and storage map under a special key - Make contract executable separate from ScVal --- Stellar-contract.x | 49 ++++++++++++++++++++++++------------------- Stellar-transaction.x | 2 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 10eaba6..bc9d9ad 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -59,18 +59,17 @@ enum SCValType SCV_VEC = 16, SCV_MAP = 17, - // SCContractExecutable and SCAddressType are types that gets used separately from - // SCVal so we do not flatten their structures into separate SCVal cases. - SCV_CONTRACT_EXECUTABLE = 18, - SCV_ADDRESS = 19, - - // SCV_LEDGER_KEY_CONTRACT_EXECUTABLE and SCV_LEDGER_KEY_NONCE are unique - // symbolic SCVals used as the key for ledger entries for a contract's code - // and an address' nonce, respectively. - SCV_LEDGER_KEY_CONTRACT_EXECUTABLE = 20, - SCV_LEDGER_KEY_NONCE = 21, - - SCV_STORAGE_TYPE = 22 + // The following are the internal SCVal variants that are not + // exposed to the contracts. + SCV_ADDRESS = 18, + SCV_CONTRACT_INSTANCE = 19, + SCV_STORAGE_TYPE = 20, + + // SCV_LEDGER_KEY_CONTRACT_INSTANCE and SCV_LEDGER_KEY_NONCE are unique + // symbolic SCVals used as the key for ledger entries for a contract's + // instance and an address' nonce, respectively. + SCV_LEDGER_KEY_CONTRACT_INSTANCE = 21, + SCV_LEDGER_KEY_NONCE = 22 }; enum SCErrorType @@ -139,17 +138,17 @@ struct Int256Parts { uint64 lo_lo; }; -enum SCContractExecutableType +enum ContractExecutableType { - SCCONTRACT_EXECUTABLE_WASM_REF = 0, - SCCONTRACT_EXECUTABLE_TOKEN = 1 + CONTRACT_EXECUTABLE_WASM = 0, + CONTRACT_EXECUTABLE_TOKEN = 1 }; -union SCContractExecutable switch (SCContractExecutableType type) +union ContractExecutable switch (ContractExecutableType type) { -case SCCONTRACT_EXECUTABLE_WASM_REF: - Hash wasm_id; -case SCCONTRACT_EXECUTABLE_TOKEN: +case CONTRACT_EXECUTABLE_WASM: + Hash wasm_hash; +case CONTRACT_EXECUTABLE_TOKEN: void; }; @@ -189,6 +188,11 @@ struct SCNonceKey { int64 nonce; }; +struct SCContractInstance { + ContractExecutable executable; + SCMap* storage; +}; + union SCVal switch (SCValType type) { @@ -237,20 +241,21 @@ case SCV_VEC: case SCV_MAP: SCMap *map; -case SCV_CONTRACT_EXECUTABLE: - SCContractExecutable exec; case SCV_ADDRESS: SCAddress address; // Special SCVals reserved for system-constructed contract-data // ledger keys, not generally usable elsewhere. -case SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: +case SCV_LEDGER_KEY_CONTRACT_INSTANCE: void; case SCV_LEDGER_KEY_NONCE: SCNonceKey nonce_key; case SCV_STORAGE_TYPE: ContractDataType storageType; + +case SCV_CONTRACT_INSTANCE: + SCContractInstance instance; }; struct SCMapEntry diff --git a/Stellar-transaction.x b/Stellar-transaction.x index f8213df..40794ff 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -499,7 +499,7 @@ case CONTRACT_ID_PREIMAGE_FROM_ASSET: struct CreateContractArgs { ContractIDPreimage contractIDPreimage; - SCContractExecutable executable; + ContractExecutable executable; }; union HostFunction switch (HostFunctionType type) From 0c44aa7752e8017ea29c6ee14c06d4c7bb91cc79 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Wed, 21 Jun 2023 16:17:03 -0400 Subject: [PATCH 089/112] Add `VmCachedInstantiation` for future use (#116) --- Stellar-contract-config-setting.x | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 4dc0a2d..ffe88cc 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -129,28 +129,30 @@ enum ContractCostType { VmMemWrite = 17, // Cost of instantiation a VM from wasm bytes code. VmInstantiation = 18, + // Cost of instantiation a VM from a cached state. + VmCachedInstantiation = 19, // Roundtrip cost of invoking a VM function from the host. - InvokeVmFunction = 19, + InvokeVmFunction = 20, // Cost of charging a value to the budgeting system. - ChargeBudget = 20, + ChargeBudget = 21, // Cost of computing a keccak256 hash from bytes. - ComputeKeccak256Hash = 21, + ComputeKeccak256Hash = 22, // Cost of computing an ECDSA secp256k1 pubkey from bytes. - ComputeEcdsaSecp256k1Key = 22, + ComputeEcdsaSecp256k1Key = 23, // Cost of computing an ECDSA secp256k1 signature from bytes. - ComputeEcdsaSecp256k1Sig = 23, + ComputeEcdsaSecp256k1Sig = 24, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 24, + RecoverEcdsaSecp256k1Key = 25, // Cost of int256 addition (`+`) and subtraction (`-`) operations - Int256AddSub = 25, + Int256AddSub = 26, // Cost of int256 multiplication (`*`) operation - Int256Mul = 26, + Int256Mul = 27, // Cost of int256 division (`/`) operation - Int256Div = 27, + Int256Div = 28, // Cost of int256 power (`exp`) operation - Int256Pow = 28, + Int256Pow = 29, // Cost of int256 shift (`shl`, `shr`) operation - Int256Shift = 29 + Int256Shift = 30 }; struct ContractCostParamEntry { From 4a25a3eaf15ed2eedaa09f8c94e932ee3b29a423 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 21 Jun 2023 17:16:14 -0400 Subject: [PATCH 090/112] Update XDR comments (#117) --- Stellar-contract.x | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index bc9d9ad..7920289 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -59,9 +59,12 @@ enum SCValType SCV_VEC = 16, SCV_MAP = 17, + // Address is the universal identifier for contracts and classic + // accounts. + SCV_ADDRESS = 18, + // The following are the internal SCVal variants that are not // exposed to the contracts. - SCV_ADDRESS = 18, SCV_CONTRACT_INSTANCE = 19, SCV_STORAGE_TYPE = 20, From 79984210572dc8822fc2717a149342e69f77f3cf Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 21 Jun 2023 21:23:42 -0700 Subject: [PATCH 091/112] Remove ContractDataType from ScVal and rename (#118) --- Stellar-contract.x | 14 ++------------ Stellar-ledger-entries.x | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 7920289..9867ce3 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -66,13 +66,12 @@ enum SCValType // The following are the internal SCVal variants that are not // exposed to the contracts. SCV_CONTRACT_INSTANCE = 19, - SCV_STORAGE_TYPE = 20, // SCV_LEDGER_KEY_CONTRACT_INSTANCE and SCV_LEDGER_KEY_NONCE are unique // symbolic SCVals used as the key for ledger entries for a contract's // instance and an address' nonce, respectively. - SCV_LEDGER_KEY_CONTRACT_INSTANCE = 21, - SCV_LEDGER_KEY_NONCE = 22 + SCV_LEDGER_KEY_CONTRACT_INSTANCE = 20, + SCV_LEDGER_KEY_NONCE = 21 }; enum SCErrorType @@ -169,12 +168,6 @@ case SC_ADDRESS_TYPE_CONTRACT: Hash contractId; }; -// Here due to circular dependency -enum ContractDataType { - TEMPORARY = 0, - PERSISTENT = 1 -}; - %struct SCVal; %struct SCMapEntry; @@ -254,9 +247,6 @@ case SCV_LEDGER_KEY_CONTRACT_INSTANCE: case SCV_LEDGER_KEY_NONCE: SCNonceKey nonce_key; -case SCV_STORAGE_TYPE: - ContractDataType storageType; - case SCV_CONTRACT_INSTANCE: SCContractInstance instance; }; diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 059e64e..5eaccac 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -493,7 +493,7 @@ struct LiquidityPoolEntry body; }; -enum ContractLedgerEntryType { +enum ContractEntryBodyType { DATA_ENTRY = 0, EXPIRATION_EXTENSION = 1 }; @@ -506,12 +506,17 @@ enum ContractDataFlags { NO_AUTOBUMP = 0x1 }; +enum ContractDataDurability { + TEMPORARY = 0, + PERSISTENT = 1 +}; + struct ContractDataEntry { SCAddress contract; SCVal key; - ContractDataType type; + ContractDataDurability durability; - union switch (ContractLedgerEntryType leType) + union switch (ContractEntryBodyType bodyType) { case DATA_ENTRY: struct @@ -530,7 +535,7 @@ struct ContractCodeEntry { ExtensionPoint ext; Hash hash; - union switch (ContractLedgerEntryType leType) + union switch (ContractEntryBodyType bodyType) { case DATA_ENTRY: opaque code<>; @@ -637,14 +642,14 @@ case CONTRACT_DATA: { SCAddress contract; SCVal key; - ContractDataType type; - ContractLedgerEntryType leType; + ContractDataDurability durability; + ContractEntryBodyType bodyType; } contractData; case CONTRACT_CODE: struct { Hash hash; - ContractLedgerEntryType leType; + ContractEntryBodyType bodyType; } contractCode; case CONFIG_SETTING: struct From 2892ca048e222eecc8347134b33fda22bc66b863 Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Thu, 22 Jun 2023 15:33:29 -0700 Subject: [PATCH 092/112] Adds expiration iterator (#104) * Adds expiration iterator * Add BucketList size window and remove eviction iterator --- Stellar-contract-config-setting.x | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index ffe88cc..2918417 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -47,7 +47,7 @@ struct ConfigSettingContractLedgerCostV0 int64 feeReadLedgerEntry; // Fee per ledger entry read int64 feeWriteLedgerEntry; // Fee per ledger entry write - int64 feeRead1KB; // Fee for reading 1KB + int64 feeRead1KB; // Fee for reading 1KB int64 feeWrite1KB; // Fee for writing 1KB // Bucket list fees grow slowly up to that size @@ -158,7 +158,7 @@ enum ContractCostType { struct ContractCostParamEntry { // use `ext` to add more terms (e.g. higher order polynomials) in the future ExtensionPoint ext; - + int64 constTerm; int64 linearTerm; }; @@ -166,18 +166,21 @@ struct ContractCostParamEntry { struct StateExpirationSettings { uint32 maxEntryExpiration; uint32 minTempEntryExpiration; - uint32 minRestorableEntryExpiration; + uint32 minPersistentEntryExpiration; uint32 autoBumpLedgers; // rent_fee = wfee_rate_average / rent_rate_denominator_for_type - int64 restorableRentRateDenominator; + int64 persistentRentRateDenominator; int64 tempRentRateDenominator; - union switch (int v) - { - case 0: - void; - } ext; + // max number of entries that emit expiration meta in a single ledger + uint32 maxEntriesToExpire; + + // Number of snapshots to use when calculating average BucketList size + uint32 bucketListSizeWindowSampleSize; + + // Maximum number of bytes that we scan for eviction per ledger + uint64 evictionScanSize; }; // limits the ContractCostParams size to 20kB @@ -199,7 +202,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES = 8, CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, CONFIG_SETTING_STATE_EXPIRATION = 10, - CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11 + CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11, + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -228,5 +232,7 @@ case CONFIG_SETTING_STATE_EXPIRATION: StateExpirationSettings stateExpirationSettings; case CONFIG_SETTING_CONTRACT_EXECUTION_LANES: ConfigSettingContractExecutionLanesV0 contractExecutionLanes; +case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: + uint64 bucketListSizeWindow<>; }; } \ No newline at end of file From 5fe1784e405a1f874ffeb8557f48ffb42b994d5d Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 22 Jun 2023 18:00:15 -0500 Subject: [PATCH 093/112] XDR for RestoreFootprintOp (#120) * XDR for RestoreFootprintOp * Use extension point instead --- Stellar-transaction.x | 46 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 40794ff..ca6308f 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -63,7 +63,8 @@ enum OperationType LIQUIDITY_POOL_DEPOSIT = 22, LIQUIDITY_POOL_WITHDRAW = 23, INVOKE_HOST_FUNCTION = 24, - BUMP_FOOTPRINT_EXPIRATION = 25 + BUMP_FOOTPRINT_EXPIRATION = 25, + RESTORE_FOOTPRINT = 26 }; /* CreateAccount @@ -585,23 +586,28 @@ struct InvokeHostFunctionOp SorobanAuthorizationEntry auth<>; }; -enum BumpFootprintExpirationType -{ - BUMP_FOOTPRINT_EXPIRATION_UNIFORM = 0 -}; - /* Bump the expiration ledger of the entries specified in the readOnly footprint so they'll expire at least ledgersToExpire ledgers from lcl. Threshold: med Result: BumpFootprintExpirationResult */ -union BumpFootprintExpirationOp switch (BumpFootprintExpirationType type) +struct BumpFootprintExpirationOp { -case BUMP_FOOTPRINT_EXPIRATION_UNIFORM: + ExtensionPoint ext; uint32 ledgersToExpire; }; +/* Restore the expired or evicted entries specified in the readWrite footprint. + + Threshold: med + Result: RestoreFootprintOp +*/ +struct RestoreFootprintOp +{ + ExtensionPoint ext; +}; + /* An operation is the lowest unit of work that a transaction does */ struct Operation { @@ -664,6 +670,8 @@ struct Operation InvokeHostFunctionOp invokeHostFunctionOp; case BUMP_FOOTPRINT_EXPIRATION: BumpFootprintExpirationOp bumpFootprintExpirationOp; + case RESTORE_FOOTPRINT: + RestoreFootprintOp restoreFootprintOp; } body; }; @@ -1813,6 +1821,26 @@ union BumpFootprintExpirationResult switch (BumpFootprintExpirationResultCode co case BUMP_FOOTPRINT_EXPIRATION_SUCCESS: void; case BUMP_FOOTPRINT_EXPIRATION_MALFORMED: +case BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: + void; +}; + +enum RestoreFootprintResultCode +{ + // codes considered as "success" for the operation + RESTORE_FOOTPRINT_SUCCESS = 0, + + // codes considered as "failure" for the operation + RESTORE_FOOTPRINT_MALFORMED = -1, + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2 +}; + +union RestoreFootprintResult switch (RestoreFootprintResultCode code) +{ +case RESTORE_FOOTPRINT_SUCCESS: + void; +case RESTORE_FOOTPRINT_MALFORMED: +case RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: void; }; @@ -1886,6 +1914,8 @@ case opINNER: InvokeHostFunctionResult invokeHostFunctionResult; case BUMP_FOOTPRINT_EXPIRATION: BumpFootprintExpirationResult bumpFootprintExpirationResult; + case RESTORE_FOOTPRINT: + RestoreFootprintResult restoreFootprintResult; } tr; case opBAD_AUTH: From e372df9f677961aac04c5a4cc80a3667f310b29f Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 23 Jun 2023 16:39:40 +0100 Subject: [PATCH 094/112] Replace 'restorable' -> 'persistent' for state expiration config to match new terminology (#114) --- Stellar-contract-config-setting.x | 2 +- Stellar-ledger.x | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 2918417..00fa376 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -235,4 +235,4 @@ case CONFIG_SETTING_CONTRACT_EXECUTION_LANES: case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: uint64 bucketListSizeWindow<>; }; -} \ No newline at end of file +} diff --git a/Stellar-ledger.x b/Stellar-ledger.x index 3853267..e42e738 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -530,7 +530,7 @@ struct LedgerCloseMetaV2 // Expired restorable ledger entries that are being // evicted at this ledger. - LedgerEntry evictedRestorableLedgerEntries<>; + LedgerEntry evictedPersistentLedgerEntries<>; }; union LedgerCloseMeta switch (int v) From 5de7fe8cb2a47b3503202e17d6b9d2ee5683d86d Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 30 Jun 2023 16:38:11 -0500 Subject: [PATCH 095/112] Fix comment (#121) --- Stellar-transaction.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index ca6308f..3a465c0 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -817,7 +817,7 @@ struct SorobanResources uint32 writeBytes; // Maximum size of dynamic metadata produced by this contract ( - // currently only includes the events). + // bytes read from ledger + bytes written to ledger + event bytes written to meta). uint32 extendedMetaDataSizeBytes; }; From 257dea11483b126da23ea97ca013e640fc379029 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 11 Jul 2023 16:49:21 -0500 Subject: [PATCH 096/112] Add error when accessing expired entry (#122) --- Stellar-transaction.x | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 3a465c0..40768fe 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1793,7 +1793,8 @@ enum InvokeHostFunctionResultCode // codes considered as "failure" for the operation INVOKE_HOST_FUNCTION_MALFORMED = -1, INVOKE_HOST_FUNCTION_TRAPPED = -2, - INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 + INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, + INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4 }; union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) @@ -1803,6 +1804,7 @@ case INVOKE_HOST_FUNCTION_SUCCESS: case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: +case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: void; }; From 9d7155b3f65eab7755b5e3de9403b630e3fb623e Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 12 Jul 2023 15:53:22 -0400 Subject: [PATCH 097/112] Refactor config XDR to account for dynamic write fees. (#123) - Remove the flat fee - Rename the fields that contribute to the write fee for clarity --- Stellar-contract-config-setting.x | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 00fa376..6a534d8 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -48,16 +48,16 @@ struct ConfigSettingContractLedgerCostV0 int64 feeWriteLedgerEntry; // Fee per ledger entry write int64 feeRead1KB; // Fee for reading 1KB - int64 feeWrite1KB; // Fee for writing 1KB - - // Bucket list fees grow slowly up to that size - int64 bucketListSizeBytes; - // Fee rate in stroops when the bucket list is empty - int64 bucketListFeeRateLow; - // Fee rate in stroops when the bucket list reached bucketListSizeBytes - int64 bucketListFeeRateHigh; - // Rate multiplier for any additional data past the first bucketListSizeBytes - uint32 bucketListGrowthFactor; + + // The following parameters determine the write fee per 1KB. + // Write fee grows linearly until bucket list reaches this size + int64 bucketListTargetSizeBytes; + // Fee per 1KB write when the bucket list is empty + int64 writeFee1KBBucketListLow; + // Fee per 1KB write when the bucket list has reached `bucketListTargetSizeBytes` + int64 writeFee1KBBucketListHigh; + // Write fee multiplier for any additional data past the first `bucketListTargetSizeBytes` + uint32 bucketListWriteFeeGrowthFactor; }; // Historical data (pushed to core archives) settings for contracts. From aec9d6bc63f01443eb7017d629e28d3279779ae6 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Mon, 17 Jul 2023 13:43:46 -0400 Subject: [PATCH 098/112] Soroban tx set size upgrade support and XDR cleanup. (#124) - Use dedicated struct for `InvokeContract` host fn - Replace `ScVec` with `SCVal` or `SCVal<>` depending on the context --- Stellar-ledger.x | 10 ++++++++-- Stellar-transaction.x | 19 +++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Stellar-ledger.x b/Stellar-ledger.x index e42e738..5499319 100644 --- a/Stellar-ledger.x +++ b/Stellar-ledger.x @@ -127,7 +127,8 @@ enum LedgerUpgradeType LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, LEDGER_UPGRADE_BASE_RESERVE = 4, LEDGER_UPGRADE_FLAGS = 5, - LEDGER_UPGRADE_CONFIG = 6 + LEDGER_UPGRADE_CONFIG = 6, + LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE = 7 }; struct ConfigUpgradeSetKey { @@ -148,7 +149,12 @@ case LEDGER_UPGRADE_BASE_RESERVE: case LEDGER_UPGRADE_FLAGS: uint32 newFlags; // update flags case LEDGER_UPGRADE_CONFIG: + // Update arbitray `ConfigSetting` entries identified by the key. ConfigUpgradeSetKey newConfig; +case LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE: + // Update ConfigSettingContractExecutionLanesV0.ledgerMaxTxCount without + // using `LEDGER_UPGRADE_CONFIG`. + uint32 newMaxSorobanTxSetSize; }; struct ConfigUpgradeSet { @@ -385,7 +391,7 @@ struct ContractEvent case 0: struct { - SCVec topics; + SCVal topics<>; SCVal data; } v0; } diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 40768fe..3a70163 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -503,10 +503,16 @@ struct CreateContractArgs ContractExecutable executable; }; +struct InvokeContractArgs { + SCAddress contractAddress; + SCSymbol functionName; + SCVal args<>; +}; + union HostFunction switch (HostFunctionType type) { case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: - SCVec invokeContract; + InvokeContractArgs invokeContract; case HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs createContract; case HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: @@ -519,17 +525,10 @@ enum SorobanAuthorizedFunctionType SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN = 1 }; -struct SorobanAuthorizedContractFunction -{ - SCAddress contractAddress; - SCSymbol functionName; - SCVec args; -}; - union SorobanAuthorizedFunction switch (SorobanAuthorizedFunctionType type) { case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: - SorobanAuthorizedContractFunction contractFn; + InvokeContractArgs contractFn; case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: CreateContractArgs createContractHostFn; }; @@ -545,7 +544,7 @@ struct SorobanAddressCredentials SCAddress address; int64 nonce; uint32 signatureExpirationLedger; - SCVec signatureArgs; + SCVal signature; }; enum SorobanCredentialsType From 34241a1eb81a715cc75777ca1ed028ea1456645b Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 17 Jul 2023 20:30:52 -0700 Subject: [PATCH 099/112] Make SCError into a union to allow user errors to be u32 (#125) --- Stellar-contract.x | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 9867ce3..5bdc01a 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -102,9 +102,19 @@ enum SCErrorCode SCEC_UNEXPECTED_SIZE = 9 // something's size wasn't as expected }; -struct SCError +union SCError switch (SCErrorType type) { - SCErrorType type; +case SCE_CONTRACT: + uint32 contractCode; +case SCE_WASM_VM: +case SCE_CONTEXT: +case SCE_STORAGE: +case SCE_OBJECT: +case SCE_CRYPTO: +case SCE_EVENTS: +case SCE_BUDGET: +case SCE_VALUE: +case SCE_AUTH: SCErrorCode code; }; From 54fb7c53067307d987641811a6cf79091068a32d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 24 Jul 2023 17:50:25 -0600 Subject: [PATCH 100/112] Remove incorrect comment about Soroban u256 representation (#126) --- Stellar-contract.x | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 5bdc01a..369896b 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -38,8 +38,7 @@ enum SCValType // 128 bits is naturally supported by Rust and we use it for Soroban // fixed-point arithmetic prices / balances / similar "quantities". These - // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is - // represented as an array of 32 bytes. + // are represented in XDR as a pair of 2 u64s. SCV_U128 = 9, SCV_I128 = 10, From e72168f37f8d9ca203602d2af50f8cf3eb89b1a0 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 26 Jul 2023 16:49:31 -0400 Subject: [PATCH 101/112] Change metadata fee config to only account for contract events. (#127) Also renamed a couple tx-size related fields for clarity. --- Stellar-contract-config-setting.x | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 6a534d8..2f10e37 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -67,24 +67,26 @@ struct ConfigSettingContractHistoricalDataV0 }; // Meta data (pushed to downstream systems) settings for contracts. -struct ConfigSettingContractMetaDataV0 +struct ConfigSettingContractEventsV0 { - // Maximum size of extended meta data produced by a transaction - uint32 txMaxExtendedMetaDataSizeBytes; - // Fee for generating 1KB of extended meta data - int64 feeExtendedMetaData1KB; + // Maximum size of events that a contract call can emit. + uint32 txMaxContractEventsSizeBytes; + // Fee for generating 1KB of contract events. + int64 feeContractEvents1KB; }; -// Bandwidth related data settings for contracts +// Bandwidth related data settings for contracts. +// We consider bandwidth to only be consumed by the transaction envelopes, hence +// this concerns only transaction sizes. struct ConfigSettingContractBandwidthV0 { - // Maximum size in bytes to propagate per ledger - uint32 ledgerMaxPropagateSizeBytes; + // Maximum sum of all transaction sizes in the ledger in bytes + uint32 ledgerMaxTxsSizeBytes; // Maximum size in bytes for a transaction uint32 txMaxSizeBytes; - // Fee for propagating 1KB of data - int64 feePropagateData1KB; + // Fee for 1 KB of transaction size + int64 feeTxSize1KB; }; enum ContractCostType { @@ -217,7 +219,7 @@ case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: ConfigSettingContractHistoricalDataV0 contractHistoricalData; case CONFIG_SETTING_CONTRACT_META_DATA_V0: - ConfigSettingContractMetaDataV0 contractMetaData; + ConfigSettingContractEventsV0 contractEvents; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: From fc4dd1b6e179768f203d2e4b949ec331d723c6a7 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 26 Jul 2023 19:55:21 -0400 Subject: [PATCH 102/112] Update `SorobanResources` for consistency with config update. (#128) --- Stellar-transaction.x | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 3a70163..a294fd7 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -815,9 +815,9 @@ struct SorobanResources // The maximum number of bytes this transaction can write to ledger uint32 writeBytes; - // Maximum size of dynamic metadata produced by this contract ( - // bytes read from ledger + bytes written to ledger + event bytes written to meta). - uint32 extendedMetaDataSizeBytes; + // Maximum size of the contract events (serialized to XDR) this transaction + // can emit. + uint32 contractEventsSizeBytes; }; // The transaction extension for Soroban. From ec04dce3983103f8ed8b3b25ef028c08c9d8c59d Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 27 Jul 2023 14:54:16 -0400 Subject: [PATCH 103/112] One more metadata->events rename. (#129) --- Stellar-contract-config-setting.x | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 2f10e37..8374b64 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -66,7 +66,7 @@ struct ConfigSettingContractHistoricalDataV0 int64 feeHistorical1KB; // Fee for storing 1KB in archives }; -// Meta data (pushed to downstream systems) settings for contracts. +// Contract event-related settings. struct ConfigSettingContractEventsV0 { // Maximum size of events that a contract call can emit. @@ -197,7 +197,7 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, - CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, + CONFIG_SETTING_CONTRACT_EVENTS_V0 = 4, CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, @@ -218,7 +218,7 @@ case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: ConfigSettingContractLedgerCostV0 contractLedgerCost; case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: ConfigSettingContractHistoricalDataV0 contractHistoricalData; -case CONFIG_SETTING_CONTRACT_META_DATA_V0: +case CONFIG_SETTING_CONTRACT_EVENTS_V0: ConfigSettingContractEventsV0 contractEvents; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; From 9125ce3e4e00f168c1d3d41890795c7d534b12f3 Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Mon, 31 Jul 2023 20:44:16 +0200 Subject: [PATCH 104/112] Adds eviction iterator (#130) --- Stellar-contract-config-setting.x | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 8374b64..1b2faac 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -183,6 +183,15 @@ struct StateExpirationSettings { // Maximum number of bytes that we scan for eviction per ledger uint64 evictionScanSize; + + // Lowest BucketList level to be scanned to evict entries + uint32 startingEvictionScanLevel; +}; + +struct EvictionIterator { + uint32 bucketListLevel; + bool isCurrBucket; + uint64 bucketFileOffset; }; // limits the ContractCostParams size to 20kB @@ -205,7 +214,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, CONFIG_SETTING_STATE_EXPIRATION = 10, CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11, - CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12 + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12, + CONFIG_SETTING_EVICTION_ITERATOR = 13 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -236,5 +246,7 @@ case CONFIG_SETTING_CONTRACT_EXECUTION_LANES: ConfigSettingContractExecutionLanesV0 contractExecutionLanes; case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: uint64 bucketListSizeWindow<>; +case CONFIG_SETTING_EVICTION_ITERATOR: + EvictionIterator evictionIterator; }; } From 6098ad6d087afbb547f5d7c9d98684cf07896499 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Tue, 1 Aug 2023 16:25:59 -0400 Subject: [PATCH 105/112] Remove `ContractCostType::GuardFrame` (#131) --- Stellar-contract-config-setting.x | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index 1b2faac..e6278a5 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -121,40 +121,38 @@ enum ContractCostType { MapEntry = 12, // Cost of accessing an entry in a Vec VecEntry = 13, - // Cost of guarding a frame, which involves pushing and poping a frame and capturing a rollback point. - GuardFrame = 14, // Cost of verifying ed25519 signature of a payload. - VerifyEd25519Sig = 15, + VerifyEd25519Sig = 14, // Cost of reading a slice of vm linear memory - VmMemRead = 16, + VmMemRead = 15, // Cost of writing to a slice of vm linear memory - VmMemWrite = 17, + VmMemWrite = 16, // Cost of instantiation a VM from wasm bytes code. - VmInstantiation = 18, + VmInstantiation = 17, // Cost of instantiation a VM from a cached state. - VmCachedInstantiation = 19, + VmCachedInstantiation = 18, // Roundtrip cost of invoking a VM function from the host. - InvokeVmFunction = 20, + InvokeVmFunction = 19, // Cost of charging a value to the budgeting system. - ChargeBudget = 21, + ChargeBudget = 20, // Cost of computing a keccak256 hash from bytes. - ComputeKeccak256Hash = 22, + ComputeKeccak256Hash = 21, // Cost of computing an ECDSA secp256k1 pubkey from bytes. - ComputeEcdsaSecp256k1Key = 23, + ComputeEcdsaSecp256k1Key = 22, // Cost of computing an ECDSA secp256k1 signature from bytes. - ComputeEcdsaSecp256k1Sig = 24, + ComputeEcdsaSecp256k1Sig = 23, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 25, + RecoverEcdsaSecp256k1Key = 24, // Cost of int256 addition (`+`) and subtraction (`-`) operations - Int256AddSub = 26, + Int256AddSub = 25, // Cost of int256 multiplication (`*`) operation - Int256Mul = 27, + Int256Mul = 26, // Cost of int256 division (`/`) operation - Int256Div = 28, + Int256Div = 27, // Cost of int256 power (`exp`) operation - Int256Pow = 29, + Int256Pow = 28, // Cost of int256 shift (`shl`, `shr`) operation - Int256Shift = 30 + Int256Shift = 29 }; struct ContractCostParamEntry { From 1894f0909caa0adb00437564f8e01ec33a5b5ed2 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Tue, 8 Aug 2023 13:27:26 -0400 Subject: [PATCH 106/112] Clean up and clearify some `ContractCostType`s (#133) --- Stellar-contract-config-setting.x | 61 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index e6278a5..bb76b3c 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -100,59 +100,56 @@ enum ContractCostType { HostMemCpy = 3, // Cost of comparing two slices of host memory HostMemCmp = 4, - // Cost of a host function invocation, not including the actual work done by the function - InvokeHostFunction = 5, - // Cost of visiting a host object from the host object storage - // Only thing to make sure is the guest can't visitObject repeatly without incurring some charges elsewhere. + // Cost of a host function dispatch, not including the actual work done by + // the function nor the cost of VM invocation machinary + DispatchHostFunction = 5, + // Cost of visiting a host object from the host object storage. Exists to + // make sure some baseline cost coverage, i.e. repeatly visiting objects + // by the guest will always incur some charges. VisitObject = 6, - // Tracks a single Val (RawVal or primative Object like U64) <=> ScVal - // conversion cost. Most of these Val counterparts in ScVal (except e.g. - // Symbol) consumes a single int64 and therefore is a constant overhead. - ValXdrConv = 7, // Cost of serializing an xdr object to bytes - ValSer = 8, + ValSer = 7, // Cost of deserializing an xdr object from bytes - ValDeser = 9, + ValDeser = 8, // Cost of computing the sha256 hash from bytes - ComputeSha256Hash = 10, + ComputeSha256Hash = 9, // Cost of computing the ed25519 pubkey from bytes - ComputeEd25519PubKey = 11, + ComputeEd25519PubKey = 10, // Cost of accessing an entry in a Map. - MapEntry = 12, + MapEntry = 11, // Cost of accessing an entry in a Vec - VecEntry = 13, + VecEntry = 12, // Cost of verifying ed25519 signature of a payload. - VerifyEd25519Sig = 14, + VerifyEd25519Sig = 13, // Cost of reading a slice of vm linear memory - VmMemRead = 15, + VmMemRead = 14, // Cost of writing to a slice of vm linear memory - VmMemWrite = 16, + VmMemWrite = 15, // Cost of instantiation a VM from wasm bytes code. - VmInstantiation = 17, + VmInstantiation = 16, // Cost of instantiation a VM from a cached state. - VmCachedInstantiation = 18, - // Roundtrip cost of invoking a VM function from the host. - InvokeVmFunction = 19, - // Cost of charging a value to the budgeting system. - ChargeBudget = 20, + VmCachedInstantiation = 17, + // Cost of invoking a function on the VM. If the function is a host function, + // additional cost will be covered by `DispatchHostFunction`. + InvokeVmFunction = 18, // Cost of computing a keccak256 hash from bytes. - ComputeKeccak256Hash = 21, + ComputeKeccak256Hash = 19, // Cost of computing an ECDSA secp256k1 pubkey from bytes. - ComputeEcdsaSecp256k1Key = 22, + ComputeEcdsaSecp256k1Key = 20, // Cost of computing an ECDSA secp256k1 signature from bytes. - ComputeEcdsaSecp256k1Sig = 23, + ComputeEcdsaSecp256k1Sig = 21, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 24, + RecoverEcdsaSecp256k1Key = 22, // Cost of int256 addition (`+`) and subtraction (`-`) operations - Int256AddSub = 25, + Int256AddSub = 23, // Cost of int256 multiplication (`*`) operation - Int256Mul = 26, + Int256Mul = 24, // Cost of int256 division (`/`) operation - Int256Div = 27, + Int256Div = 25, // Cost of int256 power (`exp`) operation - Int256Pow = 28, + Int256Pow = 26, // Cost of int256 shift (`shl`, `shr`) operation - Int256Shift = 29 + Int256Shift = 27 }; struct ContractCostParamEntry { From 1795087cb8e84524eada0e5aee78ae66c2398222 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 18 Aug 2023 14:13:24 -0400 Subject: [PATCH 107/112] Add an error for exceeding refundable fee. (#134) * Add errors for exceeding the refundable fee. These have to be operation errors, as core is hard-wired to only return `txFAILED` on transaction failure and modifying this behavior is risky/slow. * Remove `contractEventsSizeBytes` from `SorobanResources`. This field is almost redundant and only helps to avoid apply-time error in the rare cases when the user sets the events resource, but forgets to set high enough refundable fee. It does, on the other hand, introduce another apply-time failure condition if the contracts emits a bit more events than expected (even if the refundable fee is high enough to cover that). The total size of the events emitted is still governed by the network setting. --- Stellar-transaction.x | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index a294fd7..2e149cd 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -814,10 +814,6 @@ struct SorobanResources uint32 readBytes; // The maximum number of bytes this transaction can write to ledger uint32 writeBytes; - - // Maximum size of the contract events (serialized to XDR) this transaction - // can emit. - uint32 contractEventsSizeBytes; }; // The transaction extension for Soroban. @@ -1793,7 +1789,8 @@ enum InvokeHostFunctionResultCode INVOKE_HOST_FUNCTION_MALFORMED = -1, INVOKE_HOST_FUNCTION_TRAPPED = -2, INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, - INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4 + INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4, + INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE = -5 }; union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) @@ -1804,6 +1801,7 @@ case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: +case INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE: void; }; @@ -1814,7 +1812,8 @@ enum BumpFootprintExpirationResultCode // codes considered as "failure" for the operation BUMP_FOOTPRINT_EXPIRATION_MALFORMED = -1, - BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2, + BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE = -3 }; union BumpFootprintExpirationResult switch (BumpFootprintExpirationResultCode code) @@ -1823,6 +1822,7 @@ case BUMP_FOOTPRINT_EXPIRATION_SUCCESS: void; case BUMP_FOOTPRINT_EXPIRATION_MALFORMED: case BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: +case BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE: void; }; @@ -1833,7 +1833,8 @@ enum RestoreFootprintResultCode // codes considered as "failure" for the operation RESTORE_FOOTPRINT_MALFORMED = -1, - RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2 + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2, + RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE = -3 }; union RestoreFootprintResult switch (RestoreFootprintResultCode code) @@ -1842,6 +1843,7 @@ case RESTORE_FOOTPRINT_SUCCESS: void; case RESTORE_FOOTPRINT_MALFORMED: case RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: +case RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE: void; }; From 7015193879e9da7cb70d889a49eecf494fefe7e1 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 21 Aug 2023 14:02:13 -0700 Subject: [PATCH 108/112] Remove ScSpecTypeSet and SC_SPEC_TYPE_SET (#136) --- Stellar-contract-spec.x | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index a314589..6988a63 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -39,7 +39,6 @@ enum SCSpecType SC_SPEC_TYPE_OPTION = 1000, SC_SPEC_TYPE_RESULT = 1001, SC_SPEC_TYPE_VEC = 1002, - SC_SPEC_TYPE_SET = 1003, SC_SPEC_TYPE_MAP = 1004, SC_SPEC_TYPE_TUPLE = 1005, SC_SPEC_TYPE_BYTES_N = 1006, @@ -70,11 +69,6 @@ struct SCSpecTypeMap SCSpecTypeDef valueType; }; -struct SCSpecTypeSet -{ - SCSpecTypeDef elementType; -}; - struct SCSpecTypeTuple { SCSpecTypeDef valueTypes<12>; @@ -119,8 +113,6 @@ case SC_SPEC_TYPE_VEC: SCSpecTypeVec vec; case SC_SPEC_TYPE_MAP: SCSpecTypeMap map; -case SC_SPEC_TYPE_SET: - SCSpecTypeSet set; case SC_SPEC_TYPE_TUPLE: SCSpecTypeTuple tuple; case SC_SPEC_TYPE_BYTES_N: From 8a65f610790a0b4b51987563e540fc6dbc2c11da Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Wed, 23 Aug 2023 11:35:52 -0700 Subject: [PATCH 109/112] Expiration Entry rework (#137) --- Stellar-contract-config-setting.x | 1 - Stellar-ledger-entries.x | 57 +++++++++++-------------------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/Stellar-contract-config-setting.x b/Stellar-contract-config-setting.x index bb76b3c..9512f0c 100644 --- a/Stellar-contract-config-setting.x +++ b/Stellar-contract-config-setting.x @@ -164,7 +164,6 @@ struct StateExpirationSettings { uint32 maxEntryExpiration; uint32 minTempEntryExpiration; uint32 minPersistentEntryExpiration; - uint32 autoBumpLedgers; // rent_fee = wfee_rate_average / rent_rate_denominator_for_type int64 persistentRentRateDenominator; diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 5eaccac..85b91fd 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -100,7 +100,8 @@ enum LedgerEntryType LIQUIDITY_POOL = 5, CONTRACT_DATA = 6, CONTRACT_CODE = 7, - CONFIG_SETTING = 8 + CONFIG_SETTING = 8, + EXPIRATION = 9 }; struct Signer @@ -493,58 +494,32 @@ struct LiquidityPoolEntry body; }; -enum ContractEntryBodyType { - DATA_ENTRY = 0, - EXPIRATION_EXTENSION = 1 -}; - -const MASK_CONTRACT_DATA_FLAGS_V20 = 0x1; - -enum ContractDataFlags { - // When set, the given entry does not recieve automatic expiration bumps - // on access. Note that entries can still be bumped manually via the footprint. - NO_AUTOBUMP = 0x1 -}; - enum ContractDataDurability { TEMPORARY = 0, PERSISTENT = 1 }; struct ContractDataEntry { + ExtensionPoint ext; + SCAddress contract; SCVal key; ContractDataDurability durability; - - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - struct - { - uint32 flags; - SCVal val; - } data; - case EXPIRATION_EXTENSION: - void; - } body; - - uint32 expirationLedgerSeq; + SCVal val; }; struct ContractCodeEntry { ExtensionPoint ext; Hash hash; - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - opaque code<>; - case EXPIRATION_EXTENSION: - void; - } body; + opaque code<>; +}; +struct ExpirationEntry { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; uint32 expirationLedgerSeq; -}; +} struct LedgerEntryExtensionV1 @@ -583,6 +558,8 @@ struct LedgerEntry ContractCodeEntry contractCode; case CONFIG_SETTING: ConfigSettingEntry configSetting; + case EXPIRATION: + ExpirationEntry expiration; } data; @@ -643,19 +620,23 @@ case CONTRACT_DATA: SCAddress contract; SCVal key; ContractDataDurability durability; - ContractEntryBodyType bodyType; } contractData; case CONTRACT_CODE: struct { Hash hash; - ContractEntryBodyType bodyType; } contractCode; case CONFIG_SETTING: struct { ConfigSettingID configSettingID; } configSetting; +case EXPIRATION: + struct + { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; + } expiration; }; // list of all envelope types used in the application From a9eb34f5084ef2863872f7dd764a51a28f28561d Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Wed, 23 Aug 2023 12:45:50 -0700 Subject: [PATCH 110/112] typo (#139) --- Stellar-ledger-entries.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar-ledger-entries.x b/Stellar-ledger-entries.x index 85b91fd..a225e16 100644 --- a/Stellar-ledger-entries.x +++ b/Stellar-ledger-entries.x @@ -519,7 +519,7 @@ struct ExpirationEntry { // Hash of the LedgerKey that is associated with this ExpirationEntry Hash keyHash; uint32 expirationLedgerSeq; -} +}; struct LedgerEntryExtensionV1 From 1177e7641d065b3bf6d5b9fc9c3fc4a0301eea2f Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 24 Aug 2023 11:35:50 -0700 Subject: [PATCH 111/112] expand SCError comments, no functional change (#140) * expand SCError comments, no functional change * Update Stellar-contract.x Co-authored-by: Siddharth Suresh --------- Co-authored-by: Siddharth Suresh --- Stellar-contract.x | 53 +++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index 369896b..7c7469c 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -75,32 +75,45 @@ enum SCValType enum SCErrorType { - SCE_CONTRACT = 0, - SCE_WASM_VM = 1, - SCE_CONTEXT = 2, - SCE_STORAGE = 3, - SCE_OBJECT = 4, - SCE_CRYPTO = 5, - SCE_EVENTS = 6, - SCE_BUDGET = 7, - SCE_VALUE = 8, - SCE_AUTH = 9 + SCE_CONTRACT = 0, // Contract-specific, user-defined codes. + SCE_WASM_VM = 1, // Errors while interpreting WASM bytecode. + SCE_CONTEXT = 2, // Errors in the contract's host context. + SCE_STORAGE = 3, // Errors accessing host storage. + SCE_OBJECT = 4, // Errors working with host objects. + SCE_CRYPTO = 5, // Errors in cryptographic operations. + SCE_EVENTS = 6, // Errors while emitting events. + SCE_BUDGET = 7, // Errors relating to budget limits. + SCE_VALUE = 8, // Errors working with host values or SCVals. + SCE_AUTH = 9 // Errors from the authentication subsystem. }; enum SCErrorCode { - SCEC_ARITH_DOMAIN = 0, // some arithmetic wasn't defined (overflow, divide-by-zero) - SCEC_INDEX_BOUNDS = 1, // something was indexed beyond its bounds - SCEC_INVALID_INPUT = 2, // user provided some otherwise-bad data - SCEC_MISSING_VALUE = 3, // some value was required but not provided - SCEC_EXISTING_VALUE = 4, // some value was provided where not allowed - SCEC_EXCEEDED_LIMIT = 5, // some arbitrary limit -- gas or otherwise -- was hit - SCEC_INVALID_ACTION = 6, // data was valid but action requested was not - SCEC_INTERNAL_ERROR = 7, // the internal state of the host was otherwise-bad - SCEC_UNEXPECTED_TYPE = 8, // some type wasn't as expected - SCEC_UNEXPECTED_SIZE = 9 // something's size wasn't as expected + SCEC_ARITH_DOMAIN = 0, // Some arithmetic was undefined (overflow, divide-by-zero). + SCEC_INDEX_BOUNDS = 1, // Something was indexed beyond its bounds. + SCEC_INVALID_INPUT = 2, // User provided some otherwise-bad data. + SCEC_MISSING_VALUE = 3, // Some value was required but not provided. + SCEC_EXISTING_VALUE = 4, // Some value was provided where not allowed. + SCEC_EXCEEDED_LIMIT = 5, // Some arbitrary limit -- gas or otherwise -- was hit. + SCEC_INVALID_ACTION = 6, // Data was valid but action requested was not. + SCEC_INTERNAL_ERROR = 7, // The host detected an error in its own logic. + SCEC_UNEXPECTED_TYPE = 8, // Some type wasn't as expected. + SCEC_UNEXPECTED_SIZE = 9 // Something's size wasn't as expected. }; +// Smart contract errors are split into a type (SCErrorType) and a code. When an +// error is of type SCE_CONTRACT it carries a user-defined uint32 code that +// Soroban assigns no specific meaning to. In all other cases, the type +// specifies a subsystem of the Soroban host where the error originated, and the +// accompanying code is an SCErrorCode, each of which specifies a slightly more +// precise class of errors within that subsystem. +// +// Error types and codes are not maximally precise; there is a tradeoff between +// precision and flexibility in the implementation, and the granularity here is +// chosen to be adequate for most purposes while not placing a burden on future +// system evolution and maintenance. When additional precision is needed for +// debugging, Soroban can be run with diagnostic events enabled. + union SCError switch (SCErrorType type) { case SCE_CONTRACT: From 65afa63b7f52c898143ebbe9541ef91fcf290ade Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 29 Aug 2023 14:03:40 -0700 Subject: [PATCH 112/112] rename txSOROBAN_RESOURCE_LIMIT_EXCEEDED to more general txSOROBAN_INVALID (#143) --- Stellar-transaction.x | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Stellar-transaction.x b/Stellar-transaction.x index 2e149cd..2e3c22b 100644 --- a/Stellar-transaction.x +++ b/Stellar-transaction.x @@ -1949,14 +1949,12 @@ enum TransactionResultCode txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction txINTERNAL_ERROR = -11, // an unknown error occurred - txNOT_SUPPORTED = -12, // transaction type not supported - txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed - txBAD_SPONSORSHIP = -14, // sponsorship not confirmed - txBAD_MIN_SEQ_AGE_OR_GAP = - -15, // minSeqAge or minSeqLedgerGap conditions not met - txMALFORMED = -16, // precondition is invalid - // declared Soroban resource usage exceeds the network limit - txSOROBAN_RESOURCE_LIMIT_EXCEEDED = -17 + txNOT_SUPPORTED = -12, // transaction type not supported + txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed + txBAD_SPONSORSHIP = -14, // sponsorship not confirmed + txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met + txMALFORMED = -16, // precondition is invalid + txSOROBAN_INVALID = -17 // soroban-specific preconditions were not met }; // InnerTransactionResult must be binary compatible with TransactionResult @@ -1987,7 +1985,7 @@ struct InnerTransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result; @@ -2034,7 +2032,7 @@ struct TransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result;