Skip to content

Commit

Permalink
Revert "Distinguish invalid opcode and invalid script (ordinals#3400)"
Browse files Browse the repository at this point in the history
This reverts commit 4a8d5ce.
  • Loading branch information
harutyunaraci authored Apr 2, 2024
1 parent f4cce58 commit 0cc66ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 87 deletions.
5 changes: 1 addition & 4 deletions crates/ordinals/src/cenotaph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::*;
pub enum Cenotaph {
EdictOutput,
EdictRuneId,
InvalidScript,
Opcode,
SupplyOverflow,
TrailingIntegers,
Expand All @@ -15,10 +14,9 @@ pub enum Cenotaph {
}

impl Cenotaph {
pub const ALL: [Self; 10] = [
pub const ALL: [Self; 9] = [
Self::EdictOutput,
Self::EdictRuneId,
Self::InvalidScript,
Self::Opcode,
Self::SupplyOverflow,
Self::TrailingIntegers,
Expand All @@ -38,7 +36,6 @@ impl Display for Cenotaph {
match self {
Self::EdictOutput => write!(f, "edict output greater than transaction output count"),
Self::EdictRuneId => write!(f, "invalid rune ID in edict"),
Self::InvalidScript => write!(f, "invalid script in OP_RETURN"),
Self::Opcode => write!(f, "non-pushdata opcode in OP_RETURN"),
Self::SupplyOverflow => write!(f, "supply overflows u128"),
Self::TrailingIntegers => write!(f, "trailing integers in body"),
Expand Down
128 changes: 45 additions & 83 deletions crates/ordinals/src/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,10 @@ impl Runestone {
let mut payload = Vec::new();

for result in instructions {
match result {
Ok(Instruction::PushBytes(push)) => {
payload.extend_from_slice(push.as_bytes());
}
Ok(Instruction::Op(_)) => {
return Ok(Some(Payload::Invalid(Cenotaph::Opcode)));
}
Err(_) => {
return Ok(Some(Payload::Invalid(Cenotaph::InvalidScript)));
}
if let Ok(Instruction::PushBytes(push)) = result {
payload.extend_from_slice(push.as_bytes());
} else {
return Ok(Some(Payload::Invalid(Cenotaph::Opcode)));
}
}

Expand Down Expand Up @@ -437,7 +431,7 @@ mod tests {
lock_time: LockTime::ZERO,
version: 2,
}),
Ok(Some(Payload::Invalid(Cenotaph::InvalidScript)))
Ok(Some(Payload::Invalid(Cenotaph::Opcode)))
);
}

Expand Down Expand Up @@ -1988,82 +1982,50 @@ mod tests {
}

#[test]
fn invalid_scripts_in_op_returns_without_magic_number_are_ignored() {
assert_eq!(
Runestone::decipher(&Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}],
output: vec![TxOut {
script_pubkey: ScriptBuf::from(vec![
opcodes::all::OP_RETURN.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
]),
value: 0,
}],
})
.unwrap(),
None
);
fn invalid_scripts_in_op_returns_are_ignored() {
let transaction = Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}],
output: vec![TxOut {
script_pubkey: ScriptBuf::from(vec![
opcodes::all::OP_RETURN.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
]),
value: 0,
}],
};

assert_eq!(
Runestone::decipher(&Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}],
output: vec![
TxOut {
script_pubkey: ScriptBuf::from(vec![
opcodes::all::OP_RETURN.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
]),
value: 0,
},
TxOut {
script_pubkey: Runestone::default().encipher(),
value: 0,
}
],
})
.unwrap(),
Some(Runestone::default())
);
}
assert_eq!(Runestone::decipher(&transaction).unwrap(), None);

let transaction = Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}],
output: vec![TxOut {
script_pubkey: ScriptBuf::from(vec![
opcodes::all::OP_RETURN.to_u8(),
Runestone::MAGIC_NUMBER.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
]),
value: 0,
}],
};

#[test]
fn invalid_scripts_in_op_returns_with_magic_number_produce_cenotaph() {
assert_eq!(
Runestone::decipher(&Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: ScriptBuf::new(),
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}],
output: vec![TxOut {
script_pubkey: ScriptBuf::from(vec![
opcodes::all::OP_RETURN.to_u8(),
Runestone::MAGIC_NUMBER.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
]),
value: 0,
}],
})
.unwrap(),
Runestone::decipher(&transaction).unwrap(),
Some(Runestone {
cenotaph: Cenotaph::InvalidScript.into(),
cenotaph: Cenotaph::Opcode.into(),
..default()
})
);
Expand Down

0 comments on commit 0cc66ca

Please sign in to comment.