Просмотр исходного кода

contract/money: explicitly disallow local outputs in calls that don't support that

skoupidi 2 месяцев назад
Родитель
Сommit
bfef162d93

+ 6 - 0
src/contract/money/src/entrypoint/genesis_mint_v1.rs

@@ -114,6 +114,12 @@ pub(crate) fn money_genesis_mint_process_instruction_v1(
     let mut new_coins = Vec::with_capacity(params.outputs.len());
     msg!("[GenesisMintV1] Iterating over anonymous outputs");
     for (i, output) in params.outputs.iter().enumerate() {
+        // Disallow local outputs
+        if output.tx_local {
+            msg!("[GenesisMintV1] Error: Local output found: {}", i);
+            return Err(MoneyError::InvalidLocalOutput.into())
+        }
+
         // Check that the coin has not existed before
         if new_coins.contains(&output.coin) ||
             wasm::db::db_contains_key(coins_db, &serialize(&output.coin))?

+ 6 - 0
src/contract/money/src/entrypoint/pow_reward_v1.rs

@@ -80,6 +80,12 @@ pub(crate) fn money_pow_reward_process_instruction_v1(
     let self_ = &calls[call_idx].data;
     let params: MoneyPoWRewardParamsV1 = deserialize(&self_.data[1..])?;
 
+    // Disallow local output
+    if params.output.tx_local {
+        msg!("[PoWRewardV1] Error: Local output found");
+        return Err(MoneyError::InvalidLocalOutput.into())
+    }
+
     // Verify this contract call is not verified against genesis block
     let verifying_block_height = wasm::util::get_verifying_block_height()?;
     if verifying_block_height == 0 {

+ 4 - 0
src/contract/money/src/error.rs

@@ -111,6 +111,9 @@ pub enum MoneyError {
 
     #[error("Missing inputs in burn call")]
     BurnMissingInputs,
+
+    #[error("Invalid local output")]
+    InvalidLocalOutput,
 }
 
 impl From<MoneyError> for ContractError {
@@ -146,6 +149,7 @@ impl From<MoneyError> for ContractError {
             MoneyError::RootsValueDataMismatch => Self::Custom(28),
             MoneyError::ChildrenIndexesLengthMismatch => Self::Custom(29),
             MoneyError::BurnMissingInputs => Self::Custom(30),
+            MoneyError::InvalidLocalOutput => Self::Custom(31),
         }
     }
 }