From c7cc402c4c6f424fb31828f5b593b2fb48f0c18d Mon Sep 17 00:00:00 2001 From: karim-en Date: Tue, 24 Oct 2023 19:02:31 +0100 Subject: [PATCH] Update near plugins and it's roles --- contracts/near/Cargo.lock | 8 ++--- contracts/near/eth-client/Cargo.toml | 2 +- contracts/near/eth-prover/Cargo.toml | 4 +-- contracts/near/eth-prover/rust-toolchain | 2 +- contracts/near/eth-prover/src/lib.rs | 29 ++++++++++------ contracts/near/eth2-client/Cargo.toml | 4 +-- contracts/near/eth2-client/rust-toolchain | 2 +- contracts/near/eth2-client/src/lib.rs | 41 ++++++++++++++++------- 8 files changed, 58 insertions(+), 34 deletions(-) diff --git a/contracts/near/Cargo.lock b/contracts/near/Cargo.lock index be9ac915..475bfc58 100644 --- a/contracts/near/Cargo.lock +++ b/contracts/near/Cargo.lock @@ -1102,7 +1102,7 @@ dependencies = [ [[package]] name = "eth-prover" -version = "0.1.0" +version = "0.2.0" dependencies = [ "borsh", "eth-types", @@ -1143,7 +1143,7 @@ dependencies = [ [[package]] name = "eth2-client" -version = "0.3.0" +version = "0.4.0" dependencies = [ "anyhow", "bitvec 1.0.1", @@ -2410,7 +2410,7 @@ dependencies = [ [[package]] name = "near-plugins" version = "0.1.0" -source = "git+https://github.com/aurora-is-near/near-plugins?rev=8920f9a72631f1b224ed93405640bc062f2a0191#8920f9a72631f1b224ed93405640bc062f2a0191" +source = "git+https://github.com/aurora-is-near/near-plugins?tag=v0.1.0#64c512f96d4b51ccdd1a1aed683ed90fd1ca8c57" dependencies = [ "bitflags", "near-plugins-derive", @@ -2421,7 +2421,7 @@ dependencies = [ [[package]] name = "near-plugins-derive" version = "0.1.0" -source = "git+https://github.com/aurora-is-near/near-plugins?rev=8920f9a72631f1b224ed93405640bc062f2a0191#8920f9a72631f1b224ed93405640bc062f2a0191" +source = "git+https://github.com/aurora-is-near/near-plugins?tag=v0.1.0#64c512f96d4b51ccdd1a1aed683ed90fd1ca8c57" dependencies = [ "darling", "proc-macro-crate 0.1.5", diff --git a/contracts/near/eth-client/Cargo.toml b/contracts/near/eth-client/Cargo.toml index c089410c..6722ee15 100644 --- a/contracts/near/eth-client/Cargo.toml +++ b/contracts/near/eth-client/Cargo.toml @@ -18,7 +18,7 @@ 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", rev = "8920f9a72631f1b224ed93405640bc062f2a0191" } +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 diff --git a/contracts/near/eth-prover/Cargo.toml b/contracts/near/eth-prover/Cargo.toml index 23842f0b..37305ce7 100644 --- a/contracts/near/eth-prover/Cargo.toml +++ b/contracts/near/eth-prover/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eth-prover" -version = "0.1.0" +version = "0.2.0" authors = ["Near Inc "] edition = "2021" @@ -15,7 +15,7 @@ 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", rev = "8920f9a72631f1b224ed93405640bc062f2a0191" } +near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.1.0" } [dev-dependencies] hex = { version = "0.4.3", features = ["serde"] } diff --git a/contracts/near/eth-prover/rust-toolchain b/contracts/near/eth-prover/rust-toolchain index 421bf0f8..f2415f83 100644 --- a/contracts/near/eth-prover/rust-toolchain +++ b/contracts/near/eth-prover/rust-toolchain @@ -1,2 +1,2 @@ [toolchain] -channel = "1.68.0" +channel = "1.69.0" diff --git a/contracts/near/eth-prover/src/lib.rs b/contracts/near/eth-prover/src/lib.rs index def71065..dc95edb1 100644 --- a/contracts/near/eth-prover/src/lib.rs +++ b/contracts/near/eth-prover/src/lib.rs @@ -5,7 +5,9 @@ use near_plugins::{ }; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{env, ext_contract, near_bindgen, Gas, PanicOnDefault, PromiseOrValue}; +use near_sdk::{ + env, ext_contract, near_bindgen, Gas, PanicOnDefault, Promise, PromiseOrValue, PublicKey, +}; use rlp::Rlp; type AccountId = String; @@ -22,11 +24,9 @@ pub enum Role { PauseManager, UnrestrictedVerifyLogEntry, UnrestrictedVerifyStorageProof, - UpgradableManager, UpgradableCodeStager, UpgradableCodeDeployer, - UpgradableDurationManager, - ConfigManager, + DAO, } #[near_bindgen] @@ -34,11 +34,11 @@ pub enum Role { #[access_control(role_type(Role))] #[pausable(manager_roles(Role::PauseManager))] #[upgradable(access_control_roles( - code_stagers(Role::UpgradableCodeStager, Role::UpgradableManager), - code_deployers(Role::UpgradableCodeDeployer, Role::UpgradableManager), - duration_initializers(Role::UpgradableDurationManager, Role::UpgradableManager), - duration_update_stagers(Role::UpgradableDurationManager, Role::UpgradableManager), - duration_update_appliers(Role::UpgradableDurationManager, Role::UpgradableManager), + 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 EthProver { bridge_smart_contract: AccountId, @@ -349,7 +349,7 @@ impl EthProver { } } - #[access_control_any(roles(Role::ConfigManager))] + #[access_control_any(roles(Role::DAO))] pub fn set_bridge(&mut self, bridge: AccountId) { env::log_str( format!( @@ -360,6 +360,15 @@ impl EthProver { ); self.bridge_smart_contract = bridge; } + + #[access_control_any(roles(Role::DAO))] + pub fn attach_full_access_key(&self, public_key: PublicKey) -> Promise { + Promise::new(env::current_account_id()).add_full_access_key(public_key) + } + + pub fn version(&self) -> String { + env!("CARGO_PKG_VERSION").to_owned() + } } #[cfg(test)] diff --git a/contracts/near/eth2-client/Cargo.toml b/contracts/near/eth2-client/Cargo.toml index 545fd48b..30713547 100644 --- a/contracts/near/eth2-client/Cargo.toml +++ b/contracts/near/eth2-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eth2-client" -version = "0.3.0" +version = "0.4.0" authors = ["Aurora "] edition = "2021" @@ -17,7 +17,7 @@ bls = { git = "https://github.com/aurora-is-near/lighthouse.git", optional = tru near-sdk = "4.1.1" borsh = "0.9.3" bitvec = "1.0.0" -near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", rev = "8920f9a72631f1b224ed93405640bc062f2a0191" } +near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.1.0" } [dev-dependencies] lazy_static = "1.4.0" diff --git a/contracts/near/eth2-client/rust-toolchain b/contracts/near/eth2-client/rust-toolchain index 421bf0f8..f2415f83 100644 --- a/contracts/near/eth2-client/rust-toolchain +++ b/contracts/near/eth2-client/rust-toolchain @@ -1,2 +1,2 @@ [toolchain] -channel = "1.68.0" +channel = "1.69.0" diff --git a/contracts/near/eth2-client/src/lib.rs b/contracts/near/eth2-client/src/lib.rs index fcc240af..b5114399 100644 --- a/contracts/near/eth2-client/src/lib.rs +++ b/contracts/near/eth2-client/src/lib.rs @@ -13,7 +13,9 @@ use eth2_utility::types::*; use eth_types::eth2::*; use eth_types::{BlockHeader, H256}; use near_sdk::collections::{LazyOption, LookupMap}; -use near_sdk::{env, near_bindgen, require, AccountId, BorshStorageKey, PanicOnDefault}; +use near_sdk::{ + env, near_bindgen, require, AccountId, BorshStorageKey, PanicOnDefault, Promise, PublicKey, +}; use tree_hash::TreeHash; mod migrate; @@ -34,24 +36,23 @@ enum StorageKey { #[serde(crate = "near_sdk::serde")] pub enum Role { PauseManager, - UpgradableManager, UpgradableCodeStager, UpgradableCodeDeployer, - UpgradableDurationManager, - ConfigManager, UnrestrictedSubmitLightClientUpdate, + UnrestrictedSubmitExecutionHeader, + DAO, } #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Pausable, Upgradable)] #[access_control(role_type(Role))] -#[pausable(manager_roles(Role::PauseManager))] +#[pausable(manager_roles(Role::PauseManager, Role::DAO))] #[upgradable(access_control_roles( - code_stagers(Role::UpgradableCodeStager, Role::UpgradableManager), - code_deployers(Role::UpgradableCodeDeployer, Role::UpgradableManager), - duration_initializers(Role::UpgradableDurationManager, Role::UpgradableManager), - duration_update_stagers(Role::UpgradableDurationManager, Role::UpgradableManager), - duration_update_appliers(Role::UpgradableDurationManager, Role::UpgradableManager), + 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 Eth2Client { /// If set, only light client updates by the trusted signer will be accepted @@ -223,7 +224,7 @@ impl Eth2Client { .map(|header| header.block_number) } - #[pause(except(roles(Role::UnrestrictedSubmitLightClientUpdate)))] + #[pause(except(roles(Role::UnrestrictedSubmitLightClientUpdate, Role::DAO)))] pub fn submit_beacon_chain_light_client_update( &mut self, #[serializer(borsh)] update: LightClientUpdate, @@ -238,6 +239,7 @@ impl Eth2Client { } #[result_serializer(borsh)] + #[pause(except(roles(Role::UnrestrictedSubmitExecutionHeader, Role::DAO)))] pub fn submit_execution_header(&mut self, #[serializer(borsh)] block_header: BlockHeader) { require!(self.client_mode == ClientMode::SubmitHeader); @@ -335,7 +337,7 @@ impl Eth2Client { ); } - #[access_control_any(roles(Role::ConfigManager))] + #[access_control_any(roles(Role::DAO))] pub fn update_trusted_signer(&mut self, trusted_signer: Option) { self.trusted_signer = trusted_signer; } @@ -344,10 +346,23 @@ impl Eth2Client { self.trusted_signer.clone() } - #[private] + #[access_control_any(roles(Role::DAO))] pub fn update_hashes_gc_threshold(&mut self, hashes_gc_threshold: u64) { self.hashes_gc_threshold = hashes_gc_threshold; } + + pub fn get_hashes_gc_threshold(&self) -> u64 { + self.hashes_gc_threshold + } + + #[access_control_any(roles(Role::DAO))] + pub fn attach_full_access_key(&self, public_key: PublicKey) -> Promise { + Promise::new(env::current_account_id()).add_full_access_key(public_key) + } + + pub fn version(&self) -> String { + env!("CARGO_PKG_VERSION").to_owned() + } } impl Eth2Client {