Skip to content

Conversation

@alberto-crossmint
Copy link
Contributor

Add comprehensive event emission for auth-related failures

Summary

This PR adds comprehensive event emission for authentication-related failures throughout the stellar smart account contract, as requested by @alberto-crossmint. When auth functions fail for any reason, the contract now emits detailed events before returning errors, making it easier to parse and understand failure reasons.

Key Changes:

  • Added 4 new event structures: AuthCheckFailedEvent, SignerOperationFailedEvent, PolicyValidationFailedEvent, SignatureVerificationFailedEvent
  • Events are emitted before errors are returned in: __check_auth, signer management functions (add_signer, update_signer, revoke_signer), policy validation, signature verification, and constructor validation
  • Added helper functions to convert Error enums to numeric codes and string messages for Soroban compatibility
  • All events include contextual information like error type, signer key (when applicable), and operation context

Technical Notes:

  • Event structures use #[contracttype] for Soroban serialization compatibility
  • Error types are mapped to u32 codes (1-11) with string messages for easy parsing
  • Signer keys are represented as simple type strings ("ed25519_key", "secp256r1_key") due to Soroban environment limitations with format! macro
  • All existing tests pass (77 tests, 0 failures)

Review & Testing Checklist for Human

  • Verify event structure fields provide sufficient detail for your intended parsing use case (especially simplified signer key representation)
  • Test event emission in failure scenarios by triggering auth failures and confirming events are actually emitted with correct data
  • Validate error code mappings in error_to_code_and_message() function are accurate and complete for all Error enum variants
  • Confirm no functional regressions by testing normal auth flows still work as expected
  • Review signer key representation - simplified to type strings due to technical limitations, verify this meets requirements

Recommended Test Plan:

  1. Deploy contract and trigger various auth failures (invalid signatures, missing signers, policy violations)
  2. Monitor emitted events to verify they contain expected error codes, messages, and context
  3. Test normal auth flows to ensure no regressions
  4. Verify event parsing works as intended for your downstream systems

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    A["contracts/smart-account/src/account.rs"]:::major-edit
    B["contracts/smart-account/src/lib.rs"]:::minor-edit
    C["contracts/smart-account/src/auth/policy/time_based.rs"]:::minor-edit
    D["contracts/smart-account/src/auth/policy/allow_list.rs"]:::minor-edit
    E["contracts/smart-account/src/auth/signers/ed25519.rs"]:::minor-edit
    F["contracts/smart-account/src/auth/signers/secp256r1.rs"]:::minor-edit
    
    A --> |"exports events"| B
    A --> |"calls policy validation"| C
    A --> |"calls policy validation"| D
    A --> |"calls signature verification"| E
    A --> |"calls signature verification"| F
    
    A --> |"emits events on failure"| G["Event Emission Points:<br/>- __check_auth<br/>- add_signer<br/>- update_signer<br/>- revoke_signer<br/>- __constructor"]:::context
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit
        L3["Context/No Edit"]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB
classDef context fill:#FFFFFF
Loading

Notes

  • Session Info: Requested by Alberto García (@alberto-crossmint) - Devin Session
  • Limitation: Signer key representation had to be simplified due to Soroban environment not supporting format! macro for hex encoding
  • Event Topics: Events use consistent topic patterns like ("auth", "failed"), ("signer", "failed"), ("policy", "failed") for easy filtering
  • Error Codes: Numeric error codes (1-11) map to specific Error enum variants for programmatic parsing

devin-ai-integration bot and others added 2 commits July 24, 2025 00:24
- Add event structures for auth check failures, signer operations, policy validation, and signature verification
- Emit events before returning errors in __check_auth, signer management, policy validation, and signature verification functions
- Include detailed context (error type, signer key, operation context) for easy parsing
- Follow existing event emission patterns using env.events().publish()
- Convert Error enum and SignerKey to Soroban-compatible types (u32 codes and strings)
- Add helper functions for error and signer key conversion to maintain consistency

Co-Authored-By: Alberto Garc\u00EDa <[email protected]>
Co-Authored-By: Alberto Garc\u00EDa <[email protected]>
@devin-ai-integration
Copy link
Contributor

Original prompt from Alberto:

in the smart account contract, emit events when some the check with function fails for any reason

You only need to look in the following repo: Crossmint/stellar-smart-account

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits July 24, 2025 00:29
- Break long lines in error_to_code_and_message calls to comply with rustfmt
- Simplify signer_key_to_string match arms to single-line format
- Address all formatting violations identified by cargo fmt --check

Co-Authored-By: Alberto Garc\u00EDa <[email protected]>
- Prefix unused variables with underscores to satisfy clippy lint checks
- Resolves clippy errors that were causing CI lint failures

Co-Authored-By: Alberto Garc\u00EDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants