Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions core/cap-0090.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: Custom signature payload for account contracts
Working Group:
Owner: Dmytro Kozhevin <@dmkozh>
Authors: Dmytro Kozhevin <@dmkozh>
Consulted: Boyan <@brozorec>, Leigh McCulloch <@leighmcculloch>
Consulted: Boyan <@brozorec>, Leigh McCulloch <@leighmcculloch>, Tyler van der Hoeven <@kalepail>
Status: Draft
Created: 2026-10-21
Discussion: https://github.com/orgs/stellar/discussions/2049
Expand All @@ -13,7 +13,7 @@ Protocol version: 31

## Simple Summary

Add an option for users to pass an arbitrary value to the custom account contract's signature payload, as well as a way for an account contract to access this value during authorization.
Add an option for users to pass an arbitrary value to the custom account contract's signature payload, and a ways for an account contract to access this value during authorization along with the authorized address.

## Working Group

Expand All @@ -27,6 +27,10 @@ While the built-in payload is sufficient to cover context that is *external* to

Internal context is not necessary for every custom account, but it increases the account developer toolset significantly. Custom, account-specific payload is a natural extension to the existing protocol-defined signature payload, and it arguably was an oversight in the protocol design to not include it from the inception.

Besides the lack of custom payload, currently custom accounts are not always aware of the address that is being authorized (i.e. the address `require_auth` has been called for). Without delegation that address always corresponds to the account's own address, but with delegation it could be an arbitrary address of the delegator account. Without the address of the authorized account custom accounts are not able to implement some more fine-grained and secure policies. For example, currently it is not possible to create a policy that allows (or disallows) using a specific key when the account serves is the delegate of another account. Another example would be a policy for authorizing admin operations that typically don't include the address of the admin in the authorization context: the custom account is only able to define a policy that allows a key to perform an admin operation, but is not able to tell which admin is performing it.

Similarly to the internal context, the authorized address does not need to be utilized by every custom account, but providing it increases the custom account implementation flexibility and allows developers building more secure authorization policies.

### Goals Alignment

This CAP is aligned with the following Stellar Network Goals:
Expand All @@ -37,9 +41,9 @@ This CAP is aligned with the following Stellar Network Goals:

This CAP introduces two new kinds of Soroban credentials: `SOROBAN_CREDENTIALS_ADDRESS_V3` and `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` that respectively extend `SOROBAN_CREDENTIALS_ADDRESS_V2` and `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES` with the new optional `customPayload` field. `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` also uses `SorobanDelegateSignatureV2` that has a `customPayload` field as well for delegate-specific custom payload.

When custom payload is provided, a new signature preimage envelope `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD` has to be used in order to include the custom payload into the signature payload.
A new signature preimage envelope `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD` has to be used for these new credential types.

In order to handle custom payload in the account implementation, `__check_auth` function can now take the fourth argument that represents the account's custom payload provided in the credentials. Custom accounts that don't accept the fourth argument will not be able to authorize credentials with custom payload.
`__check_auth` function can now take five arguments instead of three: the fourth argument is the address that is being authorized, and the fifth argument represents the account's custom payload provided in the credentials. Custom accounts that don't accept five arguments will not be able to authorize credentials with custom payload or retrieve the authorized address.

## Specification

Expand Down Expand Up @@ -142,7 +146,7 @@ index 11cacd7..621bb1c 100644
+ // ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS or
+ // ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD can be used.
+ Hash sorobanAuthPayloadHash;
+ SCVal customPayload;
+ SCVal* customPayload;
+ } sorobanAuthorizationWithCustomPayload;
};

Expand All @@ -153,25 +157,27 @@ index 11cacd7..621bb1c 100644

#### New credential types

The CAP introduces `SOROBAN_CREDENTIALS_ADDRESS_V3` and credential types.
The CAP introduces `SOROBAN_CREDENTIALS_ADDRESS_V3` and `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` credential types.

`SOROBAN_CREDENTIALS_ADDRESS_V3` extends the existing `SOROBAN_CREDENTIALS_ADDRESS_V2` with an additional `customPayload` field that is an optional arbitrary `SCVal` passed to the respective custom account.

`SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` extends the existing `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES` credential type. Credentials with delegates include the optional common `customPayload` through the `addressCredentials` of the top-level address, as well as per-delegate custom payload in `SorobanDelegateSignatureV2` `customPayload` optional field. Custom payloads are inherited by all the nested delegates of the top-level address or a given delegate via signature payloads, i.e. `customPayload` of `addressCredentials` is signed by both the top-level address and all the nested delegates, while a delegate's `customPayload` is signed by that delegate and all its `nestedDelegates`. The preimage generation logic is described in the following section.

#### Signature preimage for custom payload

A new signature preimage type `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD` is added to `HashIDPreimage` union. This preimage is used for computing signature payloads that cover the *set* `customPayload` field in the credentials. This preimage allows for recursive combination via `sorobanAuthPayloadHash`:
A new signature preimage type `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD` is added to `HashIDPreimage` union. This preimage is used for computing signature payloads for credentials that contain `customPayload` field. This preimage allows for recursive combination via `sorobanAuthPayloadHash`:

- For `SOROBAN_CREDENTIALS_ADDRESS_V3` or `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` `addressCredentials` that have `customPayload` set, the expected signature payload is `SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD(sorobanAuthPayloadHash=SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS(...), customPayload)))`, where `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS` is computed based on the credential inputs and network id as usual. If `customPayload` is not set, `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS` preimage should be used directly.
- Notice that legacy unsafe `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION` preimage is never used for computing signature payloads for the new credential types.
- For a delegate of `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` that has `customPayload` set, the expected signature payload is `SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD(sorobanAuthPayloadHash=parentSignaturePayload, customPayload)))`, where `parentSignaturePayload` is SHA256 of signature payload of the delegate's parent (`addressCredentials` for the top-level delegate, or the enclosing delegate for `nestedDelegates`). If `customPayload` is not set for the delegate, the hashed parent's payload should be signed directly.
- For `SOROBAN_CREDENTIALS_ADDRESS_V3` that have `customPayload` set, the expected signature payload is `SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD(sorobanAuthPayloadHash=SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS(...), customPayload)))`, where `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS` is computed based on the credential inputs and network id as usual. If `customPayload` is not set, `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS` preimage should be used directly.
- For `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` `addressCredentials`, the expected signature payload is always `SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD(sorobanAuthPayloadHash=SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS(...), customPayload)))`, where `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS` is computed based on the credential inputs and network id as usual, regardless of whether `customPayload` is set or not.
- For a delegate of `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` the expected signature payload is `SHA256(HashIDPreimage::ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_CUSTOM_PAYLOAD(sorobanAuthPayloadHash=parentSignaturePayload, customPayload)))`, where `parentSignaturePayload` is SHA256 of signature payload of the delegate's parent (`addressCredentials` for the top-level delegate, or the enclosing delegate for `nestedDelegates`).

#### Custom payload dispatch rules

The reserved `__check_auth` contract function is now allowed to receive 3 or 4 arguments, instead of exactly 3 arguments in the current protocol.
The reserved `__check_auth` contract function is now allowed to receive 3 or 5 arguments, instead of exactly 3 arguments in the current protocol.

The fourth argument is always used for receiving the address that is being authorized from the host, i.e. the address for which `require_auth/require_auth_for_args` that spawned this `__check_auth` call has been called. The fourth argument is not passed if the `__check_auth` is declared with only 3 arguments.

The fourth argument is used for receiving the `customPayload` from the host. The value of `customPayload` argument is going to be a `VecObject` with the following contents:
The fifth argument is used for receiving the `customPayload` from the host. The value of `customPayload` argument is going to be a `VecObject` with the following contents:
- Empty vector if `customPayload` is not set in the credentials or `SorobanDelegateSignatureV2` of the delegate.
- A single-element vector with the only element being the `Val`-converted `customPayload` `SCVal` from the credentials or `SorobanDelegateSignatureV2` of the delegate.

Expand All @@ -182,15 +188,15 @@ This CAP does not change the host authentication flow: it will still follow [CAP
- If the legacy credential type is used:
- For G-account addresses, no changes
- For `__check_auth` with 3 arguments, no changes
- For `__check_auth` with 4 arguments, pass empty vector as the fourth argument.
- For `__check_auth` with 5 arguments, pass empty vector as the fifth argument.
- If the new credential type (or `SorobanDelegateSignatureV2` for delegate's `__check_auth` call) is used with unset `customPayload`:
- For G-account addresses, no changes
- For `__check_auth` with 3 arguments, no changes
- For `__check_auth` with 4 arguments, pass empty vector as the fourth argument.
- For `__check_auth` with 5 arguments, pass empty vector as the fifth argument.
- If the new credential type (or `SorobanDelegateSignatureV2` for delegate's `__check_auth` call) is used with set `customPayload`:
- For G-account addresses, return an error and cause guest to panic (since `customPayload` is not supported for G-account addresses).
- For `__check_auth` with 3 arguments, return an error and cause guest to panic (since the account is not able to handle `customPayload`).
- For `__check_auth` with 4 arguments, pass a single-element vector with the `Val`-converted `customPayload` `SCVal` as the fourth argument.
- For `__check_auth` with 5 arguments, pass a single-element vector with the `Val`-converted `customPayload` `SCVal` as the fifth argument.

## Design Rationale

Expand All @@ -213,10 +219,14 @@ While this may slightly reduce the downstream integration surface at the XDR API

### Custom payload and delegated signers

Delegated signers introduced in [CAP-0071](./cap-0071.md) are supposed to act 'as if' they were authorizing exactly the same call as their parent address. Custom payload is an exception to this rule, as by definition it represents the internal context of the parent account. The delegates generally do not know what that context means and thus can't make a meaningful decision based on it. They still do sign the parent's custom payload though, as it is hashed into the expected signature preimage.
Delegated signers introduced in [CAP-0071](./cap-0071.md) are supposed to act 'as if' they were authorizing exactly the same call as their parent address. Custom payload is an exception to this rule, as by definition it represents the internal context of the parent account. The delegates generally do not know what that context means and thus can't make a meaningful decision based on it. They still do sign the parents' custom payload though, as it is hashed into the expected signature preimage.

Delegated signers are also allowed to have their own custom payload that they can interpret. While this increases the complexity of the CAP to a degree, it allows for more flexible delegation schemes, e.g. combining the top-level account with context rules in custom payload with a delegate that has a sequential nonce as its own custom payload.

### Signing the unset custom payloads for delegated signers

The signature preimage for `SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES_V2` credentials always includes the custom payload field even when it is not set. This increases the complexity of the preimage building a bit (as if you use V2 credentials without a custom payload, you still need to hash the signature preimage twice), however it is necessary to prevent preimage malleability: otherwise, the same custom payload that is set either for the parent or for its delegate would look identical.

### Custom payload argument format

The CAP uses somewhat unusual format for the custom payload argument, specifically, a 0 or 1 argument vector object. This is done in order to disambiguate between the absence of a custom payload and the presence of `SCVal::VOID` payload, both of which would map to `Val::Void` (or `None` from the guest contract point of view) if we used a more intuitive `Option<Val>` type on the guest side.
Expand All @@ -233,7 +243,7 @@ There are no backwards incompatibilities introduced by this CAP.

### Resource Utilization

The new host functions are going to be metered using the existing metering primitives. No other resource utilization changes are expected.
Host needs to perform some additional work according to the CAP, and that work is going to be metered using the existing metering primitives. No new cost types are introduced.

## Security Concerns

Expand Down
Loading