diff --git a/README.md b/README.md index c4f2ce10..31f80a40 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Ergo Improvement Proposals (EIPs) specify and/or describe standards for the Ergo Please check out existing EIPs, such as [EIP-1](eip-0001.md), to understand the general expectation of how EIPs are supposed to be formatted. | Number | Title | -| ----------------------- | ----------------------------------------------------- | +|-------------------------|-------------------------------------------------------| | [EIP-0001](eip-0001.md) | Application-Friendly Wallet API | | [EIP-0002](eip-0002.md) | Ergo grant program | | [EIP-0003](eip-0003.md) | Deterministic Wallet Standard | @@ -25,3 +25,4 @@ Please check out existing EIPs, such as [EIP-1](eip-0001.md), to understand the | [EIP-0039](eip-0039.md) | Monotonic box creation height rule | | [EIP-0043](eip-0043.md) | Reduced Transaction | | [EIP-0044](eip-0044.md) | Arbitrary Data Signing Standard | +| [EIP-0050](eip-0050.md) | Ergo protocol 6.0 Soft-Fork | \ No newline at end of file diff --git a/eip-0050.md b/eip-0050.md new file mode 100644 index 00000000..a3fa2988 --- /dev/null +++ b/eip-0050.md @@ -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) + + +Documentation: + +* update `LangSpec.md` +