Skip to content

KIP 17 implementation#797

Merged
someone235 merged 21 commits intokaspanet:covppfrom
someone235:covenants
Jan 1, 2026
Merged

KIP 17 implementation#797
someone235 merged 21 commits intokaspanet:covppfrom
someone235:covenants

Conversation

@someone235
Copy link
Copy Markdown
Contributor

See KIP 17 for details.

Pending PR for KIP 17: kaspanet/kips#32

Comment thread consensus/core/src/hashing/tx.rs Outdated
}

pub fn transaction_id_preimage(tx: &Transaction) -> Vec<u8> {
let mut hasher = PreimageHasher { buff: vec![] };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can calculate capacity and preallocate vector to avoid allocation when vector grows. However I don't see usages except tests and examples, maybe it's not needed to be done

impl From<Vec<Vec<u8>>> for Stack {
fn from(inner: Vec<Vec<u8>>) -> Self {
// TODO: Replace with the correct max element size after the fork.
Self { inner, max_element_size: usize::MAX }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to set it to 520?

Comment thread crypto/txscript/src/data_stack.rs Outdated
}

#[cfg(test)]
pub(crate) fn get_inner(&self) -> Vec<Vec<u8>> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common name and signature are into_inner(self) or inner(&self) -> &T, in both cases it's up to caller to clone or not

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
return Err(TxScriptError::InvalidState("expected boolean".to_string()));
}
cond = match cond_buf.pop() {
Some(stack_cond) => match stack_cond {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be rewritten with

cond = match cond_buf.pop() {
    Some(1) => OpCond::True,
    Some(_) => return Err(TxScriptError::InvalidState("expected boolean".to_string())),
    None => OpCond::False,
};

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
return Err(TxScriptError::InvalidState("expected boolean".to_string()));
}
cond = match cond_buf.pop() {
Some(stack_cond) => match stack_cond {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding "match"

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
opcode OpInvert<0x83, 1>(self, vm){
if vm.flags.covenants_enabled{
let data = vm.dstack.pop()?;
let r: Vec<u8> = data.iter().map(|b| !b).collect();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to update data in place data.iter_mut().for_each(|b| *b = !*b);
And push it back onto stack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using into_iter instead to consume the vector (same for similar comments)

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
if a.len() != b.len() {
return Err(TxScriptError::InvalidState("AND operands must be of equal length".to_string()));
}
let r: Vec<u8> = a.iter().zip(b.iter()).map(|(a_byte, b_byte)| a_byte & b_byte).collect();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it also makes sense to use iter mut and reuse one of already existing vectors overriding values instead of allocating the new one

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
if a.len() != b.len() {
return Err(TxScriptError::InvalidState("OR operands must be of equal length".to_string()));
}
let r: Vec<u8> = a.iter().zip(b.iter()).map(|(a_byte, b_byte)| a_byte | b_byte).collect();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
if a.len() != b.len() {
return Err(TxScriptError::InvalidState("XOR operands must be of equal length".to_string()));
}
let r: Vec<u8> = a.iter().zip(b.iter()).map(|(a_byte, b_byte)| a_byte ^ b_byte).collect();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread crypto/txscript/src/opcodes/mod.rs Outdated
opcode OpMod<0x97, 1>(self, vm){
if vm.flags.covenants_enabled{
let [ a, b ]: [i64; 2] = vm.dstack.pop_items()?;
// TODO (before merge): Check with other implementations if they handle negative numbers differently.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actual? Anyone use rem_euclid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I validated it against BCH code with 1000 i64 numbers drawn randomly, and it seems to be compatible

let mut next_id: u64 = 1;
let mut tip = config.genesis.hash;

// Redeem script that uses OpCat (disabled before covenants activation, enabled after)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't contain opcat

}
assert_eq!(consensus.get_virtual_daa_score(), ACTIVATION_DAA_SCORE - 1);

// Pre-activation: inserting block with the covenant opcode should be rejected
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it use covenant opcode? Actually this block is accepted

@someone235 someone235 changed the base branch from master to covpp January 1, 2026 13:14
@someone235 someone235 merged commit e2b77bb into kaspanet:covpp Jan 1, 2026
6 checks passed
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 this pull request may close these issues.

2 participants