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