Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions core/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,19 @@ impl CommitSequenceVerifier {
agenda_proof: agenda_proof.clone(),
};
}
(Commit::ExtraAgendaTransaction(tx), Phase::AgendaProof { agenda_proof: _ }) => {
(Commit::ExtraAgendaTransaction(tx), Phase::AgendaProof { agenda_proof }) => {
match tx {
ExtraAgendaTransaction::Delegate(tx) => {
// Update reserved reserved_state by applying delegation
self.reserved_state.apply_delegate(tx).map_err(|e| {
Error::InvalidArgument(format!("invalid delegation: {e}"))
})?;
// Check if extra-agenda transactions are in chronological order
if tx.data.timestamp < agenda_proof.timestamp {
return Err(Error::InvalidArgument(
format!("invalid extra-agenda transaction timestamp: expected larger than or equal to the last transaction timestamp {}, got {}", agenda_proof.timestamp, tx.data.timestamp)
));
}
self.phase = Phase::ExtraAgendaTransaction {
last_extra_agenda_timestamp: tx.data.timestamp,
};
Expand Down Expand Up @@ -2198,10 +2204,47 @@ mod test {
#[ignore]
#[test]
// Test the case where the `Delegate` extra-agenda transaction is invalid because the timestamp is invalid.
/// This test case is ignored because the extra-agenda transaction is not implemented yet.
// TODO: enable this test case when the extra-agenda transaction is implemented.
fn invalid_delegate_transaction_with_invalid_timestamp() {
todo!("Implement this test")
let (validator_keypair, reserved_state, mut csv) = setup_test(4);
// Apply agenda commit
let agenda_transactions_hash = calculate_agenda_transactions_hash(csv.phase.clone());
let agenda: Agenda = Agenda {
author: reserved_state.query_name(&validator_keypair[0].0).unwrap(),
timestamp: 1,
transactions_hash: agenda_transactions_hash,
height: csv.header.height + 1,
previous_block_hash: csv.header.to_hash256(),
};
csv.apply_commit(&generate_agenda_commit(&agenda)).unwrap();
// Apply agenda-proof commit
csv.apply_commit(&generate_agenda_proof_commit(
&validator_keypair,
&agenda,
agenda.to_hash256(),
))
.unwrap();
// Apply extra-agenda transaction commit
// delegator: member-0, delegatee: member-1
let delegator = reserved_state.members[0].clone();
let valid_delegator_private_key = validator_keypair[0].1.clone();
// Apply delegation transaction with invalid timestamp
let delegatee = reserved_state.members[1].clone();
let delegation_transaction_data: DelegationTransactionData = DelegationTransactionData {
delegator: delegator.name,
delegatee: delegatee.name,
governance: true,
block_height: csv.header.height + 1,
timestamp: -1,
chain_name: reserved_state.genesis_info.chain_name,
};
let proof =
TypedSignature::sign(&delegation_transaction_data, &valid_delegator_private_key)
.unwrap();
csv.apply_commit(&generate_delegation_transaction_commit(
&delegation_transaction_data,
proof,
))
.unwrap_err();
}

#[ignore]
Expand Down