Skip to content

[Task] Compare cost of using map as default storage for rust contracts #605

Closed

Description

@gagdiez

Background

During DevConnect Buenos Aires the people of Solidity discussed on the problem of contact migration

As it happens on NEAR, their contracts store data in a linearly serialized way, as we do with Borsh. This makes them run into the same "state is corrupted" error when they update the contract's state struct.

They are proposing a new EIP where they simply store the contract state as a map: variable_name -> value

Since on a map different variables are always in a different space, most of the corruption problems are easily avoidable

Would be useful for us to run some benchmarks, both in terms of NEAR locked and gas overhead to maybe propose a similar NEP

User Story

Acceptance Criteria

Resources & Additional Notes

No response

Activity

  1. moved this from NEW❗ to Backlog 📖 in DevRelon Jan 12, 2026
  2. garikbesson commented on Jan 27, 2026

    @garikbesson

    I compared two NEAR contracts (both are basic auction contracts):

    • Custom state contract – where I store data in the state by keys, for example storage_write(b"highest_bid", &borsh::to_vec(&highest_bid).unwrap());
    • Default contract where state is handled by near-sdk.

    Both are deployed with the same init arguments (end_time, auctioneer) and the same sequence of actions. The test then compares (custom vs. default):

    Case Custom State Default State
    Gas used to deploy and init the contract, Ggas 13180 12211
    Storage locked after deploy, NEAR 1.48065 1.41435
    Bid method 2467 2247
    Claim method 2591 2232
    Save rust vector (1000 elem.), Ggas 1991 1851
    Save sdk vector (1000 elem.), Ggas 92889 85947
    Save sdk iterable map (1000 elem.), Ggas 67653 66965
    Storage locked after all tests, NEAR 2.26806 2.20168

    So, basically, the difference is not so significant to say that storing data in the state by keys doesn't make sense. It requires more NEAR to store the same data and more gas to save it, but "most of the corruption state problems are easily avoidable".

    The repo with tests.

  3. moved this from Backlog 📖 to Shipped 🚀 in DevRelon Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Shipped 🚀

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions