feat: create and join agent-wallet rules for a fundable address#1386
Conversation
|
Warning Review limit reached
More reviews will be available in 32 minutes and 8 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughReplaces single-step MAA with a rule-centric flow: new precompiles compute rules_hash and derive a 32-byte rule_id and 20-byte maa_address; migrations add rule, allowed_actions, instances, and events tables; tests rewritten to exercise maa_create_rule then maa_join and updated getters. ChangesModular Agent Address (MAA) System
Sequence Diagram(s) sequenceDiagram
participant Client
participant computeRulesHash as compute_rules_hash
participant deriveRuleID as derive_rule_id
participant deriveMAA as derive_maa_address
participant SQL as migrations / actions
Client->>computeRulesHash: (fee_mode, fee_bps, fee_flat, namespaces[], actions[], body_hashes[])
computeRulesHash->>computeRulesHash: normalize, dedupe, sort, encode RULES_PREIMAGE
computeRulesHash-->>Client: rules_hash (32B)
Client->>deriveRuleID: (restricted, rules_hash)
deriveRuleID->>deriveRuleID: validate, encode preimage
deriveRuleID-->>Client: rule_id (32B)
Client->>deriveMAA: (unrestricted, restricted, rule_id)
deriveMAA->>deriveMAA: encode preimage, keccak256, truncate 20B
deriveMAA-->>SQL: insert maa_instances / use maa_address in maa_join
SQL-->>Client: confirmation, events (CREATE_RULE / JOIN)
🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Time Submission Status
You can submit time with the command. Example: See available commands to help comply with our Guidelines. |
d2c6f48 to
8b311b4
Compare
|
@holdex pr submit-time 4h |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/migrations/048-maa.sql (2)
146-151: 💤 Low valueAdd explicit validation for
fee_flat >= 0.
fee_bpsis explicitly validated (line 149-151) butfee_flatrelies solely on the table's CHECK constraint. While functionally correct, a constraint-violation error is less informative than a custom message. Add validation for consistency with the other fee parameter.Suggested validation
if $fee_bps < 0 OR $fee_bps > 10000 { ERROR('fee_bps must be between 0 and 10000 (10000 = 100%)'); } + if $fee_flat < 0 { + ERROR('fee_flat must be non-negative'); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/migrations/048-maa.sql` around lines 146 - 151, Add an explicit validation for fee_flat similar to fee_bps: in the same validation block (near the checks referencing $fee_mode and $fee_bps) add a guard that checks if $fee_flat is negative and raise a clear ERROR like "fee_flat must be >= 0"; update the function/migration around the existing checks so the new validation runs before relying on the table CHECK constraint.
329-329: 💤 Low valueAddress parsing assumes
0xprefix without validation.
substring(LOWER($agent), 3, 40)assumes the input has a0xprefix. Malformed input (missing prefix, wrong length, non-hex characters) would silently produce incorrect bytes or empty results rather than a clear error.Consider validating the input format or documenting the expected format clearly in the action signature. Alternatively, handle both prefixed and non-prefixed formats.
Also applies to: 350-350
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/migrations/048-maa.sql` at line 329, The current assignment to $agent_bytes using decode(substring(LOWER($agent), 3, 40), 'hex') assumes a "0x" prefix and valid hex of exact length; update the procedure to explicitly validate and normalize $agent before decoding: accept both "0x"-prefixed and non-prefixed values by stripping a leading "0x" if present, assert the remaining string length matches the expected hex length, and assert it matches a hex regexp (e.g. only 0-9a-f); if validation fails, RAISE EXCEPTION with a clear message; then use decode(normalized_agent_hex, 'hex') to set $agent_bytes. Apply the same validation/normalization for the other occurrence that currently uses substring/LOWER($agent).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/migrations/048-maa.sql`:
- Around line 146-151: Add an explicit validation for fee_flat similar to
fee_bps: in the same validation block (near the checks referencing $fee_mode and
$fee_bps) add a guard that checks if $fee_flat is negative and raise a clear
ERROR like "fee_flat must be >= 0"; update the function/migration around the
existing checks so the new validation runs before relying on the table CHECK
constraint.
- Line 329: The current assignment to $agent_bytes using
decode(substring(LOWER($agent), 3, 40), 'hex') assumes a "0x" prefix and valid
hex of exact length; update the procedure to explicitly validate and normalize
$agent before decoding: accept both "0x"-prefixed and non-prefixed values by
stripping a leading "0x" if present, assert the remaining string length matches
the expected hex length, and assert it matches a hex regexp (e.g. only 0-9a-f);
if validation fails, RAISE EXCEPTION with a clear message; then use
decode(normalized_agent_hex, 'hex') to set $agent_bytes. Apply the same
validation/normalization for the other occurrence that currently uses
substring/LOWER($agent).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6ec2e5e1-76c3-49bc-9f11-3cbeda53a549
📒 Files selected for processing (5)
extensions/tn_utils/maa.goextensions/tn_utils/maa_test.goextensions/tn_utils/precompiles.gointernal/migrations/048-maa.sqltests/streams/maa/create_test.go
8b311b4 to
8dcfead
Compare
resolves: https://github.com/truflation/website/issues/4035
Summary by CodeRabbit
New Features
Bug Fixes / Validation
Tests