Skip to content
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 - Sigma 6.0 #100

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
112 changes: 112 additions & 0 deletions eip-0050.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Sigma 6.0
=========

This EIP contains proposed changes for Ergo contractual layer, called Sigma. These changes are based on found issues
in the current version of Sigma, as well as feedback got from users, i.e. Ergo ecosystem developers.


Activation
----------

Rule 1011 should be replaced with another one, likely with the same rule but under different id.

Features Set
------------

* *.validatePoW* method of *Header* type to validate Autolykos2 proof of work done on header

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/958

* 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: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/962 (nbits encoding)


* implement Boolean to Byte conversion (boolean.toByte method)

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/931
PR: https://github.com/ScorexFoundation/sigmastate-interpreter/pull/932

* implement BigIntModQ type (unsigned bigints mod Q, where Q is the order of secp256k1 group)

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554


* finish executeFromVar implementation

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/443 , https://github.com/ScorexFoundation/sigmastate-interpreter/issues/612

* support MethodCall encoding of Numeric methods

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/667
Copy link
Member

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 and opcode 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.



* Add Numeric.toBytes, .toBits

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/486

* Fix for downcasting BigInt to Long fails

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877


* Lazy default evaluation for Option.getOrElse

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/906

* Implement Some and None as global methods

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/462

* Serialize Option[T] in DataSerializer

issue: https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659




How to add a new method
-----------------------

Here are instructions on how to add a (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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* For each new method separate property tests should be added to SigmaDslSpecification.



How to add a new type
---------------------

[TODO: complete]