Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid runestones are cenotaphs #3325

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {

let mut unallocated = self.unallocated(tx)?;

let burn = runestone
let cenotaph = runestone
.as_ref()
.map(|runestone| runestone.burn)
.map(|runestone| runestone.cenotaph)
.unwrap_or_default();

let default_output = runestone.as_ref().and_then(|runestone| {
Expand All @@ -81,7 +81,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {

let mut etched = self.etched(tx_index, tx, &runestone)?;

if !burn {
if !cenotaph {
for Edict { id, amount, output } in runestone.edicts {
let Ok(output) = usize::try_from(output) else {
continue;
Expand Down Expand Up @@ -158,13 +158,13 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
}

if let Some(etched) = etched {
self.create_rune_entry(txid, burn, etched)?;
self.create_rune_entry(txid, cenotaph, etched)?;
}
}

let mut burned: HashMap<RuneId, u128> = HashMap::new();

if burn {
if cenotaph {
for (id, balance) in unallocated {
*burned.entry(id).or_default() += balance;
}
Expand Down
16 changes: 8 additions & 8 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ mod tests {
}

#[test]
fn etched_rune_is_allocated_with_zero_supply_for_burned_runestone() {
fn etched_rune_is_allocated_with_zero_supply_for_cenotaph() {
let context = Context::builder().arg("--index-runes").build();

let (txid0, id) = context.etch(
Expand All @@ -763,7 +763,7 @@ mod tests {
..Default::default()
}),
default_output: None,
burn: true,
cenotaph: true,
..Default::default()
},
1,
Expand All @@ -784,7 +784,7 @@ mod tests {
}

#[test]
fn etched_rune_open_etching_parameters_are_unset_for_burned_runestone() {
fn etched_rune_open_etching_parameters_are_unset_for_cenotaph() {
let context = Context::builder().arg("--index-runes").build();

let (txid0, id) = context.etch(
Expand All @@ -805,7 +805,7 @@ mod tests {
symbol: Some('$'),
spacers: 1,
}),
burn: true,
cenotaph: true,
..Default::default()
},
1,
Expand Down Expand Up @@ -834,7 +834,7 @@ mod tests {
}

#[test]
fn etched_reserved_rune_is_allocated_with_zero_supply_for_burned_runestone() {
fn etched_reserved_rune_is_allocated_with_zero_supply_in_cenotaph() {
let context = Context::builder().arg("--index-runes").build();

context.mine_blocks(1);
Expand All @@ -849,7 +849,7 @@ mod tests {
output: 0,
}],
etching: Some(Etching::default()),
burn: true,
cenotaph: true,
..Default::default()
}
.encipher(),
Expand Down Expand Up @@ -920,7 +920,7 @@ mod tests {
inputs: &[(id.block.try_into().unwrap(), 1, 0, Witness::new())],
op_return: Some(
Runestone {
burn: true,
cenotaph: true,
..Default::default()
}
.encipher(),
Expand Down Expand Up @@ -3855,7 +3855,7 @@ mod tests {
inputs: &[(5, 0, 0, Witness::new())],
op_return: Some(
Runestone {
burn: true,
cenotaph: true,
claim: Some(id),
edicts: vec![Edict {
id,
Expand Down
4 changes: 2 additions & 2 deletions src/runes/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub(super) enum Flag {
Etch = 0,
Mint = 1,
#[allow(unused)]
Burn = 127,
Cenotaph = 127,
}

impl Flag {
Expand All @@ -29,7 +29,7 @@ mod tests {
#[test]
fn mask() {
assert_eq!(Flag::Etch.mask(), 0b1);
assert_eq!(Flag::Burn.mask(), 1 << 127);
assert_eq!(Flag::Cenotaph.mask(), 1 << 127);
}

#[test]
Expand Down
52 changes: 26 additions & 26 deletions src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const MAX_SPACERS: u32 = 0b00000111_11111111_11111111_11111111;

#[derive(Default, Serialize, Debug, PartialEq)]
pub struct Runestone {
pub burn: bool,
pub cenotaph: bool,
pub claim: Option<RuneId>,
pub default_output: Option<u32>,
pub edicts: Vec<Edict>,
pub etching: Option<Etching>,
}

struct Message {
burn: bool,
cenotaph: bool,
edicts: Vec<Edict>,
fields: HashMap<u128, u128>,
}
Expand All @@ -21,7 +21,7 @@ impl Message {
fn from_integers(tx: &Transaction, payload: &[u128]) -> Self {
let mut edicts = Vec::new();
let mut fields = HashMap::new();
let mut burn = false;
let mut cenotaph = false;

for i in (0..payload.len()).step_by(2) {
let tag = payload[i];
Expand All @@ -34,7 +34,7 @@ impl Message {
if let Some(edict) = Edict::from_integers(tx, id, chunk[1], chunk[2]) {
edicts.push(edict);
} else {
burn = true;
cenotaph = true;
}
}
break;
Expand All @@ -48,7 +48,7 @@ impl Message {
}

Self {
burn,
cenotaph,
edicts,
fields,
}
Expand All @@ -68,7 +68,7 @@ impl Runestone {
let integers = Runestone::integers(&payload);

let Message {
burn,
cenotaph,
edicts,
mut fields,
} = Message::from_integers(transaction, &integers);
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Runestone {
};

Ok(Some(Self {
burn: burn || flags != 0 || fields.keys().any(|tag| tag % 2 == 0),
cenotaph: cenotaph || flags != 0 || fields.keys().any(|tag| tag % 2 == 0),
claim: claim.and_then(|claim| claim.try_into().ok()),
default_output,
edicts,
Expand Down Expand Up @@ -193,8 +193,8 @@ impl Runestone {
Tag::DefaultOutput.encode(default_output.into(), &mut payload);
}

if self.burn {
Tag::Burn.encode(0, &mut payload);
if self.cenotaph {
Tag::Cenotaph.encode(0, &mut payload);
}

if !self.edicts.is_empty() {
Expand Down Expand Up @@ -733,10 +733,10 @@ mod tests {
}

#[test]
fn unrecognized_even_tag_is_burn() {
fn runestone_with_unrecognized_even_tag_is_cenotaph() {
assert_eq!(
decipher(&[
Tag::Burn.into(),
Tag::Cenotaph.into(),
0,
Tag::Body.into(),
rune_id(1).into(),
Expand All @@ -749,18 +749,18 @@ mod tests {
amount: 2,
output: 0,
}],
burn: true,
cenotaph: true,
..Default::default()
},
);
}

#[test]
fn unrecognized_flag_is_burn() {
fn runestone_with_unrecognized_flag_is_cenotaph() {
assert_eq!(
decipher(&[
Tag::Flags.into(),
Flag::Burn.mask(),
Flag::Cenotaph.mask(),
Tag::Body.into(),
rune_id(1).into(),
2,
Expand All @@ -772,31 +772,31 @@ mod tests {
amount: 2,
output: 0,
}],
burn: true,
cenotaph: true,
..Default::default()
},
);
}

#[test]
fn rune_id_with_zero_block_and_nonzero_tx_is_burn() {
fn runestone_with_edict_id_with_zero_block_and_nonzero_tx_is_cenotaph() {
pretty_assert_eq!(
decipher(&[Tag::Body.into(), RuneId { block: 0, tx: 1 }.into(), 2, 0]),
Runestone {
edicts: Vec::new(),
burn: true,
cenotaph: true,
..Default::default()
},
);
}

#[test]
fn output_over_max_is_burn() {
fn runestone_with_output_over_max_is_cenotaph() {
pretty_assert_eq!(
decipher(&[Tag::Body.into(), 1, 2, 2]),
Runestone {
edicts: Vec::new(),
burn: true,
cenotaph: true,
..Default::default()
},
);
Expand Down Expand Up @@ -1128,7 +1128,7 @@ mod tests {
amount: 2,
output: 0,
}],
burn: true,
cenotaph: true,
..Default::default()
},
);
Expand Down Expand Up @@ -1588,7 +1588,7 @@ mod tests {
},
],
default_output: Some(11),
burn: true,
cenotaph: true,
claim: Some(RuneId::try_from(12).unwrap()),
},
&[
Expand All @@ -1612,7 +1612,7 @@ mod tests {
12,
Tag::DefaultOutput.into(),
11,
Tag::Burn.into(),
Tag::Cenotaph.into(),
0,
Tag::Body.into(),
rune_id(6).into(),
Expand All @@ -1633,7 +1633,7 @@ mod tests {
rune: Some(Rune(3)),
spacers: 0,
}),
burn: false,
cenotaph: false,
..Default::default()
},
&[Tag::Flags.into(), Flag::Etch.mask(), Tag::Rune.into(), 3],
Expand All @@ -1648,18 +1648,18 @@ mod tests {
rune: None,
spacers: 0,
}),
burn: false,
cenotaph: false,
..Default::default()
},
&[Tag::Flags.into(), Flag::Etch.mask()],
);

case(
Runestone {
burn: true,
cenotaph: true,
..Default::default()
},
&[Tag::Burn.into(), 0],
&[Tag::Cenotaph.into(), 0],
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/runes/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(super) enum Tag {
DefaultOutput = 12,
Claim = 14,
#[allow(unused)]
Burn = 126,
Cenotaph = 126,

Divisibility = 1,
Spacers = 3,
Expand Down Expand Up @@ -86,7 +86,7 @@ mod tests {
#[test]
fn burn_and_nop_are_one_byte() {
let mut payload = Vec::new();
Tag::Burn.encode(0, &mut payload);
Tag::Cenotaph.encode(0, &mut payload);
assert_eq!(payload.len(), 2);

let mut payload = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl Batch {
}

let script_pubkey = Runestone {
burn: false,
cenotaph: false,
claim: None,
default_output: None,
edicts,
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() {
amount: 750,
output: 2
}],
burn: false,
cenotaph: false,
claim: None,
},
);
Expand Down
Loading