Add predefined function to strip ErgoTree header byte#1100
Open
shubham5080 wants to merge 2 commits intoergoplatform:masterfrom
Open
Add predefined function to strip ErgoTree header byte#1100shubham5080 wants to merge 2 commits intoergoplatform:masterfrom
shubham5080 wants to merge 2 commits intoergoplatform:masterfrom
Conversation
Author
|
please check does this PR working or not. |
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.
PR Title
Add predefined function to strip ErgoTree header byte
PR Description
This PR introduces a new predefined ErgoScript function for working with serialized ErgoTrees without the header byte, addressing the use case described in issue #1075 & #1028.
Summary of changes
Added a high-level predefined function that returns serialized ErgoTree bytes with the header byte removed.
This allows safe hashing and comparison of ErgoTrees without requiring manual slicing in user scripts.
The implementation is cross-platform (JVM + Scala.js) and does not affect existing cost models or serialization formats.
Test updates and rationale
Two test adjustments were required during integration:
SigmaCompilerTest
The compiler/type-checker lowers the predefined function into an equivalent Slice over the serialized ErgoTree bytes.
The test expectation was updated to reflect this lowered form, matching the compiler’s actual output rather than asserting a non-lowered AST node.
TestingInterpreterSpecification
The original test attempted to serialize and deserialize a constant value produced by the new function, which is not a valid standalone serialized value and caused a deserialization error.
This check was replaced with an equivalent runtime comparison of the sliced bytes, keeping the test focused on the intended semantics (header removal) rather than serialization internals.
Both test suites now pass:
SigmaCompilerTest
TestingInterpreterSpecification
Design notes
The function is intended for hashing and comparison of ErgoTrees and does not expose invalid serialized structures as deserializable values.
Lowering to existing primitives (Slice) is intentional and keeps the compiler and interpreter behavior consistent and stable.
No existing opcodes were modified or renumbered.
Verification
Focused tests can be run with:
sbt "testOnly SigmaCompilerTest"
sbt "testOnly TestingInterpreterSpecification"
All tests pass successfully.
Follow-ups (optional)
If preferred in the future, the function could be preserved as a first-class compiled node rather than lowering to Slice. This would require additional graph-builder and serializer support and is intentionally out of scope for this PR.
This PR adds an Automatic-Module-Name entry to the JAR manifest,
providing a stable Java module name for Java 9+ users.
Chosen module name:
org.ergoplatform.sigmastate.interpreter
The attribute is added via shared JVM build settings, so it
applies to all generated JVM artifacts. This change is fully
backward-compatible and does not affect runtime behavior.
Fixes: #1075 & #1028.