Skip to content

Commit

Permalink
Update near plugins and it's roles
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Oct 24, 2023
1 parent 750da65 commit c7cc402
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 34 deletions.
8 changes: 4 additions & 4 deletions contracts/near/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/near/eth-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions contracts/near/eth-prover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eth-prover"
version = "0.1.0"
version = "0.2.0"
authors = ["Near Inc <[email protected]>"]
edition = "2021"

Expand All @@ -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"] }
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"
29 changes: 19 additions & 10 deletions contracts/near/eth-prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,23 +24,21 @@ pub enum Role {
PauseManager,
UnrestrictedVerifyLogEntry,
UnrestrictedVerifyStorageProof,
UpgradableManager,
UpgradableCodeStager,
UpgradableCodeDeployer,
UpgradableDurationManager,
ConfigManager,
DAO,
}

#[near_bindgen]
#[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::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,
Expand Down Expand Up @@ -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!(
Expand All @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/near/eth2-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eth2-client"
version = "0.3.0"
version = "0.4.0"
authors = ["Aurora <[email protected]>"]
edition = "2021"

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion contracts/near/eth2-client/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"
41 changes: 28 additions & 13 deletions contracts/near/eth2-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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<AccountId>) {
self.trusted_signer = trusted_signer;
}
Expand All @@ -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 {
Expand Down

0 comments on commit c7cc402

Please sign in to comment.