-
Notifications
You must be signed in to change notification settings - Fork 34
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
[WIP] EIP-50 - 6.0 Soft-Fork #100
Open
kushti
wants to merge
21
commits into
master
Choose a base branch
from
eip50
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a24fc41
EIP-50 initial draft
kushti f7361ba
implementation and tests for new method
kushti ecb6ff3
more issues added
kushti 698c270
fixing class names
kushti 9be47ad
update with new issues and PRs
kushti 278bee5
minor text polishing
kushti 7cbc850
updating header related issues and PRs
kushti 8685ed9
(de)serialization PRs updated
kushti df7ad75
updating issues
kushti 7a1caa8
LangSpec.md, updating serialization PRs
kushti cdd347c
updating statuses
kushti 63a22ae
finalizing 6.0 scope
kushti 32e74a8
update w. fromBigEndianBytes
kushti 6922535
getvar issues update
kushti 1059a13
update towards impl
kushti 1670e76
motivation / main changes started
kushti 0bcbffd
main changes
kushti cdb3c0f
reordering sections
kushti f01f902
statuses removed, header, appendices
kushti 396824a
polishing issues / PRs
kushti 027e8cb
new param and voting relaxation text in motivation
kushti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,273 @@ | ||||||
Sigma 6.0 | ||||||
========= | ||||||
|
||||||
* Author: kushti | ||||||
* Status: Proposed | ||||||
* Created: 25-Nov-2024 | ||||||
* Implemented: Ergo Protocol Reference Client 6.0.0 | ||||||
* Last edited: 25-Nov-2024 | ||||||
* License: CC0 | ||||||
* Forking: soft-fork (at least all the miners have to update) | ||||||
|
||||||
Motivation | ||||||
---------- | ||||||
|
||||||
To the moment, ErgoTree features are still the same as of mainnet launch (July, 2019), with only JIT costing replacing | ||||||
AOT introduced in 5.0 soft-fork, along with minimal changes. | ||||||
|
||||||
Within five years after mainnet launch, developers found many ways to improve expressiveness of scripts and make | ||||||
efficiently things which can be implemented in highly non-trivial way now. Some issues were found as well (happily, nothing critical). | ||||||
And finally, there are some features planned during Ergo testnets even (2018-19) but not landed in the mainnet. | ||||||
|
||||||
To address developers' feedback, and also fix known issues, we are proposing a soft-fork ( | ||||||
with existing nodes validating scripts with old features and skipping scripts with new features) in this document. | ||||||
|
||||||
Also, we propose to relax voteable parameters validation to support introducing new parameters to vote via soft-forks or | ||||||
even velvet forks. Also, we propose to add new blockchain parameter to vote since 6.0, namely, number of sub-blocks | ||||||
per blocks, to enhance upcoming sub-blocks implementation. This change is done in soft-fork way also, by disabling soft-forkable rule #215 via | ||||||
miners voting. | ||||||
|
||||||
Main Changes | ||||||
------------- | ||||||
|
||||||
The biggest proposed changes are: | ||||||
|
||||||
* new UnsignedBigInt type, unsigned 256-bits integers tailored for cryptographic applications, with modular arithmetics | ||||||
|
||||||
* support for serialization and deserialization in the scripts for all the existing types (including composite, | ||||||
such as collection of optional block headers, `Coll[Option[Header]]` in ErgoScript) | ||||||
|
||||||
* support for serialization and deserialization of instances of Option and Header types. It allows to store them in | ||||||
register or context extension variables. Also, constructors for Option instances (`Global.some[T]()` and `Global.none[T]` | ||||||
methods for any type `T`). Also, support for serialization and deserialization of SFunc type, which is providing | ||||||
support for higher-order functions | ||||||
|
||||||
* support for conversion from nbits-encoded number to big integer and back, to provide support to check difficulty for | ||||||
Ergo (and Bitcoin) headers efficiently. Examples for checking PoW for Ergo and Bitcoin headers can be found in 6.0 | ||||||
tests. | ||||||
|
||||||
* new methods to check proof of work for Ergo header (header.checkPow), and also to check PoW for custom variant of | ||||||
Autolykos2 algorithm for arbitrary message | ||||||
|
||||||
* possibility to read context variable from another input (useful to obtain state transition for a companion input) | ||||||
|
||||||
* methods support for `Byte`, `Short`, `Int`, `Long` types, more methods for all the numeric types (`.toBytes`, `.toBits`, | ||||||
`.shiftLeft`, `.shiftRight`, `bitwiseOr`, `bitwiseAnd`, `bitwiseXor` etc) | ||||||
|
||||||
* more collection methods (`.get` to optionally get element if a collection contains it, `reverse`, `distrinct`, | ||||||
`startsWith`, `endsWith`) | ||||||
|
||||||
And also: | ||||||
|
||||||
* possibility to propose voting for parameters not known to protocol client. It allows for introducing new voteable | ||||||
parameters via soft or even velvet-forks | ||||||
|
||||||
* new voteable parameter, number of sub-blocks per block (for further sub-blocks implementation) | ||||||
|
||||||
To check how those features are implemented, and to get more features and fixes done, see pointers to concrete issues | ||||||
and pull requests in the *Corresponding Issues and Pull Requests* section below. | ||||||
|
||||||
|
||||||
Corresponding Issues and Pull Requests | ||||||
-------------------------------------- | ||||||
|
||||||
* *.checkPoW* method of *Header* type to validate Autolykos2 proof of work done on header | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/958 | ||||||
PR #1: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/965 (Autolykos verification for a custom message) | ||||||
PR #2: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/968 (Header.checkPow) | ||||||
|
||||||
|
||||||
* implement conversion from Long-encoded nBits representation to BigInt (long.fromNBits method) and to nBits from BitInt (bigInt.toNBits method) | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/675 | ||||||
PR #1: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/962 (nbits encoding) | ||||||
PR #2: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/962 (nbits decoding) | ||||||
|
||||||
|
||||||
* UnsignedBigInt type for cryptographic applications | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/997 | ||||||
|
||||||
|
||||||
* support MethodCall encoding of Numeric methods | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/667 | ||||||
PR: (Numeric.toBigEndianBytes) https://github.com/ScorexFoundation/sigmastate-interpreter/pull/984 | ||||||
|
||||||
* Add Numeric.toBytes | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/486 | ||||||
PR: (Numeric.toBigEndianBytes) https://github.com/ScorexFoundation/sigmastate-interpreter/pull/984 | ||||||
|
||||||
|
||||||
* Add Numeric.toBits | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/992 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/1017 | ||||||
|
||||||
|
||||||
* Fix for downcasting BigInt to Long fails | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/1007 | ||||||
|
||||||
|
||||||
* Lazy default evaluation for Option.getOrElse and Coll.getOrElse | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/906 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1008 | ||||||
|
||||||
* Implement Some and None constructors as global methods | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/462 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1026 | ||||||
|
||||||
* Serialize Option[T] in DataSerializer | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/990 | ||||||
|
||||||
|
||||||
* Add support for Header values (de)serialization in DataSerializer: | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/969 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/972 | ||||||
|
||||||
|
||||||
* GetVar(inputIndex, varId) variant for reading context variable from another input | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/978 | ||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/983 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1016 | ||||||
|
||||||
* Implement binary serialization and deserialization for every type | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/945 | ||||||
PR #1 (Global.deserializeTo): https://github.com/ScorexFoundation/sigmastate-interpreter/pull/979 | ||||||
PR #2 (Global.serialize): https://github.com/ScorexFoundation/sigmastate-interpreter/pull/989 | ||||||
PR #3 (Numeric.toBigEndianBytes) https://github.com/ScorexFoundation/sigmastate-interpreter/pull/984 | ||||||
PR #4 (Global.fromBigEndianBytes) https://github.com/ScorexFoundation/sigmastate-interpreter/pull/1013 | ||||||
|
||||||
|
||||||
* Fix SubstContants: serialize ErgoTree size | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/994 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/995 | ||||||
|
||||||
* New collection methods for 6.0 | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/1004 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1010 | ||||||
|
||||||
* New numeric methods for 6.0 | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/1006 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1017 | ||||||
|
||||||
* Implementation of Box.getReg | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/416 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1015 | ||||||
|
||||||
* Serialize SFunc in TypeSerializer | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/847 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/1020 | ||||||
|
||||||
* Revise liftToConstant method | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1021 | ||||||
|
||||||
* Improve collections equality | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/909 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1011 | ||||||
|
||||||
|
||||||
* Revise checkSoftForkCondition | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/904 | ||||||
PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1029 | ||||||
|
||||||
Activation | ||||||
---------- | ||||||
|
||||||
To have old clients supporting 6.0 changes after soft-fork activation, some script deserialization validation rules | ||||||
should be replaced with identical ones but having different ids, namely, rules # 1007, 1008, 1011 ( | ||||||
done in https://github.com/ergoplatform/sigmastate-interpreter/pull/1029 ). | ||||||
|
||||||
Appendix 1. More possible issues to investigate and features to implement | ||||||
------------------------------------------------------------------------- | ||||||
|
||||||
* implement Boolean to Byte conversion (boolean.toByte method) - include ??? | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/931 | ||||||
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/932 | ||||||
|
||||||
status: unfinished | ||||||
|
||||||
* Add check using isValidIndex in Coll[T] impls | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/567 | ||||||
|
||||||
|
||||||
* ErgoTree Exponentiate (for GroupElement) op evaluation differs from BcDlogGroup.exponentiate | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/731 | ||||||
|
||||||
|
||||||
* Revise semantics of propBytes | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/903 | ||||||
|
||||||
|
||||||
* Fix semantics of AvlTree.insert | ||||||
|
||||||
issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908 | ||||||
|
||||||
|
||||||
Appendix 2. How to add a new method | ||||||
----------------------------------- | ||||||
|
||||||
Here are instructions on how to add a new method to existing types (as 6.0 is heavily about adding new methods). | ||||||
|
||||||
Implementation: | ||||||
|
||||||
* Checkout new branch based on "v6.0.0" branch | ||||||
|
||||||
* Find appropriate type (e.g. *SBigInt*) to add a desirable method (e.g. *nbits*) | ||||||
|
||||||
* Add method description there and add description handle to *getMethods()* in a class \*Methods corresponding to the type (*SBigIntMethods* in our example), add *method_eval* to be used via reflection in the compiler | ||||||
|
||||||
* Add method implementation to corresponding type in *SigmaDsl.scala* | ||||||
|
||||||
|
||||||
* Add method evaluation to *ErgoTreeEvaluator* interface and its instantiation *CErgoTreeEvaluator* | ||||||
|
||||||
* Add new method to reflection-related descriptions in *ReflectionData* (needed for compiler mostly?) | ||||||
|
||||||
* Add pattern matching in GraphBuilding.scala to the compiler to get support for the new method in ErgoScript, e.g. | ||||||
``` | ||||||
case Select(obj, SBigIntMethods.ToNBits.name, _) if obj.tpe == SBigInt && VersionContext.current.isV6SoftForkActivated => | ||||||
``` | ||||||
|
||||||
* Add new method to *SigmaDslUnit.scala* / *SigmaDslImpl.scala* (needed for compiler only) | ||||||
|
||||||
|
||||||
Tests: | ||||||
|
||||||
|
||||||
* Add compilation test in *TestingInterpreterSpecification* | ||||||
|
||||||
* Add roundtrip test in *MethodCallSerializerSpecification* | ||||||
|
||||||
* Add evaluation test (see "nbits evaluation" test) | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Documentation: | ||||||
|
||||||
* update `LangSpec.md` | ||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is not necessary. Looking back is was not good idea to allow both
method call
andopcode
encoding for methods. It would be better to forbid method calls for those methods which have dedicated opcodes.The translation MC -> opcode is actually happens in the compiler, but is not strictly enforced. This creates more surface for test coverage and potential bugs.