From 54f86ddbae99a3ef16a1e881ccf56b22510cdcff Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 1 Dec 2022 13:20:49 -0500 Subject: [PATCH] XDR changes for Auth Next. - 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