refactor(contracts): standardize error codes via shared trivela-contract-errors crate - #1395
Merged
joelpeace48-cell merged 3 commits intoSep 25, 2026
Conversation
no_std crate reserving numeric error-code ranges per contract (rewards 1-99, campaign 100-199, nullifiers 200-299, badges/voting reserved, shared 900-999) with domain_of() lookup and an assert_codes_in_domain() test helper. Added to the workspace. Refs FinesseStudioLab#1192
…anges Nullifier registry codes 1-3 collided with rewards 1-3; renumber to 200-202. Rewards and campaign codes are unchanged (already deployed and mapped client-side). Each contract gets an error_codes_test asserting every Error variant stays inside its reserved range. Closes FinesseStudioLab#1192
|
@gideononiru Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a shared
trivela-contract-errorscrate with structured numeric error-code ranges, and makes every workspace contract conform to it. After this, anError(Contract, #N)identifies both the failing contract and the reason without extra context.Error-code ranges
Changes
contracts/errors(trivela-contract-errors,no_std, no Soroban dependency), added to the workspace:ContractDomainenum withrange(),contains()andname();domain_of(code): aconst fnthat resolves which contract owns a code;assert_codes_in_domain(domain, codes): a test helper;AlreadySpent,UnauthorizedandNotInitializedmove from 1/2/3 to 200/201/202. The old values collided with the rewards contract'sOverflow,InsufficientBalanceandUnauthorized(1/2/3), so anError(Contract, #2)was ambiguous. No backend or frontend code maps nullifier codes.frontend/src/lib/contractErrors.jsand the backend mappings only cover rewards and campaign, so nothing off-chain changes.error_codes_test.rsin rewards, campaign and nullifiers lists everyErrorvariant and asserts each one is in its range. They're generated from the enums: 69, 27 and 3 variants. The crate is a dev-dependency only, so contract WASM size and ABI are unaffected.Cargo.lockrecords the new crate (additive only).Backward compatibility
rewards::merkle::MerkleVerifyError(1–2) is an internalResulttype used in tests, not a contract-returned error, so it's left as is.Not verified (raised early on request)
soroban-sdk25.1 dependencies, socargo testnever started. CI needs to confirm compilation and tests.Closes refactor(contracts): Standardize error codes across all Rust smart contracts #1192
Closes feat(contracts): Implement claim delegation capability (proxy claim for gasless user experience) #1191
Closes feat(contracts): Implement proof-based merkle tree reward distribution #1193
Closes feat(contracts): Implement automated contract upgradeability timelock governance #1194