Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staking transactions are not enforced to be to / from the staking contract #2605

Closed
danimoh opened this issue Jun 13, 2024 · 2 comments · Fixed by #2634
Closed

Staking transactions are not enforced to be to / from the staking contract #2605

danimoh opened this issue Jun 13, 2024 · 2 comments · Fixed by #2634
Assignees

Comments

@danimoh
Copy link
Member

danimoh commented Jun 13, 2024

verify of Transaction currently checks that the Staking sender / recipient type must be set, if the the sender / recipient address is the staking contract, but does not enforce that the sender / recipient must be the staking contract, if the sender / recipient sender type is Staking.
Verification of the sender / recipient data, and potentially later processing of the data, are solely based on the sender / recipient type though.
Thus, it might be possible to, for example, send a transaction that is interpreted as a staking transaction, via the Staking sender / recipient type, which is not in fact to / from the staking contract.

if self.recipient == Policy::STAKING_CONTRACT_ADDRESS
&& self.recipient_type != AccountType::Staking
{
return Err(TransactionError::InvalidForRecipient);
}
// Should not be necessary as the sender would have to sign the transaction
// and the private key for the staking contract is unknown
if self.sender == Policy::STAKING_CONTRACT_ADDRESS
&& self.sender_type != AccountType::Staking
{
return Err(TransactionError::InvalidForSender);
}

PS: I did not confirm the issue on-chain, just filing this issue based on reading the code.

@styppo
Copy link
Member

styppo commented Jun 14, 2024

There is a check here that the target account has the correct type when applying the transaction, so a transaction with an invalid sender/recipient type would not be accepted. We could however add an additional check to the intrinsic transaction verification to reject such transactions early, i.e. before attempting to apply them.

@sisou
Copy link
Member

sisou commented Jun 14, 2024

With the existing check, the transaction can still enter the mempool I guess? But then not get accepted into block, so filling up the mempool?

@styppo styppo added this to the Nimiq PoS Mainnet milestone Jun 17, 2024
@styppo styppo self-assigned this Jun 17, 2024
styppo added a commit that referenced this issue Jun 17, 2024
@hrxi hrxi closed this as completed in 89fee43 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants