ScorexFoundation / sigmastate-interpreter

ErgoScript compiler and ErgoTree Interpreter implementation for Ergo blockchain
MIT License
62 stars 40 forks source link

[v6.0] Implement new CreateAvlTree operation #907

Open aslesarenko opened 1 year ago

aslesarenko commented 1 year ago

This new operation will allow creating AvlTree instances from parameters (which is not possible in v5.x)

Details https://github.com/ScorexFoundation/sigmastate-interpreter/blob/2b72f2fddcd9ceedd84aa6bb225d6717c04c4f48/interpreter/shared/src/main/scala/sigmastate/trees.scala#L207

kushti commented 4 months ago

Could be replaced with Global.deserialize[AvlTree] from #979 , with hardcoded bytes provided , and then CreateAvlTree opcode can be reused in future

aslesarenko commented 4 months ago

Could be replaced with Global.deserialize[AvlTree]

Yes, in principle, but it will be less usable and less powerful, because all the parameters will be hidden under hex and also fixed as constants.

As a side note, the better way to introduce object creation is through constructors like val tree = AvlTree() where every type works like a name of the constructor (same as in Scala3).

With that said, this issue can be closed, as it can be covered by #981

kushti commented 4 months ago

You can construct bytes avl tree data bytes in the script as well, so they are not necessarily constant

kushti commented 4 months ago

The main point is to reduce new nodes / opcodes / complexity

aslesarenko commented 4 months ago

The main point is to reduce new nodes / opcodes / complexity

Yes, that is why this issue can be closed regardless of what we decide about NewObject operation. I.e. it is better to add NewObject opcode, which will serve many usecases, instead of just this CreateAvlTree.