Skip to content

Remove unsafe code in precompiles #181

Open
@MarcosNicolau

Description

@MarcosNicolau

The sha256 and keccak256 precompile functions store the intermediate state of the hash rather than the final digest. To access this state, we need to interact with the state fields within the hasher struct. However, these fields are private, and there isn't a direct way to access them. We have four potential options:

  • Replicate the Struct and Transmute Memory: This is the riskiest approach, as it involves moving memory and can lead to undefined behavior.
  • Create a Raw Pointer and Cast it to a Replicated Struct: This method is safer than transmuting memory because it only reads the memory without altering it, but it still requires the use of unsafe blocks.
  • Fork the Repository: We could fork the repo and modify the necessary code to make the fields accessible, though this adds maintenance overhead.
  • Use Pre-Release Library Versions: The upcoming versions introduce a SerializableState trait, which provides safe access to the hash state. See here and here.

Currently we are doing number two see, but the idea is to move to the library once the stable release gets shipped.

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