Skip to content

Commit

Permalink
Changes to auth-related XDR and a bit of cleanup. (#95)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dmkozh authored May 31, 2023
1 parent 48540f2 commit 077fe70
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 102 deletions.
9 changes: 4 additions & 5 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,13 @@ case SC_ADDRESS_TYPE_CONTRACT:
%struct SCVal;
%struct SCMapEntry;

const SCVAL_LIMIT = 256000;
const SCSYMBOL_LIMIT = 32;

typedef SCVal SCVec<SCVAL_LIMIT>;
typedef SCMapEntry SCMap<SCVAL_LIMIT>;
typedef SCVal SCVec<>;
typedef SCMapEntry SCMap<>;

typedef opaque SCBytes<SCVAL_LIMIT>;
typedef string SCString<SCVAL_LIMIT>;
typedef opaque SCBytes<>;
typedef string SCString<>;
typedef string SCSymbol<SCSYMBOL_LIMIT>;

struct SCNonceKey {
Expand Down
10 changes: 3 additions & 7 deletions Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ struct ContractCodeEntry {
ExtensionPoint ext;

Hash hash;
opaque code<SCVAL_LIMIT>;
opaque code<>;
};


Expand Down Expand Up @@ -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
};
}
151 changes: 61 additions & 90 deletions Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -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<SCVAL_LIMIT>;
};

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<MAX_OPS_PER_TX>;
// 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 */
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 077fe70

Please sign in to comment.