You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/stellar-contracts/accounts/authorization-flow.mdx
+67-94Lines changed: 67 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,30 @@
2
2
title: Authorization Flow
3
3
---
4
4
5
-
Authorization in smart accounts is determined by matching the current context against the account's context rules. Rules are gathered, ordered by recency, and evaluated until one satisfies the requirements. If a matching rule is found, its policies (if any) are enforced. Otherwise, authorization fails.
5
+
Authorization in smart accounts is determined by matching the current context against explicitly selected context rules. The caller supplies `context_rule_ids` in the `AuthPayload`, specifying exactly one rule per auth context. If the selected rule passes all checks, its policies (if any) are enforced. Otherwise, authorization fails.
6
+
7
+
## AuthPayload
8
+
9
+
The `AuthPayload` structure is passed as the signature data in `__check_auth`:
10
+
11
+
```rust
12
+
#[contracttype]
13
+
pubstructAuthPayload {
14
+
/// Signature data mapped to each signer.
15
+
pubsigners:Map<Signer, Bytes>,
16
+
/// Per-context rule IDs, aligned by index with `auth_contexts`.
17
+
pubcontext_rule_ids:Vec<u32>,
18
+
}
19
+
```
20
+
21
+
Each entry in `context_rule_ids` specifies the rule ID to validate against for the corresponding auth context (by index). Its length must equal `auth_contexts.len()`.
22
+
23
+
<Callouttype="warning">
24
+
The `context_rule_ids` are bound into the signed digest: `sha256(signature_payload || context_rule_ids.to_xdr())`. This prevents rule-selection downgrade attacks where an attacker could redirect a signature to a less restrictive rule.
25
+
</Callout>
6
26
7
27
## Detailed Flow
28
+
8
29
```mermaid
9
30
sequenceDiagram
10
31
participant User
@@ -14,105 +35,67 @@ sequenceDiagram
14
35
participant Verifier
15
36
participant Policy
16
37
17
-
User->>SmartAccount: Signatures
18
-
SmartAccount->>ContextRule: Match context<br/>(CallContract, Default, ...)
19
-
ContextRule->>ContextRule: Filter expired rules<br/>Sort newest first
20
-
21
-
loop Each rule until match
22
-
Note over ContextRule,DelegatedSigner: Built-in authorization <br/>for delegated signers
This triggers any necessary state changes such as updating spending counters, recording timestamps, emitting audit events, or modifying allowances.
98
+
Policy enforcement happens during rule evaluation. When `enforce()` is called, policies both validate conditions and perform state changes (updating spending counters, recording timestamps, emitting audit events, etc.).
116
99
117
100
Policy enforcement requires the smart account's authorization, ensuring that policies can only be enforced by the account itself.
- Authorization check: All policies enforceable → Success
159
-
3. Enforce: Update spending counters, emit events
137
+
1. Authenticate: Passkey signature verified
138
+
2. Look up Rule 2: Not expired, context type matches
139
+
3. Enforce: Spending limit policy validates and updates counters
160
140
4. Result: Authorized
161
141
162
-
If the spending limit had been exceeded, Rule 2 would fail and evaluation would continue to Rule 1 (which would also fail since the passkey doesn't match Alice or Bob).
Copy file name to clipboardExpand all lines: content/stellar-contracts/accounts/context-rules.mdx
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ List of authorized signers (maximum 15 per rule). Signers can be either delegate
32
32
For detailed documentation on signers, see [Signers](/stellar-contracts/accounts/signers-and-verifiers).
33
33
34
34
#### Policies
35
-
List of policy contracts (maximum 5 per rule). Policies act as enforcement modules that perform read-only prechecks and state-changing enforcement logic.
35
+
List of policy contracts (maximum 5 per rule). Policies act as enforcement modules that validate and enforce authorization constraints.
36
36
37
37
For detailed documentation on policies, see [Policies](/stellar-contracts/accounts/policies).
38
38
@@ -44,28 +44,29 @@ Each rule must contain at least one signer OR one policy. This enables pure poli
44
44
### Multiple Rules Per Context
45
45
Multiple rules can exist for the same context type with different signer sets and policies. This allows progressive authorization models where different combinations of credentials grant access to the same operations.
46
46
47
-
### Rule Precedence
48
-
Rules are evaluated in reverse chronological order (newest first). The first matching rule wins. This enables seamless permission updates: adding a new rule with different requirements immediately takes precedence over older rules for the same context.
47
+
### Explicit Rule Selection
48
+
The caller explicitly selects which rule to validate against for each auth context via `AuthPayload::context_rule_ids`. No automatic iteration or rule precedence is applied — the caller chooses the exact rule to use.
49
49
50
50
### Automatic Expiration
51
-
Expired rules are automatically filtered out during authorization evaluation.
51
+
Expired rules are rejected during authorization evaluation.
52
52
53
53
## Context Rule Limits
54
54
55
-
The framework enforces limits to keep costs predictable and encourage proactive context rule management (remove expired or non-valid rules):
55
+
The framework enforces per-rule limits to maintain predictability:
56
56
57
-
- Maximum context rules per smart account: 15
58
57
- Maximum signers per context rule: 15
59
58
- Maximum policies per context rule: 5
60
59
60
+
There is no upper limit on the total number of context rules per smart account.
61
+
61
62
## Authorization Matching
62
63
63
-
During authorization, the framework:
64
+
During authorization, the caller supplies `context_rule_ids` in the `AuthPayload`, one per auth context. For each (context, rule_id) pair:
64
65
65
-
1.Gathers all non-expired rules matching the context type plus default rules
66
-
2.Sorts rules by creation time (newest first)
67
-
3.Evaluates rules in order until one matches
68
-
4.Returns the first matching rule or fails if none match
66
+
1.The rule is looked up by its explicit ID
67
+
2.The rule is validated: must not be expired, context type must match
68
+
3.Signers are authenticated and policies enforced
69
+
4.Authorization succeeds if all checks pass, otherwise fails
69
70
70
71
For detailed documentation on the authorization flow, see [Authorization Flow](/stellar-contracts/accounts/authorization-flow).
0 commit comments