Skip to content

Commit

Permalink
Addressed comments form the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Oct 14, 2023
1 parent facedff commit 00e5af2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion crates/client/src/client/schema/tx/transparent_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pub struct Transaction {
pub input_asset_ids: Option<Vec<AssetId>>,
/// The list of all contracts from the inputs of the transaction.
///
/// It is a helper function and doesn't have a corresponding field in the transaction.
/// The result of a `input_contracts()` helper function is stored here.
/// It is not an original field of the transaction.
pub input_contracts: Option<Vec<ContractIdFragment>>,
/// The field of the `Mint` transaction.
pub input_contract: Option<InputContract>,
Expand All @@ -93,6 +94,7 @@ pub struct Transaction {
pub is_create: bool,
pub is_mint: bool,
pub outputs: Vec<Output>,
/// The field of the `Mint` transaction.
pub output_contract: Option<ContractOutput>,
pub maturity: Option<U32>,
pub mint_amount: Option<U64>,
Expand Down
48 changes: 32 additions & 16 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,16 @@ where
let coinbase_tx = Transaction::mint(
TxPointer::new(block_height, execution_data.tx_count),
input::contract::Contract {
utxo_id: Default::default(),
balance_root: Default::default(),
state_root: Default::default(),
tx_pointer: Default::default(),
utxo_id: UtxoId::new(Bytes32::zeroed(), 0),
balance_root: Bytes32::zeroed(),
state_root: Bytes32::zeroed(),
tx_pointer: TxPointer::new(BlockHeight::new(0), 0),
contract_id: self.config.coinbase_recipient,
},
output::contract::Contract {
input_index: 0,
balance_root: Default::default(),
state_root: Default::default(),
balance_root: Bytes32::zeroed(),
state_root: Bytes32::zeroed(),
},
amount_to_mint,
self.config.consensus_parameters.base_asset_id,
Expand Down Expand Up @@ -727,7 +727,32 @@ where
let coinbase_id = checked_mint.id();
let (mut mint, _) = checked_mint.into();

if mint.input_contract().contract_id != ContractId::zeroed() {
fn verify_mint_for_empty_contract(mint: &Mint) -> ExecutorResult<()> {
if *mint.mint_amount() != 0 {
return Err(ExecutorError::CoinbaseAmountMismatch)
}

let input = input::contract::Contract {
utxo_id: UtxoId::new(Bytes32::zeroed(), 0),
balance_root: Bytes32::zeroed(),
state_root: Bytes32::zeroed(),
tx_pointer: TxPointer::new(BlockHeight::new(0), 0),
contract_id: ContractId::zeroed(),
};
let output = output::contract::Contract {
input_index: 0,
balance_root: Bytes32::zeroed(),
state_root: Bytes32::zeroed(),
};
if mint.input_contract() != &input || mint.output_contract() != &output {
return Err(ExecutorError::MintMismatch)
}
Ok(())
}

if mint.input_contract().contract_id == ContractId::zeroed() {
verify_mint_for_empty_contract(&mint)?;
} else {
if *mint.mint_amount() != execution_data.coinbase {
return Err(ExecutorError::CoinbaseAmountMismatch)
}
Expand Down Expand Up @@ -824,15 +849,6 @@ where
*mint.input_contract_mut() = input;
*mint.output_contract_mut() = output;
}
} else {
if *mint.mint_amount() != 0 {
return Err(ExecutorError::CoinbaseAmountMismatch)
}
let input = input::contract::Contract::default();
let output = output::contract::Contract::default();
if mint.input_contract() != &input || mint.output_contract() != &output {
return Err(ExecutorError::MintMismatch)
}
}

let tx = mint.into();
Expand Down

0 comments on commit 00e5af2

Please sign in to comment.