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..6113f6e1 --- /dev/null +++ b/eip-0050.md @@ -0,0 +1,212 @@ +Sigma 6.0 +========= + +* Author: kushti +* Status: Proposed +* Created: 25-Nov-2024 +* Implemented: Ergo Protocol Reference Client 6.0.0 +* Last edited: 27-May-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 non-trivial ways only 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, pretty much like e.g. SegWit update in Bitcoin) 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, average number of sub-blocks +per block, 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 integer tailored for cryptographic applications, with modular arithmetic operations and so on + +* 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`, `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 + +* Fix semantics of AvlTree.insert + +issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908 +PR: https://github.com/ergoplatform/sigmastate-interpreter/pull/1038 + +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 ). + +Notes +----- + +* You can use methods added in 6.0 and new `UnsignedBigInt` type only within an ErgoTree with version >= 3 + +* You can't put values of `Option[]`, `Header`, `UnsignedBigInt` types into registers or context extension variables to +avoid versioning issues with 5.0 clients. To bypass the limitation, you can write typed value as bytes and call `Global.deserialize` in a script to get an instance of those types. +* Example of higher order lambdas supported since since this EIP implemented: +[https://github.com/ergoplatform/sigmastate-interpreter/blob/b754e143cf38ed86d95698ede744a470dfa053d6/sigmastate/src/test/scala/special/sigma/SigmaDslSpecification.scala#L10040](https://github.com/ergoplatform/sigmastate-interpreter/blob/b754e143cf38ed86d95698ede744a470dfa053d6/sigmastate/src/test/scala/special/sigma/SigmaDslSpecification.scala#L10040) \ No newline at end of file