Skip to content

perf(audit_registry): optimize anchor payload storage and gas#3

Open
devnWisdom wants to merge 339 commits into
mainfrom
feat/optimize-anchor-storage-552
Open

perf(audit_registry): optimize anchor payload storage and gas#3
devnWisdom wants to merge 339 commits into
mainfrom
feat/optimize-anchor-storage-552

Conversation

@devnWisdom

Copy link
Copy Markdown
Owner

Summary

Reduces the persistent ledger entry size for each anchor() call from 36 bytes → 4 bytes (88% reduction) by eliminating a redundant field from the stored value.

Problem

anchor() previously stored a full AuditAnchor struct as the persistent entry value:

AuditAnchor {
    reading_hash: BytesN<32>,   // 32 bytes — already the storage KEY
    anchored_at_ledger: u32,    // 4 bytes
}
// total: 36 bytes per entry

The reading_hash field is identical to the key (DataKey::Anchor(reading_hash)), so it was pure duplication.

Change

Store only the u32 ledger sequence as the entry value (4 bytes). verify() reconstructs the full AuditAnchor from key + stored ledger seq at read time — no extra I/O.

Gas impact

Field Before After Saving
Entry value size 36 B 4 B −32 B / anchor (−88%)
write_bytes fee higher lower proportional to fee schedule

At scale (e.g. 10 000 anchors/day) this materially reduces XLM operating costs.

Compatibility

  • Public API unchanged — verify() still returns Option<AuditAnchor>
  • All existing tests pass without modification

Closes AnnabelJoe#552

magaret457 and others added 30 commits May 29, 2026 10:20
…-smoke-governance-tests

Add contract docs, backup recovery guide, smoke test, and governance tests
- Hardware requirements (Ed25519 key storage, HSM/TPM recommendations)
- API integration steps (key gen, hash, sign, submit)
- Reference scripts documented
- Certification checklist for new meter models
- Contact information for integration support

Closes AnnabelJoe#320
…belJoe#306)

- npm: weekly on Monday, patch/minor grouped, major flagged for review
- Cargo: weekly on Monday, patch/minor grouped, major flagged for review
- GitHub Actions: monthly, major flagged for review
- Auto-merge for patch-level updates already wired via dependabot-auto-merge.yml

Closes AnnabelJoe#306
- web: 1 GB memory / 1.0 CPU (256 MB / 0.25 CPU reserved)
- supabase-db: 512 MB memory / 0.5 CPU (128 MB / 0.1 CPU reserved)
- redis: 128 MB memory / 0.25 CPU (32 MB / 0.05 CPU reserved)
- README updated with minimum host requirements table

Closes AnnabelJoe#304
- docs/runbooks/contract-deployment.md: testnet/mainnet deploy, verify, rollback
- docs/runbooks/meter-key-rotation.md: scheduled and emergency key rotation
- docs/runbooks/failed-mint-investigation.md: diagnose and retry failed mints
- docs/runbooks/incident-response.md: triage, containment, resolution, postmortem
- docs/runbooks/README.md: index of all runbooks

Closes AnnabelJoe#315
- Enable test task caching in turbo.json (was cache: false)
- Add TURBO_TOKEN/TURBO_TEAM env vars to all CI steps (test, contracts fmt/clippy/test)
- Remote cache signature verification already enabled
…ons (AnnabelJoe#330)

- energy_token: mint, transfer, burn, retire event tests
- audit_registry: anchor event test (topics + data fields verified)
- community_governance: propose, vote, finalize, execute event tests
- Each test verifies event topic and data payload fields
…nnabelJoe#285)

- Document mainnet deployment steps (build, deploy script, initialize, verify)
- Add key management guidance (admin HSM, deployer rotation, minter rotation)
- Add environment separation table (testnet vs mainnet vars)
- Add deployment checklist with sign-off table
- deploy-mainnet.sh already exists and is idempotent; referenced in docs
…le (AnnabelJoe#318)

- Add legend explaining [REQUIRED] vs [OPTIONAL] markers
- Split NEXT_PUBLIC_ENERGY_TOKEN_ID/AUDIT_REGISTRY_ID/COMMUNITY_GOVERNANCE_ID
  into separate entries with individual descriptions
- Add [OPTIONAL] marker and description to LOGTAIL_SOURCE_TOKEN
- Add [OPTIONAL] marker and fallback behaviour note to CORS_ALLOWED_ORIGINS
- Group variables by service: Supabase, Stellar/Soroban, Redis, Logging, CORS
…ation

feat: log aggregation and retention
## [1.9.0](AnnabelJoe/solarproof@v1.8.2...v1.9.0) (2026-05-29)

### Features

* configure log aggregation and retention ([AnnabelJoe#299](AnnabelJoe#299)) ([3ee0154](AnnabelJoe@3ee0154))
- Implement bucketed storage to reduce ledger entries
- Move idempotency nonces to temporary storage
- Remove redundant reading_hash from storage values
- Update and expand test suite

Closes AnnabelJoe#281
- Added guidance for quorum, thresholds, and durations
- Included configurations for small, medium, and large DAOs
- Linked guide from community_governance contract docs

Closes AnnabelJoe#279
- Implement bucketed storage to reduce ledger entries
- Move idempotency nonces to temporary storage
- Remove redundant reading_hash from storage values
- Update and expand test suite
- Include regression test test_issue_281_bucket_collision

Closes AnnabelJoe#281
…tion

Add pagination and filtering to certificates
## [1.10.0](AnnabelJoe/solarproof@v1.9.0...v1.10.0) (2026-05-30)

### Features

* add pagination and filtering to certificates [AnnabelJoe#258](AnnabelJoe#258) ([4d2bde0](AnnabelJoe@4d2bde0))
…boundaries

Implement error boundary components
DevKingOche and others added 19 commits June 24, 2026 13:37
…nt-user-context

Add persistent user context for cooperative pages (AnnabelJoe#543)
…ce-tests

Add governance tally and edge-case tests (AnnabelJoe#551)
…admin-mobile

Improve admin page mobile layout and action affordances (AnnabelJoe#541)
…k-backlog

Add user story backlog for public verification kiosk mode (AnnabelJoe#611)
…ery-hooks

Consolidate React Query logic into shared hooks
…th-role

Audit require_auth and admin role assignment
…supabase-rls-tests

issue AnnabelJoe#546: strengthen Supabase RLS tests for readings and certificate access
…tl-management

issue AnnabelJoe#549: add on-chain Soroban storage TTL extension methods
…lJoe#552)

The persistent entry value for each anchor previously stored a full
AuditAnchor struct { reading_hash: BytesN<32>, anchored_at_ledger: u32 }
(36 bytes). Because reading_hash is already encoded in the storage key
(DataKey::Anchor(hash)), it was pure duplication.

Change: store only the u32 ledger sequence as the entry value.
verify() reconstructs the AuditAnchor on read at no extra I/O cost.

Result: 36 B → 4 B per persistent entry value — 88% reduction.
This directly lowers the Soroban write_bytes fee for every anchor() call.

All existing tests remain green; no public API changes.

Closes AnnabelJoe#552
@github-actions

Copy link
Copy Markdown

🔍 Vercel Preview Deployment

URL: Learn More: https://err.sh/vercel/missing-token-value

Uses Stellar testnet contract addresses.

devnWisdom and others added 3 commits June 25, 2026 11:44
…oe#559)

Adds overflow_tests module with 16 tests covering every i128
arithmetic path in energy_token:

Overflow paths:
- mint() overflows recipient balance (balance + amount > i128::MAX)
- mint() overflows total_minted counter
- transfer() overflows recipient balance
- transfer_from() overflows recipient balance

Underflow / insufficient-funds paths:
- burn() amount > balance
- burn() on zero balance
- burn_from() amount > balance
- burn_from() amount > allowance
- transfer() amount > sender balance

Positive-only / non-negative guards:
- mint(0), mint(-1) rejected
- burn(0) rejected
- transfer(0) rejected
- approve(-1) rejected

Closes AnnabelJoe#559
…-tests-559

test(energy_token): add overflow/underflow test coverage for token arithmetic
@github-actions

Copy link
Copy Markdown

❌ pnpm audit

┌─────────────────────┬────────────────────────────────────────────────────────┐
│ critical            │ When Vitest UI server is listening, arbitrary file can │
│                     │ be read and executed                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ vitest                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <3.2.6                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=3.2.6                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps/web > @vitest/coverage-v8@2.1.9 > vitest@2.1.9    │
│                     │                                                        │
│                     │ apps/web > vitest@2.1.9                                │
│                     │                                                        │
│                     │ packages/stellar > vitest@2.1.9                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-5xrq-8626-4rwp      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ ws: Memory exhaustion DoS from tiny fragments and data │
│                     │ chunks                                                 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ ws                                                     │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=8.0.0 <8.21.0                                        │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=8.21.0                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps/web > @vitest/coverage-v8@2.1.9 > vitest@2.1.9 >  │
│                     │ jsdom@25.0.1 > ws@8.20.1                               │
│                     │                                                        │
│                     │ apps/web > jsdom@25.0.1 > ws@8.20.1                    │
│                     │                                                        │
│                     │ apps/web > vitest@2.1.9 > jsdom@25.0.1 > ws@8.20.1     │
│                     │                                                        │
│                     │ ... Found 4 paths, run `pnpm why ws` for more          │
│                     │ information                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-96hv-2xvq-fx4p      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ form-data: CRLF injection in form-data via unescaped   │
│                     │ multipart field names and filenames                    │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ form-data                                              │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ >=4.0.0 <4.0.6                                         │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=4.0.6                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ apps/web >                                             │
│                     │ @solarproof/stellar@link:../../packages/stellar >      │
│                     │ @stellar/stellar-sdk@13.3.0 > axios@1.16.1 >           │
│                     │ form-data@4.0.5                                        │
│                     │                                                        │
│                     │ apps/web > @stellar/stellar-sdk@13.3.0 > axios@1.16.1  │
│                     │ > form-data@4.0.5                                      │
│                     │                                                        │
│                     │ apps/web > @vitest/coverage-v8@2.1.9 > vitest@2.1.9 >  │
│                     │ jsdom@25.0.1 > form-data@4.0.5                         │
│                     │                                                        │
│                     │ ... Found 7 paths, run `pnpm why form-data` for more   │
│                     │ information                                            │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-hmw2-7cc7-3qxx      │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ vite: `server.fs.deny` bypass on Windows alternate     │
│                     │ paths                                                  │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ vite                                                   │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <=6.4.2                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patc

Comment thread apps/web/e2e/a11y.spec.ts
* violations are found. Baseline violations (if any) are documented below.
*/

import { test, expect } from '@playwright/test'
* Tests for useWallet hook using the mock Freighter wallet.
* Runs headlessly in CI — no browser extension required.
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
accountType = 'cooperative',
meterCount = 0,
}: { existing?: unknown; accountType?: string; meterCount?: number } = {}) {
const maybeSingle = vi.fn().mockResolvedValue({ data: existing })
@@ -98,23 +103,31 @@
const searchParams = useSearchParams()
const [query, setQuery] = useState(searchParams.get('id') ?? '')
const [result, setResult] = useState<ChainOfCustody | null>(null)
const [error, setError] = useState<string | null>(null)
const [pageError, setPageError] = useState<Error | null>(null)
</div>
)

function ThrowError({ error }: { error: Error }) {
const inMock = vi.fn().mockReturnValue({ error: null })
deleteMock.mockReturnValue({ in: inMock })

function makeInsertMock(row: Record<string, unknown>) {
Comment thread scripts/smoke-test.mjs
Comment on lines +2 to +8
import {
Contract,
Keypair,
Networks,
TransactionBuilder,
BASE_FEE,
} from '@stellar/stellar-sdk'
@github-actions

Copy link
Copy Markdown

✅ cargo audit

�[0m�[0m�[1m�[32m    Fetching�[0m advisory database from `https://github.com/RustSec/advisory-db.git`
�[0m�[0m�[1m�[32m      Loaded�[0m 1138 security advisories (from /home/runner/.cargo/advisory-db)
�[0m�[0m�[1m�[32m    Updating�[0m crates.io index
�[0m�[0m�[1m�[32m    Scanning�[0m Cargo.lock for vulnerabilities (192 crate dependencies)
�[0m�[0m�[1m�[33mCrate:    �[0m derivative
�[0m�[0m�[1m�[33mVersion:  �[0m 2.2.0
�[0m�[0m�[1m�[33mWarning:  �[0m unmaintained
�[0m�[0m�[1m�[33mTitle:    �[0m `derivative` is unmaintained; consider using an alternative
�[0m�[0m�[1m�[33mDate:     �[0m 2024-06-26
�[0m�[0m�[1m�[33mID:       �[0m RUSTSEC-2024-0388
�[0m�[0m�[1m�[33mURL:      �[0m https://rustsec.org/advisories/RUSTSEC-2024-0388

�[0m�[0m�[1m�[33mCrate:    �[0m paste
�[0m�[0m�[1m�[33mVersion:  �[0m 1.0.15
�[0m�[0m�[1m�[33mWarning:  �[0m unmaintained
�[0m�[0m�[1m�[33mTitle:    �[0m paste - no longer maintained
�[0m�[0m�[1m�[33mDate:     �[0m 2024-10-07
�[0m�[0m�[1m�[33mID:       �[0m RUSTSEC-2024-0436
�[0m�[0m�[1m�[33mURL:      �[0m https://rustsec.org/advisories/RUSTSEC-2024-0436

�[0m�[0m�[1m�[33mwarning:�[0m 2 allowed warnings found

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.

Optimize storage and gas for anchor payloads