Code Monkey home page Code Monkey logo

oracle-contract's Introduction

oracle-contract

Predeployed contract to verify Oracle responses

Description

Oracle-contract is a predeployed smart-contract set running on each SKALE Chain which can verify Oracle responses.

Response structure

{
    "cid": 1,
    "uri": "http://worldtimeapi.org/api/timezone/Europe/Kiev",
    "jsps": [ "/unixtime", "/day_of_year", "/xxx" ],
    "trims": [ 1, 1, 1 ],
    "post": "/time_answer",
    "time": 1642521456593,
    "rslts": [ "164252145", "1", null ],
    "sigs": [
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac844:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f1",
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac845:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f1",
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac846:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f2",
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac847:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f3",
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac848:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f4",
        "0:fd4dde03a49aa83dcad8fe4e1e3e7b51e827c35d0339b047c71dd2a5673ac849:695b94e047f7310143a238d8b61f22ea60dcc3960d897d6dc57f212b91efe6f5",
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null
    ]
}

Signature structure

Each node of SKALE chain get an Oracle response, removes part after "rslts":[...],, combine to one string without spaces, get a KECCAK256 hash of this string and sign this string by ECDSA signature of this node

Example object to sign:

{
    "cid": 1,
    "uri": "http://worldtimeapi.org/api/timezone/Europe/Kiev",
    "jsps": [ "/unixtime", "/day_of_year", "/xxx" ],
    "trims": [ 1, 1, 1 ],
    "post": "/time_answer",
    "time": 1642521456593,
    "rslts": [ "164252145", "1", null ],

Combined to string:

{"cid":1,"uri":"http://worldtimeapi.org/api/timezone/Europe/Kiev","jsps":["/unixtime","/day_of_year","/xxx"],"trims":[1,1,1],"post":"/time_answer","time": 1642521456593,"rslts":["164252145","1",null],

If n - t + 1 ECDSA signatures provided - Oracle response is signed

where:

n - number of nodes in SKALE chain

t - threshold number for BLS signature ( 2/3n + 1 )

Install

  1. Clone this repo and enter the repo
  2. run cd oracle-contract/
  3. run yarn install

Deployment

The .env file in the oracle-contract folder should include the following variables:

ENDPOINT="your mainnet RPC url, it also can be an infura endpoint"
PRIVATE_KEY="your private key for mainnet"
GASPRICE="preferred gas price (optional param)" 
  • deploy production upgradeable version to custom network:
yarn deploy --network custom
  • deploy production not upgradeable version to custom network:
yarn deploy-not-upgradeable --network custom
  • deploy test version to custom network:
yarn deploy-test --network custom
  • deploy test not upgradeable version to custom network:
yarn deploy-test-not-upgradeable --network custom

Test

yarn test

Usage

  1. Install @skalenetwork/oracle-interfaces npm package by npm or yarn
  2. Import IOracle.sol in your Solidity smart contract
  3. Import a predeployed address 0xd205aC1e00000000000000000000000000000000 in your Solidity smart contract
  4. Run verification
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.13;

import "@skalenetwork/oracle-interfaces/IOracle.sol";

contract VerifyOracleResponses {

    address public constant ORACLE_ADDRESS = 0xd205aC1e00000000000000000000000000000000;

    function checkOracleResponse(
        IOracle.OracleResponse memory response
    )
        public
    {
        require(IOracle(ORACLE_ADDRESS).verifyOracleResponse(response), "Verification is failed");
    }
}

Python Oracle usage

To see how to send Oracle request and get Oracle responses please go to oracle-demo

oracle-contract's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oracle-contract's Issues

Fix compatibility

Problem

After changes in Oracle spec and modifications in skaled, Oracle Verifier contract became incompatible with Oracle, so it is impossible to verify Oracle request provided by Oracle in a current version of Oracle Verifier contract
Changes in Oracle/skaled:

  • Spec changed - added several new json fields(encoding, ethApi, params)
  • Limitation to read from config (whitelist of paths added)

Solution

Need add compatibility of new json fields and fix read from config

Add ethApi tests

Add more unit tests which would cover different ethApi request(successful and failed)

Add version

It would be good to have a version of Oracle contract, to provide future upgrades.

It would be good to add it before Oracle contract goes to release/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.