https://ergoplatform.org/ logo
Join Discord
Powered by
# ❓│ergoscript-support
  • s

    soysor

    05/10/2023, 6:34 AM
    if else statements i guess
  • g

    greenhat

    05/10/2023, 7:52 AM
    Actually, I see
    SELF.getReg(i)
    method. @morphic Does it work?
  • m

    morphic

    05/10/2023, 12:16 PM
    No, it doesn't work, but can be done in v6.x
  • g

    greenhat

    05/10/2023, 12:42 PM
    @morphic I have an unrelated question. I got a box on the mainchain that has the tree
    BoolToSigmaProp(SigmaOr(pk1, pk2))
    . I believe it should crash on evaluation since
    BoolSigmaProp
    should only accept bool. Am I right? Or does sigmastate skip
    BoolToSigmaProp
    evaluation in such case?
  • m

    morphic

    05/10/2023, 1:17 PM
    here is the eval logic case class BoolToSigmaProp(value: BoolValue) extends SigmaPropValue { override def companion = BoolToSigmaProp override def tpe = SSigmaProp override def opType = BoolToSigmaProp.OpType protected final override def eval(env: DataEnv)(implicit E: ErgoTreeEvaluator): Any = { val v = value.evalTo[Any](env) addCost(BoolToSigmaProp.costKind) if (VersionContext.current.isJitActivated) { SigmaDsl.sigmaProp(v.asInstanceOf[Boolean]) } else { // before v5.0 is activated we follow the old v4.x semantics to handle cases // when the value is not a boolean. There are historical transactions with such // erroneous scripts. See property("BoolToSigmaProp with SigmaProp argument should be deserializable") v match { case sp: SigmaProp => sp case _ => SigmaDsl.sigmaProp(v.asInstanceOf[Boolean]) } } } }
  • g

    greenhat

    05/10/2023, 1:41 PM
    Got it. I suppose the box was created before activation and should still evaluate, right?
  • m

    morphic

    05/10/2023, 2:37 PM
    No, there were such boxes, but they was spent succesfully. So, for historical transactions the behavior is different.
  • m

    morphic

    05/10/2023, 2:38 PM
    Now such contracts will fail.
  • g

    greenhat

    05/10/2023, 2:40 PM
    I see. Mine is still unspent https://explorer.ergoplatform.com/en/addresses/DfcvNGb2oymBMMW3BviigqyqUMsDjCDtzLRMvLAUgmkJJEeLx4aX3deRCwTbFwPcY8kDtaehWMzL7D9tyg8Mzm4CotsbLmddE7rGJvGkbm7qECfrib so it should fail then.
  • g

    greenhat

    05/10/2023, 2:47 PM
    @morphic Thank you for the explanation!
  • m

    morphic

    05/10/2023, 3:07 PM
    Not a big amount, will be collected by miners as storage rent 🙂
  • g

    greenhat

    05/10/2023, 3:12 PM
    Yes, seems like not a big deal. To clarify, when I said "mine" I meant the one with failed parsing I'm looking into now and not the ownership.
  • s

    soysor

    05/11/2023, 4:49 AM
    Anyone able to see whats wrong with this basic AVL tree insert offchain (plasma) + AVL tree get onchain scenario: https://scastie.scala-lang.org/IIGY3MY9Q4eqrExllWa7OA This line of the script is failing
    val actualValue = map.get(expectedKey, proof).get
    Which ultimately seems to be failing here during eval of `SAvlTree.get`: https://github.com/input-output-hk/scrypto/blob/d925f9357d3a3f2ee2b3f1be5d7b82f1eb8f8b54/shared/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLVerifier.scala#L249 with
    topNode == None
    Am I misunderstanding something about how to use AVL trees or not doing the insert correctly or something else? I can use
    PlasmaMap.lookUp
    offchain and can see the value exists offchain at least
  • s

    soysor

    05/11/2023, 4:57 AM
    I think I may have misunderstood how to use them
  • c

    Cheese Enthusiast

    05/11/2023, 5:05 AM
    You are providing the insertion proof while using the
    .get
    method in your contract.
    .get
    requires a lookup proof. Changing the context var to this fixes the problem:
    Copy code
    scala
    .withContextVars(new ContextVar(0.toByte, expectedValueResult.proof.ergoValue))
  • c

    Cheese Enthusiast

    05/11/2023, 5:11 AM
    To be clear, the reason you don't use the insertion proof is because you performed the insertion off chain, and your contract itself is simply checking whether or not the entry exists in the AVL tree. If you were to perform the insertion on-chain, you would provide an empty (un-modified) AVL Tree in the register and call the
    .insert
    method.
  • s

    soysor

    05/11/2023, 5:14 AM
    Gotcha, that was going to be my next question: https://scastie.scala-lang.org/ruw1qSUIQmaRbo8959780g What would I use for the proof in that case? An empty
    Coll()
    ? Thanks a lot for the help
  • c

    Cheese Enthusiast

    05/11/2023, 5:27 AM
    In the case of an insertion, you would use
    insertion.proof.ergoValue
    which is what you have written already. The error you're getting is likely happening because you are placing the already modified AVL Tree into the register of the UTXO. You're then calling
    .insert
    on this AVL Tree while providing an insertion proof that was built when the AVL Tree had nothing inside of it. Fixing the issue simply requires you re-arrange your code.
    Copy code
    scala
    val tb = ctx.newTxBuilder()
      // This AVL Tree is currently empty
      val map = new PlasmaMap[String, String](AvlTreeFlags.AllOperationsAllowed, PlasmaParameters.default)
      
      
    
      var inBox =
        tb
          .outBoxBuilder
          .value(100000000000000000L)
          .registers(map.ergoValue) // Empty AVL Tree is used in register
          .contract(ctx.compileContract(ConstantsBuilder.empty(), script))
          .build()
          .convertToInputWith("f9e5ce5aa0d95f5d54a7bc89c46730d9662397067250aa18a0039631c0f5b807", 1)
    
      val insertion = map.insert(("40e9e6112fc16e191e69d042890945b97a3eb30bccd3f39d5a07ee5e91b5fbbc", "01")) // Insertion is performed on the AVL Tree
                                                                                                             // thereby modifying it's contents/digest
      inBox = inBox.withContextVars(new ContextVar(0.toByte, insertion.proof.ergoValue)) // Providing proof for insertion onto an empty tree
  • c

    Cheese Enthusiast

    05/11/2023, 5:29 AM
    If it helps, I created a starter on AVL Trees on the GetBlok Plasma repo, it explains the basics and some small nuances in regards to them. Not sure if you've read it already, but if you're just learning AVL Trees it may be helpful. https://github.com/GetBlok-io/GetBlok-Plasma/blob/master/documents/AVL_Trees.MD
  • s

    soysor

    05/11/2023, 5:34 AM
    Thanks! Looks awesome, I'll give it a read now 👍
  • d

    dΣathgripson

    05/24/2023, 9:33 PM
    how should I deserialize the hex values in these registers:
    Copy code
    "additionalRegisters": {
            "R4": "0e200fe3ac722831c0e09e54f55ec842654d70ab97557af2758b598acfb802b7a7a0",
            "R5": "0e2062f2807734a96f9d7a6620043c9c687891723c3003d16a32741533da17148f05",
            "R6": "070224fd451e88b9ce0ec33e6fcba78689add93310922d950e66517fdf5b7e744bb8",
            "R7": "0702a16aca13b7072c1608209b6d8d1dd96be2b6912db9d998e49504f800905ea9f3"
          },
  • m

    MGpai

    05/24/2023, 11:12 PM
    @dΣathgripson what method did you use to get them?
  • m

    MGpai

    05/24/2023, 11:12 PM
    are you using api instance in scala?
  • d

    dΣathgripson

    05/24/2023, 11:15 PM
    API call from python
    blockchain/transaction/byAddress
    i just separated the registers section from the whole tx
  • d

    dΣathgripson

    05/25/2023, 1:44 AM
    what do
  • m

    MGpai

    05/25/2023, 3:57 AM
    sorry I gotta look
  • m

    MGpai

    05/25/2023, 3:57 AM
    its someone in my codebase
  • l

    lgd

    05/26/2023, 2:21 AM
    This is Scala code, but maybe this will be useful as an example nonetheless
  • l

    lgd

    05/26/2023, 2:21 AM
    https://github.com/lucagdangelo/minting-for-dummies/blob/main/src/main/scala/app/EIP24IssuerBoxPrinter.scala
  • d

    dΣathgripson

    05/26/2023, 2:21 AM
    thanks