Skip to content

Commit

Permalink
Removed BLS Keys from Header-Verifier
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Baltariu <[email protected]>
  • Loading branch information
andreiblt1304 committed Jan 23, 2025
1 parent 39e2b8d commit e76fccc
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 152 deletions.
8 changes: 2 additions & 6 deletions chain-factory/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ pub trait FactoryModule: only_admin::OnlyAdminModule {

#[only_admin]
#[endpoint(deployHeaderVerifier)]
fn deploy_header_verifier(
&self,
chain_config_address: ManagedAddress,
bls_pub_keys: MultiValueEncoded<ManagedBuffer>,
) -> ManagedAddress {
fn deploy_header_verifier(&self, chain_config_address: ManagedAddress) -> ManagedAddress {
let source_address = self.header_verifier_template().get();
let metadata = self.blockchain().get_code_metadata(&source_address);

self.tx()
.typed(HeaderverifierProxy)
.init(chain_config_address, bls_pub_keys)
.init(chain_config_address)
.gas(60_000_000)
.from_source(source_address)
.code_metadata(metadata)
Expand Down
3 changes: 0 additions & 3 deletions common/proxies/src/chain_factory_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,14 @@ where

pub fn deploy_header_verifier<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
self,
chain_config_address: Arg0,
bls_pub_keys: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedAddress<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("deployHeaderVerifier")
.argument(&chain_config_address)
.argument(&bls_pub_keys)
.original_result()
}

Expand Down
3 changes: 0 additions & 3 deletions common/proxies/src/header_verifier_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ where
{
pub fn init<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
self,
chain_config_address: Arg0,
bls_pub_keys: Arg1,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&chain_config_address)
.argument(&bls_pub_keys)
.original_result()
}
}
Expand Down
6 changes: 1 addition & 5 deletions common/proxies/src/sovereign_forge_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,12 @@ where
.original_result()
}

pub fn deploy_phase_two<
Arg0: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
pub fn deploy_phase_two(
self,
bls_keys: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("deployPhaseTwo")
.argument(&bls_keys)
.original_result()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ impl ContractInteract {
}

pub async fn deploy_header_verifier(&mut self) {
let bls_pub_key: ManagedBuffer<StaticApi> = ManagedBuffer::new();
let mut bls_pub_keys = MultiValueEncoded::new();
bls_pub_keys.push(bls_pub_key);
let header_verifier_code_path = MxscPath::new(&self.header_verifier_code);
let chain_config_address = Bech32Address::from_bech32_string("chain_config".to_string());

Expand All @@ -140,7 +137,7 @@ impl ContractInteract {
.from(&self.wallet_address)
.gas(100_000_000u64)
.typed(header_verifier_proxy::HeaderverifierProxy)
.init(chain_config_address, bls_pub_keys)
.init(chain_config_address)
.code(header_verifier_code_path)
.returns(ReturnsNewAddress)
.run()
Expand Down
6 changes: 1 addition & 5 deletions enshrine-esdt-safe/tests/enshrine_esdt_safe_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,11 @@ impl EnshrineTestState {
}

fn deploy_header_verifier_contract(&mut self) -> &mut Self {
let bls_pub_key: ManagedBuffer<StaticApi> = ManagedBuffer::new();
let mut bls_pub_keys = MultiValueEncoded::new();
bls_pub_keys.push(bls_pub_key);

self.world
.tx()
.from(ENSHRINE_ESDT_OWNER_ADDRESS)
.typed(HeaderverifierProxy)
.init(CHAIN_CONFIG_ADDRESS, bls_pub_keys)
.init(CHAIN_CONFIG_ADDRESS)
.code(HEADER_VERIFIER_CODE_PATH)
.new_address(HEADER_VERIFIER_ADDRESS)
.run();
Expand Down
2 changes: 1 addition & 1 deletion esdt-safe/interactor/src/esdt_safe_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl ContractInteract {
.from(&self.wallet_address)
.gas(100_000_000u64)
.typed(HeaderverifierProxy)
.init(chain_config_address, MultiValueEncoded::new())
.init(chain_config_address)
.code(header_verifier_code_path)
.returns(ReturnsNewAddress)
.run()
Expand Down
6 changes: 1 addition & 5 deletions esdt-safe/tests/bridge_blackbox_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,11 @@ impl BridgeTestState {
}

fn deploy_header_verifier_contract(&mut self) -> &mut Self {
let bls_pub_key: ManagedBuffer<StaticApi> = ManagedBuffer::new();
let mut bls_pub_keys = MultiValueEncoded::new();
bls_pub_keys.push(bls_pub_key);

self.world
.tx()
.from(BRIDGE_OWNER_ADDRESS)
.typed(HeaderverifierProxy)
.init(CHAIN_CONFIG_ADDRESS, bls_pub_keys)
.init(CHAIN_CONFIG_ADDRESS)
.code(HEADER_VERIFIER_CODE_PATH)
.new_address(HEADER_VERIFIER_ADDRESS)
.run();
Expand Down
10 changes: 1 addition & 9 deletions header-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ pub enum OperationHashStatus {
#[multiversx_sc::contract]
pub trait Headerverifier: setup_phase::SetupPhaseModule {
#[init]
fn init(
&self,
chain_config_address: ManagedAddress,
bls_pub_keys: MultiValueEncoded<ManagedBuffer>,
) {
fn init(&self, chain_config_address: ManagedAddress) {
require!(
self.blockchain().is_smart_contract(&chain_config_address),
"The given address is not a Smart Contract address"
);

self.chain_config_address().set(chain_config_address);

for pub_key in bls_pub_keys {
self.bls_pub_keys().insert(pub_key);
}
}

#[upgrade]
Expand Down
59 changes: 15 additions & 44 deletions header-verifier/tests/header_verifier_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ impl HeaderVerifierTestState {
fn deploy_header_verifier_contract(
&mut self,
chain_config_address: TestSCAddress,
bls_keys: BlsKeys,
) -> &mut Self {
self.world
.tx()
.from(OWNER)
.typed(HeaderverifierProxy)
.init(chain_config_address, bls_keys)
.init(chain_config_address)
.code(HEADER_VERIFIER_CODE_PATH)
.new_address(HEADER_VERIFIER_ADDRESS)
.run();
Expand Down Expand Up @@ -256,19 +255,15 @@ impl HeaderVerifierTestState {
#[test]
fn test_deploy() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);
}

#[test]
fn test_register_esdt_address() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

state.propose_register_esdt_address(ENSHRINE_ADDRESS);

Expand All @@ -286,10 +281,8 @@ fn test_register_esdt_address() {
#[test]
fn test_register_bridge_operation() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
let operation_2 = ManagedBuffer::from("operation_2");
Expand Down Expand Up @@ -327,10 +320,8 @@ fn test_register_bridge_operation() {
#[test]
fn test_remove_executed_hash_caller_not_esdt_address() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
let operation_2 = ManagedBuffer::from("operation_2");
Expand All @@ -349,10 +340,8 @@ fn test_remove_executed_hash_caller_not_esdt_address() {
#[test]
fn test_remove_executed_hash_no_esdt_address_registered() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
let operation_2 = ManagedBuffer::from("operation_2");
Expand All @@ -370,10 +359,8 @@ fn test_remove_executed_hash_no_esdt_address_registered() {
#[test]
fn test_remove_one_executed_hash() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let operation_hash_1 = ManagedBuffer::from("operation_1");
let operation_hash_2 = ManagedBuffer::from("operation_2");
Expand Down Expand Up @@ -413,10 +400,8 @@ fn test_remove_one_executed_hash() {
#[test]
fn test_remove_all_executed_hashes() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
let operation_2 = ManagedBuffer::from("operation_2");
Expand Down Expand Up @@ -460,10 +445,8 @@ fn test_remove_all_executed_hashes() {
#[test]
fn test_lock_operation_not_registered() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);
state.propose_register_esdt_address(ENSHRINE_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
Expand All @@ -481,10 +464,8 @@ fn test_lock_operation_not_registered() {
#[test]
fn test_lock_operation() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);
state.propose_register_esdt_address(ENSHRINE_ADDRESS);

let operation_1 = ManagedBuffer::from("operation_1");
Expand Down Expand Up @@ -524,10 +505,8 @@ fn test_lock_operation() {
#[test]
fn update_config_can_only_be_called_by_chain_config_admin() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let sovereign_config = SovereignConfig::new(0, 0, BigUint::default(), None);

Expand All @@ -541,10 +520,8 @@ fn update_config_can_only_be_called_by_chain_config_admin() {
#[test]
fn update_config_wrong_validator_range() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let sovereign_config = SovereignConfig::new(0, 0, BigUint::default(), None);

Expand All @@ -557,10 +534,8 @@ fn update_config_wrong_validator_range() {
#[test]
fn update_config() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let sovereign_config = SovereignConfig::new(0, 0, BigUint::default(), None);

Expand All @@ -587,10 +562,8 @@ fn update_config() {
#[test]
fn change_validator_set_incorect_length() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let sovereign_config = SovereignConfig::new(0, 0, BigUint::default(), None);

Expand All @@ -606,10 +579,8 @@ fn change_validator_set_incorect_length() {
#[test]
fn change_validator_set() {
let mut state = HeaderVerifierTestState::new();
let bls_key_1 = ManagedBuffer::from("bls_key_1");
let managed_bls_keys = state.get_bls_keys(vec![bls_key_1]);

state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS, managed_bls_keys);
state.deploy_header_verifier_contract(CHAIN_CONFIG_ADDRESS);

let sovereign_config = SovereignConfig::new(1, 2, BigUint::default(), None);

Expand Down
6 changes: 2 additions & 4 deletions sovereign-forge/interactor/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl ContractInteract {
.from(&self.wallet_address)
.gas(50_000_000u64)
.typed(HeaderverifierProxy)
.init(chain_config_address, MultiValueEncoded::new())
.init(chain_config_address)
.returns(ReturnsNewAddress)
.code(MxscPath::new(HEADER_VERIFIER_CODE_PATH))
.run()
Expand Down Expand Up @@ -413,16 +413,14 @@ impl ContractInteract {
}

pub async fn deploy_phase_two(&mut self) {
let bls_keys = MultiValueVec::from(vec![ManagedBuffer::new_from_bytes(&b""[..])]);

let response = self
.interactor
.tx()
.from(&self.wallet_address)
.to(self.state.current_address())
.gas(30_000_000u64)
.typed(SovereignForgeProxy)
.deploy_phase_two(bls_keys)
.deploy_phase_two()
.returns(ReturnsResultUnmanaged)
.run()
.await;
Expand Down
10 changes: 3 additions & 7 deletions sovereign-forge/src/common/sc_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::err_msg;
use multiversx_sc::types::{MultiValueEncoded, ReturnsResult};
use multiversx_sc::types::ReturnsResult;
use operation::SovereignConfig;
use proxies::{chain_factory_proxy::ChainFactoryContractProxy, fee_market_proxy::FeeStruct};

Expand All @@ -16,15 +16,11 @@ pub trait ScDeployModule: super::utils::UtilsModule + super::storage::StorageMod
}

#[inline]
fn deploy_header_verifier(
&self,
chain_config_address: ManagedAddress,
bls_keys: MultiValueEncoded<ManagedBuffer>,
) -> ManagedAddress {
fn deploy_header_verifier(&self, chain_config_address: ManagedAddress) -> ManagedAddress {
self.tx()
.to(self.get_chain_factory_address())
.typed(ChainFactoryContractProxy)
.deploy_header_verifier(chain_config_address, bls_keys)
.deploy_header_verifier(chain_config_address)
.returns(ReturnsResult)
.sync_call()
}
Expand Down
Loading

0 comments on commit e76fccc

Please sign in to comment.