2023 Mar 26
Got this error for this rust macro:
macro_rules! extend_secret_prefix_mac { ($mac:ident, $message:ident, $extension:ident, $digest_to_state:ident, $pad:ident, $hash_from_state:ident, $check:ident, $default:ident) => {{ let mut new_mac = $default; let state = $digest_to_state(&$mac); for key_len in 0..=64 { let full_input_len = key_len + $message.len() as u64; let padding = $pad(full_input_len); let digest = $hash_from_state($extension, full_input_len + padding.len() as u64, &state); let final_message = [$message, &padding[..], $extension].concat(); if $check(&digest, &final_message) { new_mac = digest.clone(); break; } } new_mac }}; }
It gave me this error that
digest
andfinal_message
didn’t live long enough to be borrowed. I thought this was odd because the function I modeled this after didn’t face the same problem. I learned that here it doesn’t know if$check
will use these functions after the loop iteration is done, which I’m still sort of confused why that’s the case but it does explain the error. I asked GPT if I could tell the macro somehow that it doesn’t use these values and it said there wasn’t a way other than changing the$check
function to take ownership of the value instead of references. Hmph. Feel like I’m using the macro wrong, like I’m treating it too much as a function that I want to pass functions into without making a generic interface for those functions heh…But it feels like I should be able to somewhat easily generalize this length extension attack to different hashes the way I’m intending but I just don’t know how.Would be cool if there was a cryptopals equivalent specific for Bitcoin. Could call it bitcoinpals.
Do watchtowers claim revoked HTLCs? (not like claiming using the preimage, but like if the HTLC tx confirmed would a watchtower take that? (I guess the watchtower should’ve just revoked before that?)