-
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
Callback APIs for NeoContract #284
Comments
I will call you back after I understand this...aehauheaea This will be an useful tool for several applications, @igormcoelho. |
How (which format) will these callbacks will be passed Erik, as raw opcodes? |
Nice to come back here, it was the callback you left on neo-vm :) Lambdas could easily be Neo interop objects, but honestly Erik, I think that native vm objects will be so much better. Two opcodes we need, one to create, other to execute. After that,filtering will be finally easily doable 👍 |
I think there's another problem with doing using syscalls... a hard one. Script passed should be hardcoded, for security, never coming directly from stack. This effectively rules out the possibility of doing on application layer. We should really consider doing that on vm. |
The callback within the contract is meaningless. This is a callback between contracts. |
The security issue I mention is on callback (offset) creation... it shouldnt be able to input jmp offset via stack parameter. But we can hardcode it. Tomorrow I may have more time to draw an example,with two distinct implementations. |
@erikzhang what I mention here is following problem. One example:
Is it the idea? Fine. Now, suppose the dapp user finds a way to pass a different offset there, of perhaps the dapp developer intentionally gets first offset from an array, or somewhere else. This would allow this callback to jump at an arbitrary position on code. I wonder if we could allow Interop hardcoded parameters, like this:
Could we do this? This way, first parameter would always be passed in mandatory script format, never coming from stack. If this is possible, it will be easier to design this callback interop feature. [HardcodedParameter("offset")] // <- how to put this here... a function reference?
InteropObject CreateCallback(int paramc, bool hasReturn); In my understanding here, this call would generate a |
Hello @neo-project/core, what are the use cases for this? What is not possible to do today, that this will enable? I gave it a heart, but I'm discussing with @belane and @shargon and maybe this doesn't have many usages. How the callback relates with these features:
? Thanks |
Filter(p => p.Index > 100); The statement |
@erikzhang for this proposal to work securely, I think we need Direct Syscall parameters (#1025). Suppose you want to create a "lambda" callback Without direct parameters, you could do this: This is fine... the only problem is that somehow these parameters start coming from a local variable: Now, we cannot easily know in advance which will be the offset called by this callback, which is dangerous and strongly harms code optimization (that's why relative jump offsets are banned everywhere). If somehow someone manages to change this value, we could fall within script parts that are critical, and allow crazy situations, such as jumping to the middle of a function script (which doesnt makes any sense). This simple thing can break many stack protection guarantees that we can think of. So, a simple solution, which is also much more readable on nvm side, is passing these parameters directly here: I've used serialization table for this (#1027), which is good for static and runtime serialization, in a organized and clear format.
ref table (NEP-3 inspired):
Obviously, this is a waste of space ( We can also use PUSHBYTES01 (code 01) to push1 byte, and perhaps redefine NEP-3 serialization prefix as something like e0 + NEP-3... reserving e0, e1, e2 ... until f0 to ff, and using the smaller ones for other purposes. The point is: we can benefit of having a explicit serialization standard here, without incurring too many loss of bytes... and still be able to use it directly on syscalls, when necessary. |
If we allow the parameters come from a local variable, how do you convert them to direct parameters? If you can convert them to direct parameters, of course you can convert them to |
Direct parameter won't be able to reference stack items, they are constant values. It's like On the other hand, think about |
The Java class name is uppercase
Create callback functions for smart contracts or SYSCALL, and allow other contracts to perform tasks through callback functions, which can work with iterators.
Several possible forms:
System.Runtime.CreateCallback(int offset, int paramCount, bool retValue)
System.Callback.GetFromSyscall(string name)
System.Callback.Invoke
Use with enumerators and iterators:
Neo.Enumerator.Filter
Neo.Enumerator.Select
Require neo-project/neo-vm#190
The text was updated successfully, but these errors were encountered: