Skip to content

Instantly share code, notes, and snippets.

@mablr
Last active September 21, 2024 21:27
Show Gist options
  • Save mablr/035177034ff09bdf2d92acc50f21f80a to your computer and use it in GitHub Desktop.
Save mablr/035177034ff09bdf2d92acc50f21f80a to your computer and use it in GitHub Desktop.
Fancy EIP-1014

Address is expected to start with 000000.

running 1 test
test tests::test_alloy has been running for over 60 seconds
Found matching address: 0x0000004b2284982bb9a7482bfb76c721631260fe, for salt: 0x0000000000000000000000000000000000000000000000000000000000f17dfe
test tests::test_alloy ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 520.59s
use alloy_core::primitives::{Address, FixedBytes, U256};
fn increment_fixed_bytes(val: &mut FixedBytes<32>) {
let bytes: &mut [u8] = val.as_mut_slice();
for byte in bytes.iter_mut().rev() {
if *byte < 255 {
*byte += 1;
break;
} else {
*byte = 0;
}
}
}
fn find_matching_address(sender: Address, init_code_hash: FixedBytes<32>, pattern: Address, mask: Address) {
let mut salt: FixedBytes<32> = FixedBytes::from(U256::ZERO);
loop {
let address: Address = sender.create2(salt, init_code_hash);
if address.bit_and(mask).bit_xor(pattern).is_zero() {
println!("Found matching address: {:?}, for salt: {:?}", address, salt);
break;
}
increment_fixed_bytes(&mut salt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment