Skip to content

Commit c248e6c

Browse files
committed
add mermaid charts and apply suggestions
1 parent 8de72d6 commit c248e6c

File tree

4 files changed

+88
-13
lines changed

4 files changed

+88
-13
lines changed

content/stellar-contracts/accounts/authorization-flow.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@ title: Authorization Flow
55
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.
66

77
## Detailed Flow
8+
```mermaid
9+
sequenceDiagram
10+
participant User
11+
participant SmartAccount
12+
participant ContextRule
13+
participant DelegateSigner
14+
participant Verifier
15+
participant Policy
16+
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,DelegateSigner: Built-in authorization <br/>for delegate signers
23+
ContextRule->>DelegateSigner: require_auth_for_args()
24+
DelegateSigner-->>ContextRule: Authorized
25+
Note over ContextRule,Verifier: Signature verification for external signers
26+
ContextRule->>Verifier: verify()
27+
Verifier-->>ContextRule: Valid
28+
Note over ContextRule,Policy: Policy pre-checks
29+
ContextRule->>Policy: can_enforce()
30+
Policy-->>ContextRule: True/False
31+
32+
alt All checks pass
33+
ContextRule->>Policy: enforce()
34+
Policy->>Policy: Update state
35+
ContextRule-->>SmartAccount: ✓ Authorized
36+
else Any check fails
37+
ContextRule->>ContextRule: Try next rule
38+
end
39+
end
40+
41+
SmartAccount-->>User: Success
42+
```
843

944
### 1. Rule Collection
1045

content/stellar-contracts/accounts/context-rules.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ graph TD
8787
SA --- CR2
8888
SA --- CR3
8989
SA --- CR4
90+
91+
style SA fill:#E8E8E8,stroke:#333,stroke-width:2px
9092
```
9193

9294

content/stellar-contracts/accounts/signers-and-verifiers.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ graph TD
3939
C1 --> SA2
4040
G2 --> SA2
4141
42-
style G1 fill:#6B9BD1,stroke:#333,stroke-width:2px
43-
style G2 fill:#6B9BD1,stroke:#333,stroke-width:2px
44-
style C1 fill:#F4D03F,stroke:#333,stroke-width:2px
42+
style G1 fill:#6B9BD1
43+
style G2 fill:#6B9BD1
44+
style C1 fill:#F4D03F
4545
style SA1 fill:#E8E8E8,stroke:#333,stroke-width:2px
4646
style SA2 fill:#E8E8E8,stroke:#333,stroke-width:2px
4747
style SA3 fill:#E8E8E8,stroke:#333,stroke-width:2px
@@ -100,9 +100,9 @@ graph LR
100100
TC --> |"require_auth()"| SA1
101101
SA1 --> |"require_auth_for_args()"| G1
102102
103-
style G1 fill:#6B9BD1,stroke:#333,stroke-width:2px
103+
style G1 fill:#6B9BD1
104104
style SA1 fill:#E8E8E8,stroke:#333,stroke-width:2px
105-
style TC fill:#C8D9A3,stroke:#333,stroke-width:2px
105+
style TC fill:#C8D9A3
106106
```
107107

108108
When simulating this transaction, the following authorization entry is returned. Note that `"auth"` contains a single element and the delegated signer address (G-account) is not present at all:
@@ -376,9 +376,9 @@ graph LR
376376
TC --> |"require_auth()"| SA1
377377
SA1 --> |"verify()"| V
378378
379-
style V fill:#16D9AA1,stroke:#333,stroke-width:2px
379+
style V fill:#16D9AA1
380380
style SA1 fill:#E8E8E8,stroke:#333,stroke-width:2px
381-
style TC fill:#C8D9A3,stroke:#333,stroke-width:2px
381+
style TC fill:#C8D9A3
382382
```
383383

384384
In contrast to `Delegated` signers, constructing the auth entry for an `External` signer is straightforward:
@@ -501,7 +501,7 @@ The trait uses associated types to allow different verifiers to define their own
501501

502502
### Advantages of the Verifier Pattern
503503

504-
**No Setup Costs**: Once a verifier is deployed, new keys can be used immediately without any on-chain setup or deployment expenses. Users simply reference the verifier address and provide their public key when creating signers.
504+
**No Setup Costs**: Once a verifier is deployed, new keys can be used immediately without any on-chain setup. Users simply reference the verifier address and provide their public key when creating signers.
505505

506506
**Cryptographic Flexibility**: The verifier pattern supports diverse cryptographic schemes from standard curves to emerging authentication methods like zero-knowledge proofs and email-based signing. Developers can implement custom verifiers for specialized cryptographic schemes.
507507

content/stellar-contracts/accounts/smart-account.mdx

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ title: Smart Accounts
44

55
[Source Code](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/accounts)
66

7-
Smart accounts in Soroban are contracts that manage the composition of authorization intents from multiple sources, such as policies and signing keys from different cryptographic curves. They enable flexible combinations and allow multiple authorization mechanisms to work together seamlessly.
7+
Smart accounts are contracts that manage the composition of authorization intents coming from multiple sources, such as policies, signing keys from different cryptographic curves or other Soroban accounts. This lays the ground for flexible combinations where multiple authorization mechanisms work together seamlessly.
88

99
## Overview
1010

11-
The [accounts](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/accounts) package provides a comprehensive smart account framework for Soroban, enabling flexible, programmable authorization. Instead of hard-coding signature checks, smart accounts organize authorization as a composition of context rules, signers, and policies.
11+
The [accounts](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/accounts) package provides a comprehensive smart account framework, enabling programmable authorization. Rather than hard-coding signature checks directly into the account contract, this framework organizes authorization as a composition of three core elements: context rules, signers, and policies.
1212

13-
Smart accounts in Soroban implement `CustomAccountInterface` and define authorization as data and behavior that can evolve over time. The framework is context-centric: it distinguishes who is allowed to act (signers), what they are allowed to do (scope), and how those permissions are enforced (policies).
13+
To achieve this composability, smart accounts implement the `CustomAccountInterface` and define authorization as data and behavior that can evolve over time. The framework takes a context-centric approach, separating three distinct concerns: who is allowed to act (signers), what they are allowed to do (scope or context rules), and how those permissions are enforced (policies).
1414

15-
The framework externalizes some parts of the logic and state to separate contracts. Policies are external contracts that manage enforcement rules and can maintain their own state, while verifiers are external contracts that handle signature validation logic. This separation of concerns enables modularity and flexibility, and allows multiple smart accounts to share well-audited verification and policy logic. Protocol 23 improvements make this modular design practical, with substantially cheaper cross-contract calls enabling efficient composition of multiple external components.
15+
This separation is made practical by externalizing parts of the logic and state to dedicated contracts. Specifically, policies are external contracts that enforce constraints and can maintain their own state, while verifiers are external contracts that handle signature validation logic. This modular architecture enables flexibility and allows multiple smart accounts to share well-audited verification and policy logic. The Protocol 23 improvements make this design efficient, with substantially cheaper cross-contract calls enabling practical composition of multiple external contracts.
1616

1717
## Core Components
1818

@@ -22,13 +22,51 @@ The framework separates three distinct concerns:
2222
- **Who** (Signers): Identifies the authorized entities
2323
- **How** (Policies): Enforces business logic and constraints
2424

25+
```mermaid
26+
graph LR
27+
P1((Policy)) --- CR1
28+
P2((Policy)) --- CR2
29+
P2((Policy)) --- CR3
30+
P3((Policy)) --- CR3
31+
32+
subgraph SA[Smart Account]
33+
CR1[Context Rule]
34+
CR2[Context Rule]
35+
CR3[Context Rule]
36+
end
37+
38+
S1["Delegated Signer<br/><i><small>G-account</small></i>"]
39+
S2["Delegated Signer<br/><i><small>G-account</small></i>"]
40+
S3["Delegated Signer<br/><i><small>C-account</small></i>"]
41+
S4["External Signer<br/><i><small>Verifier Contract || Pubkey</small></i>"]
42+
S5["External Signer<br/><i><small>Verifier Contract || Pubkey</small></i>"]
43+
44+
CR1 --- S1
45+
CR1 --- S2
46+
CR2 --- S3
47+
CR3 --- S4
48+
CR3 --- S5
49+
50+
style SA fill:#E8E8E8,stroke:#333,stroke-width:2px
51+
style S1 fill:#6B9BD1
52+
style S2 fill:#6B9BD1
53+
style S3 fill:#F4D03F
54+
style S4 fill:#A9DA9B
55+
style S5 fill:#A9DA9B
56+
```
57+
2558
### Context Rules
2659
Context rules function like routing tables for authorization. For each context, they specify scope, lifetime, and the conditions (signers and policies) that must be satisfied before execution proceeds.
2760

61+
#### Examples
62+
1. Subscription: A dapp public key (signer) can withdraw 100 USDC every month (policy) for one year (lifetime)
63+
2. Deployment: 2-of-3 (policy) Ed25519 keys (signers) can deploy a new contract
64+
3. Vote: 3-of-3 P256 keys (signers) can cast a vote at a specific voting contract
65+
2866
For detailed documentation, see [Context Rules](/stellar-contracts/accounts/context-rules).
2967

3068
### Signers and Verifiers
31-
Signers define who can authorize operations. The framework supports both delegated signers (any Soroban address) and external signers that use specialized verifier contracts for signature validation. Verifiers are cryptographic oracles that validate signatures for external signers.
69+
Signers define who can authorize operations. The framework supports both **delegated** signers (any Soroban address) and **external** signers that use specialized verifier contracts for signature validation. Verifiers can be seen as some sort of cryptographic oracles that validate signatures for external signers.
3270

3371
For detailed documentation, see [Signers and Verifiers](/stellar-contracts/accounts/signers-and-verifiers).
3472

0 commit comments

Comments
 (0)