Skip to content

Implement Soroban contract state compression and encoding optimization #512

Description

@Just-Bamford

Description

Problem

Large contract state payloads can increase serialization overhead, storage requirements, and network transfer costs. The SDK currently has no standardized mechanism for analyzing state representation or applying safe compression/encoding optimizations.

Different state structures may also contain repetitive data that can be represented more efficiently.

Solution

Introduce contract state optimization utilities that analyze state payloads before storage or transmission.

The system should support compression for eligible payloads, optimized encoding for common primitive and structured types, and metadata describing how the state was encoded.

Compression must be transparent to consumers: callers should be able to write optimized state and read the original logical representation without manually handling decompression.

Acceptance Criteria

  • compressContractState(state, options) is implemented.
  • decompressContractState(data, metadata) restores the original state.
  • Encoding optimization is supported for common primitive and structured values.
  • Compression metadata identifies the encoding/compression strategy.
  • Unsupported values fail safely instead of producing corrupted state.
  • Compression ratio and size savings can be measured.
  • Compression/decompression operations do not mutate caller-owned state.
  • Tests cover primitive, structured, repetitive, empty, and oversized state payloads.
  • Performance benchmarks are included for representative payloads.
  • Exported through src/soroban/index.ts.

Note for Contributors

Do not assume every Soroban storage value should be compressed. Clearly define supported payload boundaries and preserve deterministic serialization. The implementation should prioritize correctness and compatibility over maximum compression.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions