Skip to content
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

[Oracles] Syscall and ApplicationEngine #1275

Closed
belane opened this issue Nov 25, 2019 · 13 comments · Fixed by #1399
Closed

[Oracles] Syscall and ApplicationEngine #1275

belane opened this issue Nov 25, 2019 · 13 comments · Fixed by #1399
Labels
discussion Initial issue state - proposed but not yet accepted oracles Oracle related issues

Comments

@belane
Copy link
Member

belane commented Nov 25, 2019

This proposal does not require Virtual Machine modifications. It only requires to add one new download syscall. This Syscall accepts two parameters: URL and xpath filter.

  • URL is the destination address where the Oracle will download the data.
  • XPATH filter is used to shorten downloaded content and ease access to information for developers. It can be used in JSON or HTML responses.

Thus, we reduce stored content in DownloadExecutionCache to the mínimum needed for Smart Contract.
As an example, only the filtered content is agreed and stored, optimizing storage space, meaning 1 MB JSON will not be stored into the chain but just the values the smart contracts needs.
XPATH filter also helps to achieve determinism in webs/APIs that have variations in each request and these variations are outside the data that Smart Contract needs.

As an example, the following API’s response {“name”:”NEO”,”time”:213123123213} where time varies in each request, but the Smart Contract only needs “name”, this non determinism problem won’t exist during Oracle negotiation.
(Note: Maximum content size and total TBD).

ApplicationEngine Execution

During a Smart Contract execution it will check if the result exits in the DownloadExecutionCache every time Oracle’s syscall is used.

If the node represents an authorized Oracle or a client building his/her transactions, it will download the content, apply the filter and generate DownloadExecutionCache.

In case the client is building the transaction, it will include results hash in OracleExpectedResult before signing and broadcasting the transaction.

During execution, the virtual machine (syscall) will return “Failure” if there is no total or partial DownloadExecutionCache, or if the final OracleAgreement is false.

image

Open Sub-discussions:

@belane belane added the discussion Initial issue state - proposed but not yet accepted label Nov 25, 2019
@belane belane added this to the NEO 3.0 milestone Nov 25, 2019
@lock9 lock9 added the oracles Oracle related issues label Nov 25, 2019
@doubiliu
Copy link
Contributor

doubiliu commented Dec 3, 2019

Good design.But as my comment in economic model,I think we should do a little change.
We must avoid free request. @belane
#1279 (comment)

@shargon
Copy link
Member

shargon commented Dec 3, 2019

@doubiliu free request it's a second request with the same values? (because it's cached)

@doubiliu
Copy link
Contributor

doubiliu commented Dec 3, 2019

No.Free request means paid less than the actual number of executions
Such as:
User only pay fee for 3 request.But in Script it invoke 4 times Oracle Service
@shargon

@belane
Copy link
Member Author

belane commented Dec 9, 2019

I think that if the execution requires 4 but the user has only paid for 3, the transaction should enter into the block as failed and thus charge the fee to the user anyway.

@doubiliu
Copy link
Contributor

It is also possible to return the execution failure, but we should understand that the Oracle node cannot know the actual number of calls in advance. So the purpose of OracleFee is to make it the basis for evaluating the number of calls when the Oracle node executes the script. @belane

@shargon
Copy link
Member

shargon commented Dec 10, 2019

If there are fee, he should try to get the result, because he need to know the response in order to know how much fee he need it. It should be on the price.

@doubiliu
Copy link
Contributor

Normally, this is correct. But if I try to attack, then I can only pay once but call the service multiple times in the code, I don't care about the result of the request, I just want the oracle to do useless work

@doubiliu
Copy link
Contributor

The oracle needs a mechanism to verify the number of calls

@shargon
Copy link
Member

shargon commented Dec 10, 2019

If you pay, and it's not enought for 1 byte, you will be FAULT. It's the same with regular TX

@doubiliu
Copy link
Contributor

doubiliu commented Dec 10, 2019

Calling a service will incur a fee and pay once? @shargon

@belane
Copy link
Member Author

belane commented Jan 3, 2020

@shargon I think we can start with the first implementation of Syscall (or draft) as it has been decided which are the first filters, protocols and responses to be implemented.
It has also been decided:

  • Support more than one use of the oracles in the same smart contract.
  • Have multiple Oracle Syscalls, one for each protocol/method.

@shargon shargon mentioned this issue Jan 6, 2020
@EdgeDLT
Copy link

EdgeDLT commented Jan 9, 2020

@belane what about when the contract is expecting variations, in future is it feasible to support non-deterministic requests?

@shargon
Copy link
Member

shargon commented Mar 30, 2020

I think that filters are very important, but also, it should be deterministic, so this is my proposal.

Download(url, filter)

Where filter is a nef script (like an eval), after download, we will create a new ApplicationEngine with this script without storage access and with the result of the Oracle as an argument.
The cost of this execution will not be added as the cost of the main execution (because it will be executed only in wallets and oracles), But oracles will add this quantity in his desired amount in order to process the transaction.

  • Why not a script hash? because it require to deploy a filter for any value, if the projects require multiple downloads, with diferent filters, it should deploy a lot of libraries.

Another idea is the filter as a Pointer (https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/Types/Pointer.cs) we can obtain the same behaiviour, but it should be isolated, without storage access, and it could produce undesired results if the developer use static vars that was altered before the execution of the filter (with storage access).


The filter template should be like this

public class MyFilter :SmartContract
{
public byte[] Main(byte[] result, bool isError)
  {
  return result;
  }
}

@shargon shargon mentioned this issue Apr 18, 2020
@erikzhang erikzhang removed this from the NEO 3.0 milestone Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Initial issue state - proposed but not yet accepted oracles Oracle related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants