Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: enforce context to use ibc_transfer address as sender
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Apr 10, 2024
1 parent 5e6fdd9 commit 6b29dc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 7 additions & 14 deletions mocks/src/sovereign/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use sov_consensus_state_tracker::HasConsensusState;
use sov_kernels::basic::BasicKernelGenesisConfig;
use sov_modules_api::runtime::capabilities::{Kernel, KernelSlotHooks};
use sov_modules_api::{
CallResponse, DispatchCall, Gas, GasMeter, Genesis, KernelWorkingSet, ModuleInfo, SlotData,
Spec, StateCheckpoint,
CallResponse, DispatchCall, Gas, GasMeter, Genesis, KernelWorkingSet, SlotData, Spec,
StateCheckpoint,
};
use sov_rollup_interface::da::BlockHeaderTrait;
use sov_rollup_interface::services::da::DaService;
Expand All @@ -15,7 +15,7 @@ use sov_state::{MerkleProofSpec, ProverStorage, Storage};
use tokio::task::JoinHandle;
use tracing::{debug, info};

use super::{GenesisConfig, MockRollup, RuntimeCall};
use super::{GenesisConfig, MockRollup};
use crate::utils::{wait_for_block, MutexUtil};

impl<S, Da, P> MockRollup<S, Da, P>
Expand Down Expand Up @@ -105,25 +105,18 @@ where

let rollup_ctx = self.rollup_ctx();

for m in self.mempool() {
// Sets the sender address to the address of the 'sov-ibc'
// module, ensuring that the module's address is used for the
// token creation.
if let RuntimeCall::ibc(_) = m {
self.resolve_ctx(self.runtime().ibc.address().clone(), visible_slot);
}
// Resets the sender address to the address of the relayer
self.resolve_ctx(rollup_ctx.sender().clone(), visible_slot);

// NOTE: on failures, we silently ignore the error and continue as
for m in self.mempool() {
// NOTE: on failures, we silently ignore the message and continue as
// it is in the real-case scenarios
self.runtime()
.dispatch_call(m.clone(), &mut working_set, &self.rollup_ctx())
.unwrap_or_else(|e| {
info!("rollup: error executing message: {:?}", e);
CallResponse::default()
});

// Resets the sender address to the address of the relayer
self.resolve_ctx(rollup_ctx.sender().clone(), visible_slot);
}

*self.mempool.acquire_mutex() = vec![];
Expand Down
8 changes: 7 additions & 1 deletion modules/sov-ibc-transfer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ impl<'ws, S: Spec> TokenTransferExecutionContext for IbcTransferContext<'ws, S>
let minter_address = account.address.clone();
// Only the transfer module is allowed to mint
let authorized_minters = vec![self.ibc_transfer.address.clone()];
// Make sure to use `ibc_transfer` address as the sender
let context = Context::new(
self.ibc_transfer.address.clone(),
self.sdk_context.sequencer().clone(),
self.sdk_context.visible_slot_number(),
);
let new_token_id = self
.ibc_transfer
.bank
Expand All @@ -345,7 +351,7 @@ impl<'ws, S: Spec> TokenTransferExecutionContext for IbcTransferContext<'ws, S>
initial_balance,
minter_address,
authorized_minters,
&self.sdk_context,
&context,
&mut self.working_set.borrow_mut(),
)
.map_err(|err| TokenTransferError::Other(err.to_string()))?;
Expand Down

0 comments on commit 6b29dc2

Please sign in to comment.