-
Notifications
You must be signed in to change notification settings - Fork 55
GetCallingScriptHash from module returns incorrect value #83
Comments
I did some quick simulations with both Python and C#, and they seem to behave the same way. I expanded the test to include functions: GetCallingScriptHash(), GetEntryScriptHash() and GetExecutingScriptHash()
It seems the only way to get the right contract calling information is on Main scope (and store it for further usage). GetCallingScriptHash() seems to return the scriphash of the contract which performed the last CALL operation, while GetExecutingScriptHash() seems to be consistent. |
@nickfujita @localhuman That is the correct behavior. Let's assume InvocationStack is currently: CurrentContext (in GetExecutingScriptHash) is: 6edabfbf75265d2dd024416183f69aec677ee8e9 (ContractA). GetCallingScriptHash returns position 1 of InvocationStack: fb593745178a682d6df4dda9aa160af23d3444d4 (ContractB). After you perform a (function) CALL: https://github.com/neo-project/neo-vm/blob/e2f3b1aa42073ce27343c9a95bf076ce7d19d787/src/neo-vm/ExecutionEngine.cs#L124 So, GetCallingScriptHash will change value, and it is actually information that the contract itself performed the last CALL operation (not ContractB anymore). |
@shargon @vncoelho it is amazing that I got interested by this post (by chance), because it seems to break my idea of function CALL inlining in NeonOpt project, when people are using GetCallingScriptHash information... in fact, if @nickfujita used my function inliner, he wouldn't have had this issue, because auxiliar function would have been moved to main scope :D hahahah |
@nickfujita unfortunately this is expected. I reported this issue some months ago here neo-project/neo-vm#29 and Erik Zhang said it's expected and intended behaviour. |
When using
GetCallingScriptHash
along withRegisterAppCall
orDynamicAppCall
, I expected to get the hash of the contract which called the contract withGetCallingScriptHash
in all cases, but it seems that whenGetCallingScriptHash
is used in a file that is separate from the root file that contains theMain
method, it is returning the hash of itself rather that the hash of the contract that invoked it.I have created the following example code to demonstrate this issue:
https://github.com/nickfujita/neo-examples/tree/master/smartContracts/callerHash
GetCallingScriptHash
when called from theMain
methodGetCallingScriptHash
when called from theprintTest
method, located atsrc/printCaller.py
Expected result:
GetCallingScriptHash
from both theMain
andprintTest
methodsActual result:
GetCallingScriptHash
from theMain
method, but prints the script hash of Contract A when called from theprintTest
methodPlease let me know if this issue should be moved to neo-python instead.
The text was updated successfully, but these errors were encountered: