neo icon indicating copy to clipboard operation
neo copied to clipboard

Oracle response breaks CalledByEntry witness scope

Open roman-khimov opened this issue 5 years ago • 5 comments

Describe the bug CheckWitness logic for oracle responses uses original transaction's signers list. If we have a transaction with a signer using CalledByEntry scope it would work fine for CONTRACT_A with an evaluation stack of ENTRY_SCRIPT -> CONTRACT_A, but if CONTRACT_A is to make an oracle request, then for oracle response we'd get ORACLE_RESPONSE_SCRIPT -> ORACLE_CONTRACT -> CONTRACT_A evaluation stack and CalledByEntry scope would no longer work for CONTRACT_A.

Expected behavior Supposedly signer scopes should work the same way they're for original transaction that generated an oracle request (side note: this was never a problem for #1584 design). This can probably be solved with additional request metadata saved by the oracle contract and used by CheckWitness logic.

roman-khimov avatar Sep 28 '20 21:09 roman-khimov

In this case, I think you should use WitnessScope.CustomContracts.

erikzhang avatar Sep 29 '20 04:09 erikzhang

If I'm a CONTRACT_A user (caller), how do I know when should I use CalledByEntry or CustomContracts? I have no idea what's going on inside of it and usually I'm just using CalledByEntry because it's the simplest thing to do and it works. Until it doesn't.

roman-khimov avatar Sep 29 '20 06:09 roman-khimov

BTW, this can probably be solved if we're to modify the entry script and finish method. Currently finish invokes callback directly, but it can instead return contract hash, method and arguments to the entry script and then entry script will do the actual call. The only problem is that the contract needs to check if it's invoked by Oracle contract or not, but it still could do that just checking for this well-known entry script hash (it could even be provided by Oracle contract via some method) instead of Oracle contract hash.

roman-khimov avatar Aug 19 '21 16:08 roman-khimov

A counter-example: Entry -> A -> B -> Oracle with CalledByEntry scope and callback in B.

roman-khimov avatar Aug 19 '21 18:08 roman-khimov

I have no idea what's going on inside of it and usually I'm just using CalledByEntry because it's the simplest thing to do and it works. Until it doesn't.

We can throw an error detectable for wallets, in order to ask the user if the want to add this contracts to CustomContracts

shargon avatar Aug 20 '21 15:08 shargon