Эх сурвалжийг харах

contract/money: StakeV1 fixed

aggstam 3 жил өмнө
parent
commit
c5affdc7c0

+ 4 - 7
src/contract/money/src/client/stake_v1.rs

@@ -119,7 +119,6 @@ impl MoneyStakeCallBuilder {
         let value_blind = pallas::Scalar::random(&mut OsRng);
         let token_blind = pallas::Scalar::random(&mut OsRng);
         let signature_secret = SecretKey::random(&mut OsRng);
-        let spend_hook = DARK_TOKEN_ID.inner();
         let user_data_blind = pallas::Base::random(&mut OsRng);
         info!("Creating stake burn proof for input");
         let (proof, public_inputs) = create_stake_burn_proof(
@@ -128,7 +127,6 @@ impl MoneyStakeCallBuilder {
             &input,
             value_blind,
             token_blind,
-            spend_hook,
             user_data_blind,
             signature_secret,
         )?;
@@ -138,7 +136,7 @@ impl MoneyStakeCallBuilder {
             token_commit: public_inputs.token_commit,
             nullifier: public_inputs.nullifier,
             merkle_root: public_inputs.merkle_root,
-            spend_hook,
+            spend_hook: public_inputs.spend_hook,
             user_data_enc: public_inputs.user_data_enc,
             signature_public: public_inputs.signature_public,
         };
@@ -160,7 +158,6 @@ pub fn create_stake_burn_proof(
     input: &TransactionBuilderInputInfo,
     value_blind: pallas::Scalar,
     token_blind: pallas::Scalar,
-    spend_hook: pallas::Base,
     user_data_blind: pallas::Base,
     signature_secret: SecretKey,
 ) -> Result<(Proof, MoneyStakeBurnRevealed)> {
@@ -176,7 +173,7 @@ pub fn create_stake_burn_proof(
         pallas::Base::from(input.note.value),
         input.note.token_id.inner(),
         input.note.serial,
-        spend_hook,
+        input.note.spend_hook,
         input.note.user_data,
         input.note.coin_blind,
     ]);
@@ -204,7 +201,7 @@ pub fn create_stake_burn_proof(
         token_commit,
         nullifier,
         merkle_root,
-        spend_hook,
+        spend_hook: input.note.spend_hook,
         user_data_enc,
         signature_public,
     };
@@ -215,7 +212,7 @@ pub fn create_stake_burn_proof(
         Witness::Scalar(Value::known(value_blind)),
         Witness::Scalar(Value::known(token_blind)),
         Witness::Base(Value::known(input.note.serial)),
-        Witness::Base(Value::known(spend_hook)),
+        Witness::Base(Value::known(input.note.spend_hook)),
         Witness::Base(Value::known(input.note.user_data)),
         Witness::Base(Value::known(user_data_blind)),
         Witness::Base(Value::known(input.note.coin_blind)),

+ 4 - 14
src/contract/money/src/entrypoint/stake_v1.rs

@@ -125,12 +125,7 @@ pub(crate) fn money_stake_process_instruction_v1(
         return Err(MoneyError::DuplicateNullifier.into())
     }
 
-    // Check if spend hook is set and its correctness
-    if input.spend_hook == pallas::Base::zero() {
-        msg!("[MoneyStakeV1] Error: Missing spend hook");
-        return Err(MoneyError::StakeMissingSpendHook.into())
-    }
-
+    // Check next call is consensus contract
     let next_call_idx = call_idx + 1;
     if next_call_idx >= calls.len() as u32 {
         msg!("[MoneyStakeV1] Error: next_call_idx out of bounds");
@@ -138,14 +133,9 @@ pub(crate) fn money_stake_process_instruction_v1(
     }
 
     let next = &calls[next_call_idx as usize];
-    if next.contract_id.inner() != input.spend_hook {
-        msg!("[MoneyStakeV1] Error: Invoking contract call does not match spend hook");
-        return Err(MoneyError::SpendHookMismatch.into())
-    }
-
-    if input.spend_hook != CONSENSUS_CONTRACT_ID.inner() {
-        msg!("[MoneyStakeV1] Error: Spend hook is not consensus contract");
-        return Err(MoneyError::StakeSpendHookNotConsensusContract.into())
+    if next.contract_id.inner() != CONSENSUS_CONTRACT_ID.inner() {
+        msg!("[MoneyStakeV1] Error: Next contract call is not consensus contract");
+        return Err(MoneyError::StakeNextCallNotConsensusContract.into())
     }
 
     // At this point the state transition has passed, so we create a state update

+ 3 - 3
src/contract/money/src/error.rs

@@ -80,8 +80,8 @@ pub enum MoneyError {
     #[error("Missing spend hook")]
     StakeMissingSpendHook,
 
-    #[error("Spend hook is not consensus contract")]
-    StakeSpendHookNotConsensusContract,
+    #[error("Next contract call is not consensus contract")]
+    StakeNextCallNotConsensusContract,
 
     #[error("Spend hook is not money contract")]
     UnstakeSpendHookNotMoneyContract,
@@ -110,7 +110,7 @@ impl From<MoneyError> for ContractError {
             MoneyError::MintFrozen => Self::Custom(18),
             MoneyError::StakeInputNonNativeToken => Self::Custom(19),
             MoneyError::StakeMissingSpendHook => Self::Custom(20),
-            MoneyError::StakeSpendHookNotConsensusContract => Self::Custom(21),
+            MoneyError::StakeNextCallNotConsensusContract => Self::Custom(21),
             MoneyError::UnstakeSpendHookNotMoneyContract => Self::Custom(21),
         }
     }