Skip to content

Commit

Permalink
Ignore non push opcodes in runestones (#2553)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 24, 2023
1 parent 7f872a3 commit 15faa09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/runes/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::*;

#[derive(Debug, PartialEq)]
pub enum Error {
Opcode(opcodes::All),
Script(script::Error),
Varint,
}
Expand All @@ -16,7 +15,6 @@ impl From<script::Error> for Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Opcode(op) => write!(f, "non-push opcode {op} in payload"),
Self::Script(err) => write!(f, "failed to parse script: {err}"),
Self::Varint => write!(f, "varint over maximum value"),
}
Expand Down
53 changes: 30 additions & 23 deletions src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ impl Runestone {
let mut payload = Vec::new();

for result in instructions {
match result? {
Instruction::PushBytes(push) => payload.extend_from_slice(push.as_bytes()),
Instruction::Op(op) => return Err(Error::Opcode(op)),
if let Instruction::PushBytes(push) = result? {
payload.extend_from_slice(push.as_bytes());
}
}

Expand Down Expand Up @@ -331,26 +330,34 @@ mod tests {
}

#[test]
fn deciphering_runestone_with_non_push_opcode_returns_opcode_error() {
let result = Runestone::decipher(&Transaction {
input: Vec::new(),
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(opcodes::all::OP_VERIFY)
.into_script(),
value: 0,
}],
lock_time: locktime::absolute::LockTime::ZERO,
version: 0,
});

match result {
Ok(_) => panic!("expected error"),
Err(Error::Opcode(opcodes::all::OP_VERIFY)) => {}
Err(err) => panic!("unexpected error: {err}"),
}
fn non_push_opcodes_in_runestone_are_ignored() {
assert_eq!(
Runestone::decipher(&Transaction {
input: Vec::new(),
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_slice([0, 1])
.push_opcode(opcodes::all::OP_VERIFY)
.push_slice([2, 3])
.into_script(),
value: 0,
}],
lock_time: locktime::absolute::LockTime::ZERO,
version: 0,
})
.unwrap()
.unwrap(),
Runestone {
edicts: vec![Edict {
id: 1,
amount: 2,
output: 3,
}],
..Default::default()
},
);
}

#[test]
Expand Down

0 comments on commit 15faa09

Please sign in to comment.