Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Gas Cost #2

@MariusVanDerWijden

Description

@MariusVanDerWijden

Hey Marvin,

I've been looking through your contract and wanted to add my $.02 regarding gas costs. I think you could save a lot of gas if you store only the hashes of the vote instead of the full vote.

e.g.

    // maps a voteID to the vote struct
    mapping(uint256 => KNWVote) public votes;

becomes

    // maps a voteID to keccak256(KNWParams)
    mapping(uint256 => bytes32) public votes;

With Params being the start parameters that are generated at startVote.

Now Users have to provide the Parameters every time they vote, the vote than gets hashed and compared to votes[_voteID]. Since storing is so expensive (SStore 20000 gas) we can save a lot of gas (provided < 1000 votes on a proposal (very rough numbers))

See this link for how this concept is used to save gas.
https://github.com/statechannels/nitro-protocol/blob/08487def22ec8d39b1352acfce58b05aefe07ebd/contracts/ForceMove.sol#L48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions