feat(soroban): implement sha256 and keccak256 builtins#1919
Open
aryanbaranwal001 wants to merge 10 commits into
Open
feat(soroban): implement sha256 and keccak256 builtins#1919aryanbaranwal001 wants to merge 10 commits into
aryanbaranwal001 wants to merge 10 commits into
Conversation
… and codec Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…alues Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…, bytes32 Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…bytes_subscript Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Author
|
This PR is stacked on #1918 because it includes the changes from #1908 and #1904, which add support for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Solidity
sha256andkeccak256builtins were unimplemented on the Soroban target. This PR adds support for both, the following code now compiles and works as expected.Key Changes
codegen/mod.rs: addedHostFunctions::ComputeSha256("c._") andComputeKeccak256("c.1").emit/soroban/mod.rs: registered both infunction_signatureand added them todeclare_externals.codegen/expression.rs: lowerBuiltin::Sha256/Builtin::Keccak256on Soroban, pass the input bytes (args[0]) throughsoroban_encode_argto get a BytesObject handle, call the host fn, then decode the returned digest withsoroban_decode_arg.Tests
tests/soroban_testcases/hash.rs: digest fixture asserts for both builtins, determinism and distinguishability, large input handling, cross algorithm divergence (sha256 != keccak256), and Sha256 / Keccak256 padding boundary fixtures.Note
Other targets (solana, polkadot) implement hashing in
TargetRuntime::hash, which takes a (vector_bytes,vector_len) ptr/len pair. We could do the same inSorobanTarget::hash, but on Sorobanbytes memoryis ani64BytesObject handle, so we'd first need a wrapper that copies the BytesObject contents into linear memory just to feedhashthe pointer it expects. Cleaner approach is to intercept the builtin one stage earlier in codegen and lower it directly, wiring it with the Soroban hashing host functions. This follows the pattern that the existing Soroban arms forRequireAuth,ExtendTtlfollows.