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

Use lazy_static initialisation or compile time optimisation to prevent re-initialisation of script hash #377

Closed
phklive opened this issue Dec 21, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@phklive
Copy link
Contributor

phklive commented Dec 21, 2023

Use lazy_static initialisation or compile time optimisation to prevent re-initialisation of script hash every time a swap script is used:

/// Utility function generating RECIPIENT for the P2ID note script created by the SWAP script
fn build_p2id_recipient(target: AccountId, serial_num: Word) -> Result<Digest, NoteError> {
// TODO: add lazy_static initialization or compile-time optimization instead of re-generating
// the script hash every time we call the SWAP script
let assembler = assembler();
let p2id_bytes = include_bytes!(concat!(env!("OUT_DIR"), "/assets/P2ID.masb"));
let note_script_ast =
ProgramAst::from_bytes(p2id_bytes).map_err(NoteError::NoteDeserializationError)?;
let (note_script, _) = NoteScript::new(note_script_ast, &assembler)?;
let script_hash = note_script.hash();
let serial_num_hash = Hasher::merge(&[serial_num.into(), Digest::default()]);
let merge_script = Hasher::merge(&[serial_num_hash, script_hash]);
Ok(Hasher::merge(&[
merge_script,
Hasher::hash_elements(&[target.into(), ZERO, ZERO, ZERO]),
]))
}

To improve this function

@bobbinth bobbinth added the enhancement New feature or request label Mar 11, 2024
@bobbinth bobbinth added this to the v0.3 milestone Apr 11, 2024
@bobbinth
Copy link
Contributor

This should be solved by migrating to the MAST-based script format.

@bobbinth
Copy link
Contributor

Closed by #939.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

3 participants