NEWTON

NEWTON


Popular tags

    How to verify Empiric’s Data Entries Using Events?

    Asked

    3 months ago

    47

    views


    1

    How to verify Empiric’s Data Entries Using Events?

      cairostarknetempiricevents

    Newton

    asked

    3 months ago


    1 answers

    1

    Accepted answer

    Verifying Empiric’s Data Entries Using Events

    Every time a publisher sends new data to Empiric, the smart contract emits a SubmittedEntry event, which anyone can inspect on the blockchain. We will attempt to inspect this below using the GraphQL console by StarkNet Indexer.

    Before we proceed, I want to specify that these codes are in line with Empiric’s source code before the audit. So there might be changes to the existing contract address or the Event names.

    Indexing Empiric’s SubmittedEntry Event

    Here is the event we are looking for:

    @eventfunc SubmittedEntry(new_entry: Entry){}
    

    To return the last 3 submitted Entries:

    Open the console in your browser here. You should be greeted by an interface like this.


    Copy this piece of code and paste it in the console.

    {
      starknet_goerli_event(where: 
        {
            name: {_eq: "SubmittedEntry"}, 
            transmitter_contract: {_eq: "0x12fadd18ec1a23a160cc46981400160fbf4a7a5eed156c4669e39807265bcd4"}
        }, 
        limit: 5) {
        name
        arguments {
          name
          type
          value
          decimal
        }
        transaction_hash
      }
    }
    

    What’s happening here is that we create a query, starknet_goerli_event, specifying the event name we’ll be indexing and the contract address it’s being transmitted from. We also limit our query to just the last 3 emitted events.


    Run the query.

    And finally, we can see our output in the right-hand part of the console, like this.

    The returned data is an event with the name SubmittedEntry, which has a single argument new_entry of data type Entry.

    The data type Entry is a struct consisting of a key, value, source, publisher, and timestamp.

    struct Entry{
        key: felt,
        value: felt,
        source: felt,
        publisher: felt,
        timestamp: felt,
    }
    

    It lastly returns the transaction hash of the transaction that emitted the event.

    PS: Make sure to remove the redundant zero that begins the contract address or you’ll get an empty return value. What I mean is, rather than 0x012, use 0x12.


    Verifying Empiric’s Price Feed Data

    Having understood the roles events play in transparency, we can now take a detailed look at Empiric’s price feeds with respect to data frequency, reliability, and precision by indexing and analyzing the emitted events.

    Here’s a quick analysis of the ETH/USD price feed from Empiric, by querying all events emitted each time the price feed was updated.

    Crawling through the events

    For this analysis, Empiric provides a script here which you can run to crawl through our emitted events.

    You can also do something similar with the GraphQL console from earlier. To do that:

    Open the GraphQL console, and paste this piece of code below.

    query arguments_new_entry($jsonFilter: jsonb) {
      starknet_goerli_argument(
        limit: 100
        where: {event: {name: {_eq: "SubmittedEntry"}, transmitter_contract: {_eq: "0x12fadd18ec1a23a160cc46981400160fbf4a7a5eed156c4669e39807265bcd4"}}, value: {_contains: $jsonFilter}}
        order_by: {id: desc}
      ) {
        name
        type
        value
      }
    }
    

    In the Query variables bottom window, paste the code for the jsonFilter.

    {
      "jsonFilter": {
        "key": "0x6574682f757364"
      }
    }
    

    Here we are creating a query similar to the one from earlier, but this time passing in a filter for only results with the ETH/USD key.

    The console generates the data in JSON format, but using Empiric’s script we can generate a more human-readable CSV format as shown in this table. This table shows the number of times Empiric’s ETH/USD price feed pair was updated between 11:50:00 and 12:02:10 on 2022–10–11.

    One thing that stands out is the number of updates within such a short period — which we can attribute to the large number of publishers submitting their data to Empiric Network.

    Analysing the data

    • In total, the ETH/USD price feed updated 100 times in approximately 12.167 minutes or 730 seconds.
    • The shortest time between updates, which occurred repeatedly, was less than a second.
    • The longest time between updates, which occurred just once, was 58 seconds.
    • The median time between two price updates when considering all publishers was less than 5 seconds.
    • In general, all updates happened in less than a minute.
    • Not only was the feed frequently updated, but the prices were also remarkably close to the reported prices of our data providers.

    Conclusion

    Having read through the series of questions we answered, you should now possess a better understanding of how events on StarkNet work, and how you can leverage them to trustlessly audit and verify Empiric Network’s data. For infrastructure as critical as oracles it is very important to be able to independently verify past performance, and there is no better way than using an indexer to access historical events yourself! This represents a significant leap in the oracle stack — replacing intransparent black boxes with publicly available, verifiable data.

    Swagtimus.eth

    answered

    3 months ago

    Your answer

    NEWTON

    NEWTON