Skip to content

Commit

Permalink
XDR changes for Auth Next.
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dmkozh committed Jan 30, 2023
1 parent d2acf41 commit 54f86dd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
5 changes: 2 additions & 3 deletions Stellar-contract-spec.x
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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:
Expand All @@ -273,7 +288,9 @@ case SCO_BYTES:
opaque bin<SCVAL_LIMIT>;
case SCO_CONTRACT_CODE:
SCContractCode contractCode;
case SCO_ACCOUNT_ID:
AccountID accountID;
case SCO_ADDRESS:
SCAddress address;
case SCO_NONCE_KEY:
SCAddress nonceAddress;
};
}
3 changes: 2 additions & 1 deletion Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
32 changes: 31 additions & 1 deletion Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54f86dd

Please sign in to comment.