#ContextExtension

1 messages · Page 1 of 1 (latest)

kindred kelp
#

I am playing around with org.ergoplatform.playground code but am struggling to use ContextExtension to provide a custom value. Can someone point me to an example?

raw swift
kindred kelp
# raw swift I don't think `ContextExtension` is exposed in the playground API. I tried to ma...

I tried working around the playground API limitations by creating a tx through the API and then remaking it with my custom bindings like:

val initTx = Transaction(
  // tx details...
)

val initTxWithExt = new UnsignedErgoLikeTransaction(
  initTx.inputs.map(i => new UnsignedInput(i.boxId, i.extension.copy(bindings.toMap))),
  initTx.dataInputs,
  initTx.outputCandidates
)

but then when I send the tx to the mock blockchain I get this:

[error] java.lang.IllegalArgumentException: requirement failed: box (index 0) verification failed (cost 10151)
[error]         at scala.Predef$.require(Predef.scala:281)
[error]         at org.ergoplatform.playgroundenv.utils.TransactionVerifier$.$anonfun$verify$1(TransactionVerifier.scala:53)
[error]         at org.ergoplatform.playgroundenv.utils.TransactionVerifier$.$anonfun$verify$1$adapted(TransactionVerifier.scala:33)

in the verifier.
Is that because of playground limitations as well?

raw swift
# kindred kelp I tried working around the playground API limitations by creating a tx through t...

Tx verifier honor context extension - https://github.com/ergoplatform/ergo-playgrounds/blob/03a6e776be652cd5cd68a32c47236c6fe63b0487/playground-env/src/main/scala/org/ergoplatform/playgroundenv/utils/TransactionVerifier.scala#L46
What's the script in that input box? Maybe it fails for another reason (not context extension).

GitHub

Run contracts + off-chain code in the browser. Contribute to ergoplatform/ergo-playgrounds development by creating an account on GitHub.

kindred kelp
#

At this point I am just setting "true" as the contract. I hacked it down just to the essentials:

val blockchainSim = newBlockChainSimulationScenario("mockchain")

val party = blockchainSim.newParty("party")
party.generateUnspentBoxes(toSpend = 800000000)

val contract = "true"

val bindings = Map(
   1.toByte -> Values.IntConstant(10),
)

val initTx_ = Transaction(
  inputs = party.selectUnspentBoxes(toSpend = 100000000),
  outputs = List(Box(value = 100000000, script = ErgoScriptCompiler.compile(scriptEnv, contract))),
  fee = MinTxFee,
  sendChangeTo = party.wallet.getAddress
)

val initTx = new UnsignedErgoLikeTransaction(
  initTx_.inputs.map(i => new UnsignedInput(i.boxId, i.extension.add(bindings.toMap.toArray:_*))),
  initTx_.dataInputs,
  initTx_.outputCandidates
)

blockchainSim.send(party.wallet.sign(initTx))

It works if I comment out 1.toByte -> Values.IntConstant(10), but when I leave it in I get the requirement failed: box (index 0) verification failed (cost 10151) error.

raw swift
# kindred kelp At this point I am just setting `"true"` as the contract. I hacked it down just ...

I think the cause is the prover in wallet.sign ignores and removes the context extensions, but the signed message is a serialized tx with context extensions. The ergo-playgrounds uses an old appkit version where context extensions are ignored in the prover. Thus, producing invalid proofs, which the verifier fails to verify. I tried to update the appkit version, but it breaks the build, probably due to way too different sigmastate-interpreter versions used in ergo-script-compiler and appkit.

kindred kelp
#

I tried to upgrade to a few different version combinations of app-kit / ergo-scala-compiler / sigmastate but they all produced crazy lowlevel runtime exceptions. 🥹