Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsafe code in precompiles #181

Open
MarcosNicolau opened this issue Aug 12, 2024 · 0 comments
Open

Remove unsafe code in precompiles #181

MarcosNicolau opened this issue Aug 12, 2024 · 0 comments

Comments

@MarcosNicolau
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant