Skip to content

Commit

Permalink
Change rune protocol identifier to OP_PUSHNUM_13 (#3314)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Mar 18, 2024
1 parent 800d447 commit d141f47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/runestone_decipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
fuzz_target!(|input: Vec<Vec<u8>>| {
let mut builder = script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST");
.push_opcode(opcodes::all::OP_PUSHNUM_13);

for slice in input {
let Ok(push): Result<&PushBytes, _> = slice.as_slice().try_into() else {
Expand Down
2 changes: 2 additions & 0 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub use {

pub const MAX_DIVISIBILITY: u8 = 38;
pub const MAX_LIMIT: u128 = 1 << 64;

const RESERVED: u128 = 6402364363415443603228541259936211926;
const MAGIC_NUMBER: opcodes::All = opcodes::all::OP_PUSHNUM_13;

mod edict;
mod etching;
Expand Down
67 changes: 33 additions & 34 deletions src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Runestone {

let mut builder = script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST");
.push_opcode(MAGIC_NUMBER);

for chunk in payload.chunks(MAX_SCRIPT_ELEMENT_SIZE) {
let push: &script::PushBytes = chunk.try_into().unwrap();
Expand All @@ -233,7 +233,7 @@ impl Runestone {
continue;
}

if instructions.next().transpose()? != Some(Instruction::PushBytes(b"RUNE_TEST".into())) {
if instructions.next().transpose()? != Some(Instruction::Op(MAGIC_NUMBER)) {
continue;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice(payload)
.into_script(),
value: 0,
Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
fn deciphering_valid_runestone_with_invalid_script_postfix_returns_script_error() {
let mut script_pubkey = script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.into_script()
.into_bytes();

Expand All @@ -426,7 +426,7 @@ mod tests {
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice([128])
.into_script(),
value: 0,
Expand All @@ -445,7 +445,7 @@ mod tests {
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice([0, 1])
.push_opcode(opcodes::all::OP_VERIFY)
.push_slice([2, 0])
Expand Down Expand Up @@ -476,7 +476,7 @@ mod tests {
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.into_script(),
value: 0
}],
Expand All @@ -493,11 +493,12 @@ mod tests {

let payload: &PushBytes = payload.as_slice().try_into().unwrap();

let mut script_pubkey = Vec::new();
script_pubkey.push(opcodes::all::OP_RETURN.to_u8());
script_pubkey.push(opcodes::all::OP_PUSHBYTES_9.to_u8());
script_pubkey.extend_from_slice(b"RUNE_TEST");
script_pubkey.push(opcodes::all::OP_PUSHBYTES_4.to_u8());
let script_pubkey = vec![
opcodes::all::OP_RETURN.to_u8(),
opcodes::all::OP_PUSHBYTES_9.to_u8(),
MAGIC_NUMBER.to_u8(),
opcodes::all::OP_PUSHBYTES_4.to_u8(),
];

Runestone::decipher(&Transaction {
input: Vec::new(),
Expand All @@ -509,7 +510,7 @@ mod tests {
TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice(payload)
.into_script(),
value: 0,
Expand Down Expand Up @@ -1109,7 +1110,7 @@ mod tests {
output: vec![TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice::<&PushBytes>(
varint::encode(Tag::Flags.into())
.as_slice()
Expand Down Expand Up @@ -1176,7 +1177,7 @@ mod tests {
TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice(payload)
.into_script(),
value: 0
Expand Down Expand Up @@ -1216,7 +1217,7 @@ mod tests {
TxOut {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(b"RUNE_TEST")
.push_opcode(MAGIC_NUMBER)
.push_slice(payload)
.into_script(),
value: 0
Expand Down Expand Up @@ -1247,22 +1248,20 @@ mod tests {
..Default::default()
}
.encipher()
.len()
- 1
- b"RUNE_TEST".len(),
.len(),
size
);
}

case(Vec::new(), None, 1);
case(Vec::new(), None, 2);

case(
Vec::new(),
Some(Etching {
rune: Some(Rune(0)),
..Default::default()
}),
6,
7,
);

case(
Expand All @@ -1272,7 +1271,7 @@ mod tests {
rune: Some(Rune(0)),
..Default::default()
}),
8,
9,
);

case(
Expand All @@ -1288,7 +1287,7 @@ mod tests {
symbol: Some('$'),
spacers: 1,
}),
19,
20,
);

case(
Expand All @@ -1297,7 +1296,7 @@ mod tests {
rune: Some(Rune(u128::MAX)),
..Default::default()
}),
24,
25,
);

case(
Expand All @@ -1311,7 +1310,7 @@ mod tests {
rune: Some(Rune(u128::MAX)),
..Default::default()
}),
30,
31,
);

case(
Expand All @@ -1325,7 +1324,7 @@ mod tests {
rune: Some(Rune(u128::MAX)),
..Default::default()
}),
48,
49,
);

case(
Expand All @@ -1338,7 +1337,7 @@ mod tests {
output: 0,
}],
None,
11,
12,
);

case(
Expand All @@ -1351,7 +1350,7 @@ mod tests {
output: 0,
}],
None,
29,
30,
);

case(
Expand All @@ -1374,7 +1373,7 @@ mod tests {
},
],
None,
50,
51,
);

case(
Expand Down Expand Up @@ -1405,7 +1404,7 @@ mod tests {
},
],
None,
71,
72,
);

case(
Expand All @@ -1421,7 +1420,7 @@ mod tests {
4
],
None,
56,
57,
);

case(
Expand All @@ -1437,7 +1436,7 @@ mod tests {
5
],
None,
68,
69,
);

case(
Expand All @@ -1453,7 +1452,7 @@ mod tests {
5
],
None,
65,
66,
);

case(
Expand All @@ -1469,7 +1468,7 @@ mod tests {
5
],
None,
63,
64,
);
}

Expand Down

0 comments on commit d141f47

Please sign in to comment.