Comments (4)
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()
caller = GetCallingScriptHash()
caller2 = GetEntryScriptHash()
caller3 = GetExecutingScriptHash()
contracts:
(A): #6edabfbf75265d2dd024416183f69aec677ee8e9
(B): # fb593745178a682d6df4dda9aa160af23d3444d4
#python
b'caller_main'
b'\xd4D4=\xf2\n\x16\xaa\xa9\xdd\xf4m-h\x8a\x17E7Y\xfb' #b'd444343df20a16aaa9ddf46d2d688a17453759fb'
b'caller2_main'
b'v\xf1\xb4sZ\x9e\x0c\x8f\xb5\xb2s\xb8p\x10`\x1a\xcd\xa9\x04\xa9' #b'76f1b4735a9e0c8fb5b273b87010601acda904a9'
b'caller3_main'
b'\xe9\xe8~g\xec\x9a\xf6\x83aA$\xd0-]&u\xbf\xbf\xdan' #b'e9e87e67ec9af683614124d02d5d2675bfbfda6e'
b'caller_printCaller'
b'\xe9\xe8~g\xec\x9a\xf6\x83aA$\xd0-]&u\xbf\xbf\xdan' #b'e9e87e67ec9af683614124d02d5d2675bfbfda6e'
b'caller2_printCaller'
b'v\xf1\xb4sZ\x9e\x0c\x8f\xb5\xb2s\xb8p\x10`\x1a\xcd\xa9\x04\xa9' #b'76f1b4735a9e0c8fb5b273b87010601acda904a9'
b'caller3_printCaller'
b'\xe9\xe8~g\xec\x9a\xf6\x83aA$\xd0-]&u\xbf\xbf\xdan' #b'e9e87e67ec9af683614124d02d5d2675bfbfda6e'
# C#
{"txid":"0x1ebc29295160470cede06e4e05008b850f1a321c46606862538e85ecc15ed352","vmstate":"HALT, BREAK","gas_consumed":"0.101","stack":[{"type":"ByteArray","value":""},
{"type":"ByteArray","value":""},{"type":"ByteArray","value":""}],
"notifications":[{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller_main"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"d444343df20a16aaa9ddf46d2d688a17453759fb"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller2_main"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"76f1b4735a9e0c8fb5b273b87010601acda904a9"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller3_main"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"e9e87e67ec9af683614124d02d5d2675bfbfda6e"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller_printCaller"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"e9e87e67ec9af683614124d02d5d2675bfbfda6e"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller2_printCaller"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"76f1b4735a9e0c8fb5b273b87010601acda904a9"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"caller3_printCaller"}},
{"contract":"0x6edabfbf75265d2dd024416183f69aec677ee8e9","state":{"type":"ByteArray","value":"e9e87e67ec9af683614124d02d5d2675bfbfda6e"}}]}
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.
from neo-boa.
@nickfujita @localhuman That is the correct behavior.
Let's assume InvocationStack is currently:
0: 6edabfbf75265d2dd024416183f69aec677ee8e9 (ContractA)
1: fb593745178a682d6df4dda9aa160af23d3444d4 (ContractB)
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
you clone CurrentContext and put on InvocationStack, which becomes:
0: 6edabfbf75265d2dd024416183f69aec677ee8e9 (ContractA)
1: 6edabfbf75265d2dd024416183f69aec677ee8e9 (ContractA)
2: fb593745178a682d6df4dda9aa160af23d3444d4 (ContractB)
So, GetCallingScriptHash will change value, and it is actually information that the contract itself performed the last CALL operation (not ContractB anymore).
from neo-boa.
@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
from neo-boa.
@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.
from neo-boa.
Related Issues (20)
- Crowdsale Demo directory shouldn't be labeled "nex" HOT 1
- Crowdsale demo and nep5 demo should be the same style HOT 1
- The method to_s(), which generates the output of the executable in readable format, is outdated
- [Feature] Use Python assert in smart contract HOT 4
- Smart Contract Migration results in different return value HOT 1
- Add support for multi-line invocation
- Neo 3x support HOT 2
- Built-in command line interface for neo-boa HOT 1
- support for avmdbgnfo format HOT 4
- replace coz-bytecode dependency with official bytecode project HOT 1
- .abi.json support HOT 3
- Python typehinting support
- About NEP-5 Smart Contract
- Generating incorrect hash for ABI file HOT 1
- Visual DevTracker deploy function not detecting contracts compiled with neo-boa
- negative shift count error when running unit test HOT 1
- Convert byte array to number ? HOT 1
- Invoking Neo.Contract.IsPayable fails HOT 1
- Crowdsale Demo totalSupply returns circulation
- Crowdsale Demo Contract missing OnTransfer event in deploy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neo-boa.