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

Near-plugins integration #845

Merged
merged 27 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2318f37
Eth-prover: replace `admin_controlled` with near plugins
karim-en Nov 11, 2022
8eb3f63
Eth2-client: replace `admin_controlled` with near plugins
karim-en Nov 11, 2022
f5de4d1
Eth-client: replace `admin_controlled` with near plugins
karim-en Nov 15, 2022
9f0b414
Fix prover tests
karim-en Nov 15, 2022
93513bf
Add prover test to CI
karim-en Nov 15, 2022
63bff44
Update wasm builds
karim-en Nov 25, 2022
e3382b7
Merge branch 'master' into add-near-plugins
karim-en Mar 14, 2023
67ea998
Fix prover tests after merge
karim-en Mar 14, 2023
5ba5e8d
Prover: update acl plugins
karim-en Mar 14, 2023
2ba1161
Eth2Client: update acl plugins
karim-en Mar 14, 2023
bc51b8e
EthClient: Update near plugins
karim-en Mar 15, 2023
1848198
Revert script changes
karim-en Mar 15, 2023
0323f3e
Update contracts builds
karim-en Mar 15, 2023
17ccf69
Merge remote-tracking branch 'origin/master' into add-near-plugins
karim-en Oct 23, 2023
750da65
Update contracts builds
karim-en Oct 24, 2023
c7cc402
Update near plugins and it's roles
karim-en Oct 24, 2023
acb4481
Update contracts builds
karim-en Oct 24, 2023
e47da3b
Merge branch 'master' into add-near-plugins
karim-en Oct 24, 2023
87c161b
Update contract build
karim-en Oct 25, 2023
6208abe
Clean roles for eth-client contracts
karim-en Oct 27, 2023
81d25f6
Update contract build
karim-en Oct 27, 2023
8223f38
Merge remote-tracking branch 'origin/master' into add-near-plugins
karim-en Oct 30, 2023
a49435b
Fix test
karim-en Oct 30, 2023
3d2aadf
Remove unused deps
karim-en Oct 30, 2023
379cbcb
Update contract build
karim-en Oct 30, 2023
d037e4e
Minor roles fixes
karim-en Oct 30, 2023
eaff03c
Update contracts builds
karim-en Oct 30, 2023
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
72 changes: 65 additions & 7 deletions contracts/near/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions contracts/near/eth-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
eth-types = { path = "../eth-types", default-features = false }
admin-controlled = { path = "../admin-controlled" }
eth-types = { path = "../eth-types", default-features = false }
near-sdk = "4.1.1"
borsh = "0.9.3"
rlp = "0.5.2"
Expand All @@ -18,19 +17,22 @@ arrutil = "0.1.2"
ethash = { git = "https://github.com/aurora-is-near/rust-ethash", tag = "0.2.0", default-features = false }
hex = "0.4.0"
rustc-hex = "2.1.0"
near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.1.0" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# serde's Serialize and Deserialize traits are required for `near_bindgen` macro for non-wasm32 targets
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
tokio = "1.19"
primitive-types = { version = "0.7.2", default-features = false, features = ["rlp"] }
primitive-types = { version = "0.7.2", default-features = false, features = [
"rlp",
] }
web3 = "0.18.0"
lazy_static = "1.4.0"
serde_json = "1.0"
indicatif = "0.14"

[features]
default = []
expensive_tests = []
expensive_tests = []
1 change: 1 addition & 0 deletions contracts/near/eth-client/src/data/12965004.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/near/eth-client/src/data/12965005.json

Large diffs are not rendered by default.

49 changes: 34 additions & 15 deletions contracts/near/eth-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use admin_controlled::Mask;
use borsh::{BorshDeserialize, BorshSerialize};
use eth_types::*;
use near_plugins::{
access_control, access_control_any, pause, AccessControlRole, AccessControllable, Pausable,
Upgradable,
};
use near_sdk::collections::UnorderedMap;
use near_sdk::{assert_self, AccountId};
use near_sdk::{env, near_bindgen, PanicOnDefault};

#[cfg(not(target_arch = "wasm32"))]
use serde::{Deserialize, Serialize};
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault};

#[cfg(not(target_arch = "wasm32"))]
#[cfg(test)]
Expand Down Expand Up @@ -59,10 +59,27 @@ pub struct HeaderInfo {
pub number: u64,
}

const PAUSE_ADD_BLOCK_HEADER: Mask = 1;
#[derive(AccessControlRole, Deserialize, Serialize, Copy, Clone)]
#[serde(crate = "near_sdk::serde")]
pub enum Role {
PauseManager,
UpgradableCodeStager,
UpgradableCodeDeployer,
UnrestrictedAddBlockHeader,
DAO,
}

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Pausable, Upgradable)]
#[access_control(role_type(Role))]
#[pausable(manager_roles(Role::PauseManager))]
#[upgradable(access_control_roles(
code_stagers(Role::UpgradableCodeStager, Role::DAO),
code_deployers(Role::UpgradableCodeDeployer, Role::DAO),
duration_initializers(Role::DAO),
duration_update_stagers(Role::DAO),
duration_update_appliers(Role::DAO),
))]
pub struct EthClient {
/// Whether client validates the PoW when accepting the header. Should only be set to `false`
/// for debugging, testing, diagnostic purposes when used with Ganache or in PoA testnets
Expand Down Expand Up @@ -102,7 +119,8 @@ pub struct EthClient {
/// others will be immediately rejected, used in PoA testnets
trusted_signer: Option<AccountId>,
/// Mask determining all paused functions
paused: Mask,
#[deprecated]
paused: u128,
}

#[near_bindgen]
Expand All @@ -122,6 +140,7 @@ impl EthClient {
let header: BlockHeader = rlp::decode(first_header.as_slice()).unwrap();
let header_hash = header.hash.unwrap().clone();
let header_number = header.number;
#[allow(deprecated)]
let mut res = Self {
validate_ethash,
dags_start_epoch,
Expand All @@ -135,7 +154,7 @@ impl EthClient {
headers: UnorderedMap::new(b"h".to_vec()),
infos: UnorderedMap::new(b"i".to_vec()),
trusted_signer,
paused: Mask::default(),
paused: 0,
};
res.canonical_header_hashes
.insert(&header_number, &header_hash);
Expand All @@ -150,6 +169,8 @@ impl EthClient {
number: header_number,
},
);

res.acl_init_super_admin(near_sdk::env::predecessor_account_id());
res
}

Expand Down Expand Up @@ -198,14 +219,14 @@ impl EthClient {
/// Add the block header to the client.
/// `block_header` -- RLP-encoded Ethereum header;
/// `dag_nodes` -- dag nodes with their merkle proofs.
#[pause(except(roles(Role::UnrestrictedAddBlockHeader, Role::DAO)))]
#[result_serializer(borsh)]
pub fn add_block_header(
&mut self,
#[serializer(borsh)] block_header: Vec<u8>,
#[serializer(borsh)] dag_nodes: Vec<DoubleNodeWithMerkleProof>,
) {
env::log_str("Add block header");
self.check_not_paused(PAUSE_ADD_BLOCK_HEADER);
let header: BlockHeader = rlp::decode(block_header.as_slice()).unwrap();

if let Some(trusted_signer) = &self.trusted_signer {
Expand All @@ -229,21 +250,21 @@ impl EthClient {
self.record_header(header);
}

#[access_control_any(roles(Role::DAO))]
pub fn update_trusted_signer(&mut self, trusted_signer: Option<AccountId>) {
assert_self();
self.trusted_signer = trusted_signer;
}

pub fn get_trusted_signer(&self) -> Option<AccountId> {
self.trusted_signer.clone()
}

#[access_control_any(roles(Role::DAO))]
pub fn update_dags_merkle_roots(
&mut self,
#[serializer(borsh)] dags_start_epoch: u64,
#[serializer(borsh)] dags_merkle_roots: Vec<H128>,
) {
assert_self();
self.dags_start_epoch = dags_start_epoch;
self.dags_merkle_roots = dags_merkle_roots;
}
Expand Down Expand Up @@ -454,5 +475,3 @@ impl EthClient {
(H256(pair.0), H256(pair.1))
}
}

admin_controlled::impl_admin_controlled!(EthClient, paused);
5 changes: 4 additions & 1 deletion contracts/near/eth-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn get_context() -> VMContext {
signer_account_pk: "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp"
.parse()
.unwrap(),
predecessor_account_id: "carol.near".parse().unwrap(),
predecessor_account_id: "alice.near".parse().unwrap(),
input: vec![],
block_index: 0,
block_timestamp: 0,
Expand Down Expand Up @@ -278,6 +278,8 @@ fn add_dags_merkle_roots() {

#[test]
fn update_dags_merkle_roots() {
use near_plugins::AccessControllable;

let block = read_block(format!("./src/data/{}.json", 12_965_000).to_string());
let mut context = get_context();
context.predecessor_account_id = context.current_account_id.clone();
Expand All @@ -295,6 +297,7 @@ fn update_dags_merkle_roots() {
None,
);

contract.acl_grant_role(crate::Role::DAO.into(), context.predecessor_account_id);
contract.update_dags_merkle_roots(0, dmr.dag_merkle_roots.clone());

for i in 0..699 {
Expand Down
8 changes: 5 additions & 3 deletions contracts/near/eth-prover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
[package]
name = "eth-prover"
version = "0.1.0"
version = "0.2.0"
authors = ["Near Inc <[email protected]>"]
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
eth-types = { path = "../eth-types", default-features = false }
admin-controlled = { path = "../admin-controlled" }
eth-types = { path = "../eth-types", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
near-sdk = "4.1.1"
borsh = "0.9.3"
rlp = "0.5.2"
hex = "0.4.2"
near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.1.0" }

[dev-dependencies]
hex = { version = "0.4.3", features = ["serde"] }
indicatif = "0.14"
lazy_static = "*"
near-crypto = "0.16.0"
near-primitives = "0.16.0"
workspaces = "0.6.0"
tokio = { version = "1.18.1", features = ["full"] }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion contracts/near/eth-prover/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.68.0"
channel = "1.69.0"
Loading
Loading