-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...c/execution/validation/state_transition/state_transitions/masternode_vote/nonce/v1/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::error::Error; | ||
use dpp::block::block_info::BlockInfo; | ||
use dpp::consensus::basic::document::NonceOutOfBoundsError; | ||
use dpp::consensus::basic::BasicError; | ||
use dpp::identity::identity_nonce::{ | ||
validate_identity_nonce_update, validate_new_identity_nonce, MISSING_IDENTITY_REVISIONS_FILTER, | ||
}; | ||
use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; | ||
use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; | ||
|
||
use dpp::validation::SimpleConsensusValidationResult; | ||
|
||
use crate::execution::types::execution_operation::ValidationOperation; | ||
use crate::execution::types::state_transition_execution_context::{ | ||
StateTransitionExecutionContext, StateTransitionExecutionContextMethodsV0, | ||
}; | ||
use crate::platform_types::platform::PlatformStateRef; | ||
use dpp::version::PlatformVersion; | ||
use drive::grovedb::TransactionArg; | ||
|
||
pub(in crate::execution::validation::state_transition::state_transitions) trait MasternodeVoteTransitionIdentityNonceV1 | ||
{ | ||
fn validate_nonce_v1( | ||
&self, | ||
platform: &PlatformStateRef, | ||
block_info: &BlockInfo, | ||
tx: TransactionArg, | ||
execution_context: &mut StateTransitionExecutionContext, | ||
platform_version: &PlatformVersion, | ||
) -> Result<SimpleConsensusValidationResult, Error>; | ||
} | ||
|
||
impl MasternodeVoteTransitionIdentityNonceV1 for MasternodeVoteTransition { | ||
fn validate_nonce_v1( | ||
&self, | ||
platform: &PlatformStateRef, | ||
block_info: &BlockInfo, | ||
tx: TransactionArg, | ||
execution_context: &mut StateTransitionExecutionContext, | ||
platform_version: &PlatformVersion, | ||
) -> Result<SimpleConsensusValidationResult, Error> { | ||
let revision_nonce = self.nonce(); | ||
|
||
if revision_nonce & MISSING_IDENTITY_REVISIONS_FILTER > 0 { | ||
return Ok(SimpleConsensusValidationResult::new_with_error( | ||
BasicError::NonceOutOfBoundsError(NonceOutOfBoundsError::new(revision_nonce)) | ||
.into(), | ||
)); | ||
} | ||
|
||
let voter_identity_id = self.voter_identity_id(); | ||
|
||
let (existing_nonce, fee) = platform.drive.fetch_identity_nonce_with_fees( | ||
voter_identity_id.to_buffer(), | ||
block_info, | ||
true, | ||
tx, | ||
platform_version, | ||
)?; | ||
|
||
execution_context.add_operation(ValidationOperation::PrecalculatedOperation(fee)); | ||
|
||
let result = if let Some(existing_nonce) = existing_nonce { | ||
validate_identity_nonce_update(existing_nonce, revision_nonce, voter_identity_id) | ||
} else { | ||
validate_new_identity_nonce(revision_nonce, voter_identity_id) | ||
}; | ||
|
||
Ok(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
.../rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v5.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
use crate::version::drive_abci_versions::drive_abci_validation_versions::{ | ||
DriveAbciAssetLockValidationVersions, DriveAbciDocumentsStateTransitionValidationVersions, | ||
DriveAbciStateTransitionCommonValidationVersions, DriveAbciStateTransitionValidationVersion, | ||
DriveAbciStateTransitionValidationVersions, DriveAbciValidationConstants, | ||
DriveAbciValidationDataTriggerAndBindingVersions, DriveAbciValidationDataTriggerVersions, | ||
DriveAbciValidationVersions, PenaltyAmounts, | ||
}; | ||
|
||
// In this version we change the nonce validation of masternode voting. | ||
// There was a bug before this where the nonce validation would validate using the owner identity | ||
// instead of the voting identity. | ||
// This is not the same issue as before when we didn't validate nonces on masternode votes at all. | ||
pub const DRIVE_ABCI_VALIDATION_VERSIONS_V5: DriveAbciValidationVersions = | ||
DriveAbciValidationVersions { | ||
state_transitions: DriveAbciStateTransitionValidationVersions { | ||
common_validation_methods: DriveAbciStateTransitionCommonValidationVersions { | ||
asset_locks: DriveAbciAssetLockValidationVersions { | ||
fetch_asset_lock_transaction_output_sync: 0, | ||
verify_asset_lock_is_not_spent_and_has_enough_balance: 0, | ||
}, | ||
validate_identity_public_key_contract_bounds: 0, | ||
validate_identity_public_key_ids_dont_exist_in_state: 0, | ||
validate_identity_public_key_ids_exist_in_state: 0, | ||
validate_state_transition_identity_signed: 0, | ||
validate_unique_identity_public_key_hashes_in_state: 0, | ||
validate_master_key_uniqueness: 0, | ||
validate_simple_pre_check_balance: 0, | ||
}, | ||
max_asset_lock_usage_attempts: 16, | ||
identity_create_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(0), | ||
advanced_structure: Some(0), | ||
identity_signatures: Some(0), | ||
advanced_minimum_balance_pre_check: None, | ||
nonce: None, | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
identity_update_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(0), | ||
advanced_structure: Some(0), | ||
identity_signatures: Some(0), | ||
advanced_minimum_balance_pre_check: None, | ||
nonce: Some(0), | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
identity_top_up_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(0), | ||
advanced_structure: None, | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: None, | ||
nonce: None, | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
identity_credit_withdrawal_state_transition: | ||
DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(1), | ||
advanced_structure: None, | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: Some(0), | ||
nonce: Some(0), | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
identity_credit_withdrawal_state_transition_purpose_matches_requirements: 0, | ||
identity_credit_transfer_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(0), | ||
advanced_structure: None, | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: Some(0), | ||
nonce: Some(0), | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
masternode_vote_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: None, | ||
advanced_structure: Some(0), | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: Some(0), | ||
nonce: Some(1), // <---- Changed this here | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
contract_create_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: Some(0), | ||
advanced_structure: None, | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: None, | ||
nonce: Some(0), | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
contract_update_state_transition: DriveAbciStateTransitionValidationVersion { | ||
basic_structure: None, | ||
advanced_structure: None, | ||
identity_signatures: None, | ||
advanced_minimum_balance_pre_check: None, | ||
nonce: Some(0), | ||
state: 0, | ||
transform_into_action: 0, | ||
}, | ||
documents_batch_state_transition: DriveAbciDocumentsStateTransitionValidationVersions { | ||
balance_pre_check: 0, | ||
basic_structure: 0, | ||
advanced_structure: 0, | ||
state: 0, | ||
revision: 0, | ||
transform_into_action: 0, | ||
data_triggers: DriveAbciValidationDataTriggerAndBindingVersions { | ||
bindings: 0, | ||
triggers: DriveAbciValidationDataTriggerVersions { | ||
create_contact_request_data_trigger: 0, | ||
create_domain_data_trigger: 0, | ||
create_identity_data_trigger: 0, | ||
create_feature_flag_data_trigger: 0, | ||
create_masternode_reward_shares_data_trigger: 0, | ||
delete_withdrawal_data_trigger: 0, | ||
reject_data_trigger: 0, | ||
}, | ||
}, | ||
is_allowed: 0, | ||
document_create_transition_structure_validation: 0, | ||
document_delete_transition_structure_validation: 0, | ||
document_replace_transition_structure_validation: 0, | ||
document_transfer_transition_structure_validation: 0, | ||
document_purchase_transition_structure_validation: 0, | ||
document_update_price_transition_structure_validation: 0, | ||
document_create_transition_state_validation: 1, | ||
document_delete_transition_state_validation: 0, | ||
document_replace_transition_state_validation: 0, | ||
document_transfer_transition_state_validation: 0, | ||
document_purchase_transition_state_validation: 0, | ||
document_update_price_transition_state_validation: 0, | ||
}, | ||
}, | ||
has_nonce_validation: 1, | ||
process_state_transition: 0, | ||
state_transition_to_execution_event_for_check_tx: 0, | ||
penalties: PenaltyAmounts { | ||
identity_id_not_correct: 50000000, | ||
unique_key_already_present: 10000000, | ||
validation_of_added_keys_structure_failure: 10000000, | ||
validation_of_added_keys_proof_of_possession_failure: 50000000, | ||
}, | ||
event_constants: DriveAbciValidationConstants { | ||
maximum_vote_polls_to_process: 2, | ||
maximum_contenders_to_consider: 100, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters