-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace the contract method name with an offset #1335
Comments
This is an interesting proposal. Usually we call a contract like this:
Do you mean that we change to this:
This will indeed be faster. But I can think of some drawbacks, such as the inability to hide private methods. Originally posted by @erikzhang in #1094 (comment) |
What do you think @lightszero? |
Looks interesting! I see two different proposals being discussed, the ability of directly calling on ABI by absolute position and the call-by-offset... |
we can have an array with the valid offsets, and only check that it is in the range. I prefer to cache this inside the storage |
From the code I've seen one method check is ~20 bytes of code (including method name push), if we have 10 methods that's roughly 200 bytes of code out of ~9K of the average contract size (based on mainnet stat at the height of 4076134 with 141 contracts deployed). And it's a simple push-compare-jump code that shouldn't be visible in the overall contract execution time. It also adds some complexity to the compiler and its relations with developers, because before that it's simple for both of them --- you have a One benefit that I see here at the same time is a common automatic contract interface specification (in terms of available methods), but I doubt that it would be enough to be a real spec, because methods are methods, but all the rest of the arguments are just an array at the moment and the contract needs to have documentation for them anyway. |
I may be saying something a little naive but couldn't we add a C# annotation above the method to mark that method as an entry point to the Smart Contract? I believe it would be a lot easier to develop contracts that way. Something like this: @ContractMethod
public void MyMethod() {
} |
make a contract more like a dll?good point |
我来多解释一下“make a contract more like a dll“ 现在使用的合约方式是这样: 如果我们只是单纯的在入口点0里面把用name来做分支改为用index来做分支 所以我们应该做一个整体的设计 让nef文件更像一个dll,我们用工具可以直接看到nef里面有几个可调用的函数,他们的参数,他的入口点。我们调用一个函数的时候,虚拟机可以直接从函数的offset开始执行。 |
@Tommo-L help,need translate |
to EN: Let me explain "make a contract more like a DLL" Currently, the way to invoke the contract is as follows: If we just replace So we should make a complete design:
To make the nef file more like a dll, we can use some tools to see which the nef has callable functions, their parameters, and its entry point. When we want to call a function, vm can start execution directly from the offset of the function. |
Sine we already have three files: {
"groups": [],
"features": {
"storage": true,
"payable": true
},
"abi": {
"hash": "0x13f98375a2a5bf2c8ab9a71b7c1a66d0a96f82bf",
"methods": [{
"name": "main", //<--- only save public method
"parameters": [{
"name": "account",
"type": "ByteArray"
}],
"returnType": "Integer",
"offset": "0x00" // <------ add offset field
}]
},
"permissions": [{
"contract": "*",
"methods": "*"
}],
"trusts": [],
"safeMethods": []
} Then, when we want to invoke a contract, just call by this way. In Call(hash, method, args) |
If we use this way, should we add a special method for |
Yes, also it should be safer |
|
If we avoid the
Main
method and we index theOffset
in theABI
for all methods, we can avoid the initialswitch
too and start in the right place at the beginning.What do you think @erikzhang @lightszero?
Originally posted by @shargon in #1094 (comment)
The text was updated successfully, but these errors were encountered: