Skip to content

[audit][high] Unchecked size arithmetic can undercount storage costs #684

@QuantumExplorer

Description

@QuantumExplorer

Created from a Codex audit of grovedb. No code changes were made as part of the audit.

Summary

Several element sizing and cost-accounting paths use unchecked u32 arithmetic or unchecked casts.

Impact / failure scenario

Near-u32::MAX lengths can wrap in release or panic in debug, causing undercharged storage costs or verifier bypasses.

References

  • grovedb-element/src/element/helpers.rs:622
  • grovedb-element/src/element/helpers.rs:647
  • grovedb-element/src/element/helpers.rs:681
  • costs/src/lib.rs:194
  • costs/src/storage_cost/key_value_cost.rs:64
  • grovedb/src/batch/mod.rs:2945

Suggested fix

Use checked_add, checked_sub, and u32::try_from with explicit overflow errors.

Suggested tests

Add boundary tests around u32::MAX, u32::MAX - n, and oversized serialized values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions