Skip to content

Profile the owner-authorization check's per-call resource cost at the maximum owner count #353

Description

@thegreatfeez

Smart Contract — Optimisation

Summary

Every authorized call into the contract (approve, revoke, execute, and each governance proposal creation) checks the caller against the owner-weight map before doing anything else. This issue asks a contributor to measure exactly how much CPU and memory budget that check consumes at the maximum owner count, and confirm the contract stays comfortably inside Soroban's per-invocation resource limits.

Background

The owner-authorization check in contracts/accord/src/lib.rs loads the entire OWNERS persistent entry (an Address-to-u32 weight map) on every call and looks up the caller's weight from it. Because this runs at the start of nearly every entrypoint, its cost scales with the deserialization size of the owner map, which grows with the number of owners up to the MAX_OWNERS cap of 20. No benchmark currently exists showing what this actually costs in Soroban's CPU instruction and memory budget at that upper bound.

What Needs to Be Done

  1. Write a benchmark test that calls env.budget().reset_unlimited(), initializes a contract instance with the maximum of 20 owners, and then measures CPU instructions and memory consumed by a representative authorized call (for example, approve).
  2. Compare the measured cost against a small-owner-count baseline (for example, 1 owner) to quantify how much of the cost is attributable specifically to the owner-map lookup as the owner set grows.
  3. Confirm the measured cost sits well within Soroban's published per-transaction resource limits, leaving headroom for the rest of the call's logic.
  4. Record the benchmark methodology and results — including the specific env.budget() output — in ARCHITECTURE.md, alongside the existing storage cost documentation.
  5. If the measurement reveals the cost is unexpectedly close to the network's resource limits, flag this in the write-up as a follow-up concern rather than attempting a fix as part of this issue.

Acceptance Criteria

  • A test exists that measures CPU instructions and memory for an authorized call at MAX_OWNERS = 20 using env.budget().
  • The measured cost is compared against a low-owner-count baseline to isolate the cost attributable to the owner lookup.
  • The benchmark results and methodology are documented in ARCHITECTURE.md.
  • The write-up states explicitly whether the cost stays within Soroban's per-invocation resource budget, with the numbers to back it up.

Files to Look At

  • contracts/accord/src/lib.rs — the owner-authorization helper (loads the full owner-weight map on every authorized call) that this issue measures
  • contracts/accord/src/test.rs — existing tests already call env.budget().reset_unlimited(), a useful reference for wiring up the benchmark
  • docs/ARCHITECTURE.md — where the benchmark results should be documented

Difficulty: Medium

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions