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

fix: SAO updates from old repo #1

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
711 changes: 303 additions & 408 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Subgraph Oracle

The Subgraph Oracle verifies the availability of the subgraph files and does other validity checks, if a subgraph is found to be invalid it will be denied rewards in the RewardsManager contract.
The Subgraph Oracle verifies the availability of the subgraph files and does other validity checks, if a subgraph is found to be invalid it will be denied rewards in the rewards manager contract. Usage:

```
USAGE:
Expand All @@ -13,7 +12,7 @@ FLAGS:

OPTIONS:
-c, --contracts <contracts>
One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, or `ganache/mainnet`. See
One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, `ganache/mainnet`, `sepolia` or `arbitrum-sepolia`. See
`common/src/contracts/config.rs` for the respective configurations [env: ORACLE_CONTRACTS=]
--grace-period <grace-period>
Grace period, in seconds from subgraph creation, for which subgraphs will not be checked [env:
Expand Down
4 changes: 2 additions & 2 deletions availability-oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "availability-oracle"
version = "0.2.0"
version = "0.3.0"
authors = ["Leonardo Yvens <[email protected]>"]
edition = "2018"

Expand All @@ -10,7 +10,7 @@ edition = "2018"
common = { path = "../common" }
async-trait = "0.1.50"
tokio = { version = "1.10", features = ["macros", "sync", "time"] }
serde_yaml = "0.8.13"
serde_yaml = "0.9"
reqwest = { version = "0.11.4", features = ["json"] }
serde_derive = "1.0.116"
serde = "1.0.116"
Expand Down
25 changes: 15 additions & 10 deletions availability-oracle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ struct Config {
long,
env = "ORACLE_CONTRACTS",
required_unless("dry-run"),
help = "One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, or `ganache/mainnet`. \
help = "One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, `ganache/mainnet` \
`sepolia` or `arbitrum-sepolia`. \
See `common/src/contracts/config.rs` for the respective \
configurations"
)]
Expand Down Expand Up @@ -132,7 +133,7 @@ struct Config {
// Note: `ethereum/contract` is a valid alias for `ethereum`
#[structopt(
long,
default_value = "ethereum,ethereum/contract,file/ipfs",
default_value = "ethereum,ethereum/contract,file/ipfs,substreams",
value_delimiter = ",",
env = "SUPPORTED_DATA_SOURCE_KINDS",
help = "a comma separated list of the supported data source kinds"
Expand Down Expand Up @@ -434,18 +435,20 @@ async fn check(
// Check that:
// - The subgraph has the same network in all data sources.
// - That network is listed in the `supported_networks` list
match network {
None => {
match (network, ds_network) {
(None, Some(ds_network)) => {
if !supported_network_ids.contains(ds_network) {
return Err(Invalid::UnsupportedNetwork(ds_network.clone()).into());
}
network = Some(ds_network)
}
Some(network) => {
(Some(network), Some(ds_network)) => {
if network != ds_network {
return Err(Invalid::ManifestParseError(anyhow!("mismatching networks")).into());
}
}
// Data sources such as file data sources don't have a network
(_, None) => (),
}

// Check that ABIs are valid.
Expand All @@ -455,11 +458,13 @@ async fn check(
}

// Check mappings.
let wasm = ipfs.cat(check_link(file)?).await?;
if let Some(host_fn) =
calls_any_host_fn(&wasm, FORBIDDEN_HOST_FN_PREFIX).map_err(Invalid::WasmParseError)?
{
return Err(Invalid::ForbiddenApi(host_fn.to_string()).into());
if let Some(file) = file {
let wasm = ipfs.cat(check_link(file)?).await?;
if let Some(host_fn) = calls_any_host_fn(&wasm, FORBIDDEN_HOST_FN_PREFIX)
.map_err(Invalid::WasmParseError)?
{
return Err(Invalid::ForbiddenApi(host_fn.to_string()).into());
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions availability-oracle/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ pub(crate) struct Abi {

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct Mapping {
pub(crate) file: Link,
pub(crate) file: Option<Link>,
#[serde(default)]
pub(crate) abis: Vec<Abi>,
}

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct DataSource {
pub(crate) kind: String,
pub(crate) network: String,
pub(crate) network: Option<String>,
pub(crate) mapping: Mapping,
}

Expand Down
3 changes: 2 additions & 1 deletion availability-oracle/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async fn test_reconcile() {
"ethereum".into(),
"ethereum/contract".into(),
"file/ipfs".into(),
"substreams".into(),
],
)
.await
Expand Down Expand Up @@ -142,13 +143,13 @@ impl contract::RewardsManager for MockRewardsManager {
})
.collect::<Vec<_>>();

assert!(denied_status.len() == 6);
assert_eq!(denied_status[0], (TWO.to_string(), true));
assert_eq!(denied_status[1], (THREE.to_string(), true));
assert_eq!(denied_status[2], (FOUR.to_string(), false));
assert_eq!(denied_status[3], (FIVE.to_string(), true));
assert_eq!(denied_status[4], (SIX.to_string(), true));
assert_eq!(denied_status[5], (SEVEN.to_string(), true));
assert_eq!(denied_status[6], (SUBSTREAM.to_string(), true));

Ok(())
}
Expand Down
15 changes: 15 additions & 0 deletions availability-oracle/src/test_files/file_ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ dataSources:
handler: handleTrigger
file:
/: QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
templates:
- kind: file/ipfs
mapping:
abis:
- file:
/: /ipfs/QmWt3abizzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
name: Contract
apiVersion: 0.0.7
entities:
- ERC721TokenMetadata
file:
/: /ipfs/QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
handler: handler
language: wasm/assemblyscript
name: fileDsTemplate
34 changes: 12 additions & 22 deletions availability-oracle/src/test_files/substream.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
specVersion: 0.0.2
schema:
file:
/: QmWt3schemazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
dataSources:
- kind: substreams
name: Contract
mapping:
apiVersion: 0.0.5
kind: substreams/graph-entities
name: my_substreams
network: mainnet
source:
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601"
abi: Contract
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
abis:
- name: Contract
file:
/: QmWt3abizzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
entities:
- Call
eventHandlers:
- event: Trigger(uint16)
handler: handleTrigger
file:
/: QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
package:
file:
/: /ipfs/whatever
moduleName: graph_out
schema:
file:
/: /ipfs/QmWt3schemazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
specVersion: 0.0.6
33 changes: 33 additions & 0 deletions common/src/chain_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use eip_712_derive::U256;

pub const MAIN_NET: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
]);

pub const GOERLI: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
]);

// 421613 = 0x66EED is the chain ID for Arbitrum Goerli
pub const ARBITRUM_GOERLI: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 110,
237,
]);

// 42161 = 0xA4B1 is the chain ID for Arbitrum One
pub const ARBITRUM_ONE: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 164,
177,
]);

// 111551111 = 0xAA36A7 is the chain ID for Sepolia
pub const SEPOLIA: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 54,
167,
]);

// 421614 = 0x66EEE is the chain ID for Arbitrum Sepolia
pub const ARBITRUM_SEPOLIA: U256 = U256([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 110,
238,
]);
70 changes: 66 additions & 4 deletions common/src/contracts/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::ContractConfig;
use crate::chain_id::{ARBITRUM_GOERLI, ARBITRUM_ONE, ARBITRUM_SEPOLIA, GOERLI, MAIN_NET, SEPOLIA};
use crate::prelude::*;
use anyhow::anyhow;
use eip_712_derive::{
chain_id::{ARBITRUM_GOERLI, ARBITRUM_ONE, GOERLI, MAIN_NET},
U256,
};
use eip_712_derive::U256;
use serde::{Deserialize, Deserializer};
use serde_json;
use std::{collections::BTreeMap, fs::File, path::Path, str::FromStr};
Expand Down Expand Up @@ -113,6 +111,68 @@ impl ContractConfig {
chain_id: ARBITRUM_ONE,
}
}

pub fn sepolia(url: &str) -> Self {
Self {
url: url.into(),
graph_token: "0xCA59cCeb39bE1808d7aA607153f4A5062daF3a83"
.parse()
.unwrap(),
epoch_manager: "0x3C39036a76104D7c6D3eF13a21477C0fE23A3Aa2"
.parse()
.unwrap(),
dispute_manager: "0x1Da0DF3435cde4199650D35690E3B0885dfc38B1"
.parse()
.unwrap(),
staking: "0x14e9B07Dc56A0B03ac8A58453B5cCCB289d6ec90"
.parse()
.unwrap(),
curation: "0x77A6e5F2f13218B33A97Aec56d591dB18D60FFb1"
.parse()
.unwrap(),
rewards_manager: "0x175f483AfAB4Fc52A6E07F9e9d46C90eB95941b5"
.parse()
.unwrap(),
service_registry: "0x0Ee47634c94E6606f67301b3A868319073CB0FC2"
.parse()
.unwrap(),
gns: "0x5461D48556B94e7fdD8ED5A8f865Ba4F1A3b5454"
.parse()
.unwrap(),
chain_id: SEPOLIA,
}
}

pub fn arbitrum_sepolia(url: &str) -> Self {
Self {
url: url.into(),
graph_token: "0xf8c05dCF59E8B28BFD5eed176C562bEbcfc7Ac04"
.parse()
.unwrap(),
epoch_manager: "0x88b3C7f37253bAA1A9b95feAd69bD5320585826D"
.parse()
.unwrap(),
dispute_manager: "0x7C9B82717f9433932507dF6EdA93A9678b258698"
.parse()
.unwrap(),
staking: "0x865365C425f3A593Ffe698D9c4E6707D14d51e08"
.parse()
.unwrap(),
curation: "0xDe761f075200E75485F4358978FB4d1dC8644FD5"
.parse()
.unwrap(),
rewards_manager: "0x1F49caE7669086c8ba53CC35d1E9f80176d67E79"
.parse()
.unwrap(),
service_registry: "0x888541878CbDDEd880Cd58c728f1Af5C47343F86"
.parse()
.unwrap(),
gns: "0x3133948342F35b8699d8F94aeE064AbB76eDe965"
.parse()
.unwrap(),
chain_id: ARBITRUM_SEPOLIA,
}
}
}

// The idea behind having this .parse() compatible API is to be able to easily
Expand All @@ -126,8 +186,10 @@ impl FromStr for ContractConfig {
["mainnet", url] => ContractConfig::mainnet(url),
["ganache/mainnet"] => ContractConfig::ganache(MAIN_NET),
["goerli", url] => ContractConfig::goerli(url),
["sepolia", url] => ContractConfig::sepolia(url),
["arbitrum-goerli", url] => ContractConfig::arbitrum_goerli(url),
["arbitrum-one", url] => ContractConfig::arbitrum_one(url),
["arbitrum-sepolia", url] => ContractConfig::arbitrum_sepolia(url),
_ => {
return Err(anyhow!("Unrecognized format. Expecting: network:url (or just network for \"ganache/mainnet\"). Got: {}", s));
}
Expand Down
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod async_cache;
pub mod chain_id;
pub mod contracts;
pub mod logging;
pub mod metrics;
Expand Down
Loading