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

STR-728: Key Derivation Crate #520

Merged
merged 62 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c91de7f
feat: add key-derivation crate
storopoli Dec 4, 2024
06c0a63
chore(CODEOWNERS): add key-derivation
storopoli Dec 4, 2024
dc2e810
feat: operator xprivs
storopoli Dec 4, 2024
50a956c
errors: better imports and impls
storopoli Dec 5, 2024
5cf9334
operator: add master Xpriv
storopoli Dec 5, 2024
3491226
chore: move away from miniscript
storopoli Dec 5, 2024
86446ef
test: right addresses
storopoli Dec 5, 2024
e9d59ad
fix: operator derivation path naming
storopoli Dec 6, 2024
8b503e9
test: signatures are OK
storopoli Dec 6, 2024
43ffc39
chore: move zeroize to workspace
storopoli Dec 6, 2024
56e31ca
operator: zeroize impls for OperatorKeys
storopoli Dec 6, 2024
ab2d9cc
fmt: sequencer
storopoli Dec 6, 2024
33742a0
fix: feature-gate on default the imports
storopoli Dec 6, 2024
83f0a25
bridge-client: refactor to use key-derivation
storopoli Dec 6, 2024
d03e7df
fix: don't need zeroize derive feature
storopoli Dec 6, 2024
7d43f26
operator: fix derivation paths
storopoli Dec 6, 2024
1b64823
feat(bridge-client): parse xpriv from env or path
storopoli Dec 6, 2024
59a68b9
chore: add secp256k1
storopoli Dec 6, 2024
f9ad4b0
sequencer: SequencerKeys
storopoli Dec 6, 2024
7c77f06
strata-client: use key-derivation crate
storopoli Dec 6, 2024
75c4c74
fix: use &Xpriv instead of owned in OperatorKeys
storopoli Dec 9, 2024
120b9c9
feat: really zeroize stuff
storopoli Dec 9, 2024
59b8bb1
refactor(datatool): modularization
storopoli Dec 9, 2024
9703a9e
Look at me I’m the compiler now!
storopoli Dec 9, 2024
a9293a0
key-derivation: Sequencer and Operator PubKeys
storopoli Dec 9, 2024
d41d883
datatool: refactor to use key-derivation crate
storopoli Dec 9, 2024
4eb8391
doc: rugpulled by copy-pasta
storopoli Dec 9, 2024
05ec744
fix(key-derivation): deriving xpubs
storopoli Dec 9, 2024
f5815f3
fix: tests
storopoli Dec 9, 2024
874d925
doc(datatool): add a warning and description.
storopoli Dec 10, 2024
bb03d6c
fix: proper zeroizing of `as_mut`
storopoli Dec 10, 2024
792977b
chore(deps): remove `derive` from zeroize
storopoli Dec 10, 2024
d1e4cd7
chore: move constants to primitives
storopoli Dec 10, 2024
913d971
chore: fix CODEOWNERS diff
storopoli Dec 10, 2024
be70fab
OH GOD DON’T AUTOFORMAT!
storopoli Dec 10, 2024
8e4c608
chore(deps): add back `derive` for `zeroize`
storopoli Dec 11, 2024
b95e3e9
fix: rename genseed to genxpriv
storopoli Dec 11, 2024
4be13ae
chore: fix formatting
storopoli Dec 11, 2024
675a19f
fix(datatool): clarifications on resolve Xpriv
storopoli Dec 11, 2024
c2a28db
fix(datatool): MIB Flash tool on Xprivs
storopoli Dec 11, 2024
0a955f2
fix(datatool): remove blacklist
storopoli Dec 11, 2024
e9e8f88
doc: clarifications on RNG for Xpriv generation
storopoli Dec 11, 2024
f912823
doc: clarify abbreviated amounts
storopoli Dec 11, 2024
fd857ec
doc: clarify high entropy on `OsRng`
storopoli Dec 11, 2024
fdd166d
chore: move ZeroizableXpriv to primitives
storopoli Dec 11, 2024
fea018c
primitives: add Zeroize for Buf32 and Buf20
storopoli Dec 11, 2024
b38dcf1
doc: fixes
storopoli Dec 11, 2024
57fe692
chore: clippy lints
storopoli Dec 11, 2024
8cfc404
strata-cli: zeroize Xpriv and String
storopoli Dec 11, 2024
8d4a1ce
strata-client: zeroize Buf32 and Xprivs
storopoli Dec 11, 2024
3f938eb
doc(primitives): fix examples
storopoli Dec 11, 2024
efc7522
doc(primitives): fix again
storopoli Dec 11, 2024
88401c0
chore: fix lints
storopoli Dec 11, 2024
0e362ba
primitives: Zeroize Buf64
storopoli Dec 11, 2024
d74e611
chore: rebased on main
storopoli Dec 11, 2024
2946fdf
bridge-client: don’t use a buffer
storopoli Dec 11, 2024
afaa638
bridge-client: zeroize again the buffer and the xpriv
storopoli Dec 12, 2024
965aaee
datatool: MIB Zeroize all possible secrets
storopoli Dec 12, 2024
61c2e8b
doc(bridge-client): clarify precedence order
storopoli Dec 12, 2024
41f3b94
doc(datatool): clarify precedence order
storopoli Dec 12, 2024
dd5f494
doc(primitives): fix Buf64 examples
storopoli Dec 12, 2024
900251c
fix(datatool): zeroize secret data even if stuff fails
storopoli Dec 12, 2024
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
22 changes: 13 additions & 9 deletions bin/datatool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,187 +46,191 @@
const DEFAULT_NETWORK: Network = Network::Signet;

/// Resolves a [`Network`] from a string.
pub(super) fn resolve_network(arg: Option<&str>) -> anyhow::Result<Network> {
match arg {
Some("signet") => Ok(Network::Signet),
Some("regtest") => Ok(Network::Regtest),
Some(n) => anyhow::bail!("unsupported network option: {n}"),
None => Ok(DEFAULT_NETWORK),

Check warning on line 54 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L49-L54

Added lines #L49 - L54 were not covered by tests
}
}

Check warning on line 56 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L56

Added line #L56 was not covered by tests

/// Executes a `gen*` subcommand.
pub(super) fn exec_subc(cmd: Subcommand, ctx: &mut CmdContext) -> anyhow::Result<()> {
match cmd {
Subcommand::Xpriv(subc) => exec_genxpriv(subc, ctx),
Subcommand::SeqPubkey(subc) => exec_genseqpubkey(subc, ctx),
Subcommand::SeqPrivkey(subc) => exec_genseqprivkey(subc, ctx),
Subcommand::OpXpub(subc) => exec_genopxpub(subc, ctx),
Subcommand::Params(subc) => exec_genparams(subc, ctx),

Check warning on line 65 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L59-L65

Added lines #L59 - L65 were not covered by tests
}
}

Check warning on line 67 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L67

Added line #L67 was not covered by tests

/// Executes the `genxpriv` subcommand.
///
/// Generates a new [`Xpriv`] that will [`Zeroize`](zeroize) on [`Drop`] and writes it to a file.
fn exec_genxpriv(cmd: SubcXpriv, ctx: &mut CmdContext) -> anyhow::Result<()> {
if cmd.path.exists() && !cmd.force {
anyhow::bail!("not overwriting file, add --force to overwrite");
}

let xpriv = gen_priv(&mut ctx.rng, ctx.bitcoin_network);
let mut buf = xpriv.encode();
let mut s = base58::encode_check(&buf);
fs::write(&cmd.path, s.as_bytes())?;
let result = fs::write(&cmd.path, s.as_bytes());
AaronFeickert marked this conversation as resolved.
Show resolved Hide resolved

buf.zeroize();
s.zeroize();

Ok(())
match result {
Ok(_) => Ok(()),
Err(_) => anyhow::bail!("failed to write to file {:?}", cmd.path),

Check warning on line 87 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L72-L87

Added lines #L72 - L87 were not covered by tests
}
}

Check warning on line 89 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L89

Added line #L89 was not covered by tests

/// Executes the `genseqpubkey` subcommand.
///
/// Generates the sequencer [`Xpub`] from the provided [`Xpriv`]
/// and prints it to stdout.
fn exec_genseqpubkey(cmd: SubcSeqPubkey, _ctx: &mut CmdContext) -> anyhow::Result<()> {
let Some(xpriv) = resolve_xpriv(&cmd.key_file, cmd.key_from_env, SEQKEY_ENVVAR)? else {
anyhow::bail!("privkey unset");

Check warning on line 97 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L95-L97

Added lines #L95 - L97 were not covered by tests
};

let seq_keys = SequencerKeys::new(&xpriv)?;
let seq_xpub = seq_keys.derived_xpub();
let mut raw_buf = seq_xpub.to_x_only_pub().serialize();
let mut s = base58::encode_check(&raw_buf);
let raw_buf = seq_xpub.to_x_only_pub().serialize();
let s = base58::encode_check(&raw_buf);

println!("{s}");

raw_buf.zeroize();
s.zeroize();

Ok(())
}

Check warning on line 108 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L100-L108

Added lines #L100 - L108 were not covered by tests

/// Executes the `genseqprivkey` subcommand.
///
/// Generates the sequencer [`Xpriv`] that will [`Zeroize`](zeroize) on [`Drop`] and prints it to
/// stdout.
fn exec_genseqprivkey(cmd: SubcSeqPrivkey, _ctx: &mut CmdContext) -> anyhow::Result<()> {
let Some(xpriv) = resolve_xpriv(&cmd.key_file, cmd.key_from_env, SEQKEY_ENVVAR)? else {
anyhow::bail!("privkey unset");

Check warning on line 116 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L114-L116

Added lines #L114 - L116 were not covered by tests
};

let seq_keys = SequencerKeys::new(&xpriv)?;
let seq_xpriv = seq_keys.derived_xpriv();
let raw_buf = seq_xpriv.to_priv().to_bytes();
let s = base58::encode_check(&raw_buf);
let mut raw_buf = seq_xpriv.to_priv().to_bytes();
let mut s = base58::encode_check(&raw_buf);

println!("{s}");

// Zeroize the buffers after printing.
raw_buf.zeroize();
s.zeroize();

Ok(())
}

Check warning on line 131 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L119-L131

Added lines #L119 - L131 were not covered by tests

/// Executes the `genopxpub` subcommand.
///
/// Generates the root xpub for an operator.
fn exec_genopxpub(cmd: SubcOpXpub, _ctx: &mut CmdContext) -> anyhow::Result<()> {
let Some(xpriv) = resolve_xpriv(&cmd.key_file, cmd.key_from_env, OPKEY_ENVVAR)? else {
anyhow::bail!("privkey unset");

Check warning on line 138 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L136-L138

Added lines #L136 - L138 were not covered by tests
};

let op_keys = OperatorKeys::new(&xpriv)?;
let op_base_xpub = op_keys.base_xpub();
let raw_buf = op_base_xpub.encode();
let s = base58::encode_check(&raw_buf);

println!("{s}");

Ok(())
}

Check warning on line 149 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L141-L149

Added lines #L141 - L149 were not covered by tests

/// Executes the `genparams` subcommand.
///
/// Generates the params for a Strata network.
/// Either writes to a file or prints to stdout depending on the provided options.
fn exec_genparams(cmd: SubcParams, ctx: &mut CmdContext) -> anyhow::Result<()> {

Check warning on line 155 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L155

Added line #L155 was not covered by tests
// Parse the sequencer key, trimming whitespace for convenience.
let seqkey = match cmd.seqkey.as_ref().map(|s| s.trim()) {
Some(seqkey) => {
let buf = match base58::decode_check(seqkey) {
Ok(v) => v,
Err(e) => {
anyhow::bail!("failed to parse sequencer key '{seqkey}': {e}");

Check warning on line 162 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L157-L162

Added lines #L157 - L162 were not covered by tests
}
};

let Ok(buf) = Buf32::try_from(buf.as_slice()) else {
anyhow::bail!("invalid sequencer key '{seqkey}' (must be 32 bytes)");

Check warning on line 167 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L166-L167

Added lines #L166 - L167 were not covered by tests
};

Some(buf)

Check warning on line 170 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L170

Added line #L170 was not covered by tests
}
None => None,

Check warning on line 172 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L172

Added line #L172 was not covered by tests
};

// Parse each of the operator keys.
let mut opkeys = Vec::new();

Check warning on line 176 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L176

Added line #L176 was not covered by tests

if let Some(opkeys_path) = cmd.opkeys {
let opkeys_str = fs::read_to_string(opkeys_path)?;

Check warning on line 179 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L178-L179

Added lines #L178 - L179 were not covered by tests

for l in opkeys_str.lines() {

Check warning on line 181 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L181

Added line #L181 was not covered by tests
// skip lines that are empty or look like comments
if l.trim().is_empty() || l.starts_with("#") {
continue;
}

opkeys.push(parse_xpub(l)?);

Check warning on line 187 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L183-L187

Added lines #L183 - L187 were not covered by tests
}
}

Check warning on line 189 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L189

Added line #L189 was not covered by tests

for k in cmd.opkey {
opkeys.push(parse_xpub(&k)?);

Check warning on line 192 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L191-L192

Added lines #L191 - L192 were not covered by tests
}

// Parse the deposit size str.
let deposit_sats = cmd
.deposit_sats
.map(|s| parse_abbr_amt(&s))
.transpose()?
.unwrap_or(1_000_000_000);

// Parse the checkpoint verification key.
let rollup_vk: Buf32 = GUEST_CHECKPOINT_VK_HASH_STR
.parse()
.expect("invalid checkpoint verifier key hash");

let config = ParamsConfig {
name: cmd.name.unwrap_or_else(|| "strata-testnet".to_string()),
bitcoin_network: ctx.bitcoin_network,
// TODO make these consts
block_time_sec: cmd.block_time.unwrap_or(15),
epoch_slots: cmd.epoch_slots.unwrap_or(64),
genesis_trigger: cmd.genesis_trigger_height.unwrap_or(100),
seqkey,
opkeys,
rollup_vk,
// TODO make a const
deposit_sats,
proof_timeout: cmd.proof_timeout,
};

let params = construct_params(config);
let params_buf = serde_json::to_string_pretty(&params)?;

Check warning on line 223 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L196-L223

Added lines #L196 - L223 were not covered by tests

if let Some(out_path) = &cmd.output {
fs::write(out_path, params_buf)?;
eprintln!("wrote to file {out_path:?}");
} else {
println!("{params_buf}");
}

Check warning on line 230 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L225-L230

Added lines #L225 - L230 were not covered by tests

Ok(())
}

Check warning on line 233 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L232-L233

Added lines #L232 - L233 were not covered by tests

/// Generates a new [`Xpriv`] that will [`Zeroize`](zeroize) on [`Drop`].
///
Expand All @@ -235,81 +239,81 @@
/// Takes a mutable reference to an RNG to allow flexibility in testing.
/// The actual generation requires a high-entropy source like [`OsRng`](rand::rngs::OsRng)
/// to securely generate extended private keys.
fn gen_priv<R: CryptoRng + RngCore>(rng: &mut R, net: Network) -> ZeroizableXpriv {
let mut seed = [0u8; 32];
AaronFeickert marked this conversation as resolved.
Show resolved Hide resolved
rng.fill_bytes(&mut seed);
let mut xpriv = Xpriv::new_master(net, &seed).expect("valid seed");
let zeroizable_xpriv: ZeroizableXpriv = xpriv.into();

// Zeroize the seed after generating the xpriv.
seed.zeroize();
// Zeroize the xpriv after generating it.
//
// NOTE: `zeroizable_xpriv` is zeroized on drop.
xpriv.private_key.non_secure_erase();

zeroizable_xpriv
}

Check warning on line 256 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L242-L256

Added lines #L242 - L256 were not covered by tests

/// Reads an [`Xpriv`] from file as a string and verifies the checksum.
///
/// # Notes
///
/// This [`Xpriv`] will [`Zeroize`](zeroize) on [`Drop`].
fn read_xpriv(path: &Path) -> anyhow::Result<ZeroizableXpriv> {
let mut raw_buf = fs::read(path)?;
let str_buf: &str = std::str::from_utf8(&raw_buf)?;
let mut buf = base58::decode_check(str_buf)?;

Check warning on line 266 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L263-L266

Added lines #L263 - L266 were not covered by tests

// Parse into a ZeroizableXpriv.
let xpriv = Xpriv::decode(&buf)?;
let zeroizable_xpriv: ZeroizableXpriv = xpriv.into();

// Zeroize the buffers after parsing.
//
// NOTE: `zeroizable_xpriv` is zeroized on drop;
// and `str_buf` is a reference to `raw_buf`.
raw_buf.zeroize();
buf.zeroize();

Ok(zeroizable_xpriv)
}

Check warning on line 280 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L269-L280

Added lines #L269 - L280 were not covered by tests

/// Parses an [`Xpriv`] from environment variable.
///
/// # Notes
///
/// This [`Xpriv`] will [`Zeroize`](zeroize) on [`Drop`].
fn parse_xpriv_from_env(env: &'static str) -> anyhow::Result<Option<ZeroizableXpriv>> {
let mut env_val = match std::env::var(env) {
Ok(v) => v,
Err(_) => anyhow::bail!("got --key-from-env but {env} not set or invalid"),

Check warning on line 290 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L287-L290

Added lines #L287 - L290 were not covered by tests
};

let mut buf = base58::decode_check(&env_val)?;

Check warning on line 293 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L293

Added line #L293 was not covered by tests

// Parse into a ZeroizableXpriv.
let mut xpriv = Xpriv::decode(&buf)?;
let zeroizable_xpriv: ZeroizableXpriv = xpriv.into();

// Zeroize the buffers after parsing.
//
// NOTE: `zeroizable_xpriv` is zeroized on drop.
env_val.zeroize();
buf.zeroize();
xpriv.private_key.non_secure_erase();

Ok(Some(zeroizable_xpriv))
}

Check warning on line 307 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L296-L307

Added lines #L296 - L307 were not covered by tests

/// Parses an [`Xpriv`] from file path.
///
/// # Notes
///
/// This [`Xpriv`] will [`Zeroize`](zeroize) on [`Drop`].
fn parse_xpriv_from_path(path: &Path) -> anyhow::Result<Option<ZeroizableXpriv>> {
Ok(Some(read_xpriv(path)?))
}

Check warning on line 316 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L314-L316

Added lines #L314 - L316 were not covered by tests

/// Resolves an [`Xpriv`] from the file path (if provided) or environment variable (if
/// `--key-from-env` set). Only one source should be specified.
Expand All @@ -322,18 +326,18 @@
/// # Notes
///
/// This [`Xpriv`] will [`Zeroize`](zeroize) on [`Drop`].
fn resolve_xpriv(
path: &Option<PathBuf>,
from_env: bool,
env: &'static str,
) -> anyhow::Result<Option<ZeroizableXpriv>> {
match (path, from_env) {
(Some(_), true) => anyhow::bail!("got key path and --key-from-env, pick a lane"),
(Some(path), false) => parse_xpriv_from_path(path),
(None, true) => parse_xpriv_from_env(env),
_ => Ok(None),

Check warning on line 338 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L329-L338

Added lines #L329 - L338 were not covered by tests
}
}

Check warning on line 340 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L340

Added line #L340 was not covered by tests

/// Inputs for constructing the network parameters.
pub struct ParamsConfig {
Expand Down Expand Up @@ -362,73 +366,73 @@

/// Constructs the parameters for a Strata network.
// TODO convert this to also initialize the sync params
fn construct_params(config: ParamsConfig) -> RollupParams {
let cr = config
.seqkey
.map(block_credential::CredRule::SchnorrKey)
.unwrap_or(block_credential::CredRule::Unchecked);

let opkeys = config
.opkeys
.into_iter()
.map(|xpk| {
let message_xpub = convert_base_xpub_to_message_xpub(&xpk);
let wallet_xpub = convert_base_xpub_to_wallet_xpub(&xpk);
let message_key_buf = message_xpub.to_x_only_pub().serialize().into();
let wallet_key_buf = wallet_xpub.to_x_only_pub().serialize().into();
OperatorPubkeys::new(message_key_buf, wallet_key_buf)
})
.collect::<Vec<_>>();

// TODO add in bitcoin network
RollupParams {
rollup_name: config.name,
block_time: config.block_time_sec * 1000,
cred_rule: cr,
// TODO do we want to remove this?
horizon_l1_height: config.genesis_trigger / 2,
genesis_l1_height: config.genesis_trigger,
operator_config: strata_primitives::params::OperatorConfig::Static(opkeys),
// TODO make configurable
evm_genesis_block_hash:
"0x37ad61cff1367467a98cf7c54c4ac99e989f1fbb1bc1e646235e90c065c565ba"
.parse()
.unwrap(),
evm_genesis_block_state_root:
"0x351714af72d74259f45cd7eab0b04527cd40e74836a45abcae50f92d919d988f"
.parse()
.unwrap(),
// TODO make configurable
l1_reorg_safe_depth: 4,
target_l2_batch_size: config.epoch_slots as u64,
address_length: 20,
deposit_amount: config.deposit_sats,
rollup_vk: RollupVerifyingKey::SP1VerifyingKey(config.rollup_vk),
// TODO make configurable
dispatch_assignment_dur: 64,
proof_publish_mode: config
.proof_timeout
.map(|t| ProofPublishMode::Timeout(t as u64))
.unwrap_or(ProofPublishMode::Strict),
// TODO make configurable
max_deposits_in_block: 16,
network: config.bitcoin_network,
}
}

Check warning on line 421 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L369-L421

Added lines #L369 - L421 were not covered by tests

/// Parses an [`Xpub`] from [`&str`], richly generating [`anyhow::Result`]s from
/// it.
fn parse_xpub(s: &str) -> anyhow::Result<Xpub> {
let Ok(buf) = base58::decode_check(s) else {
anyhow::bail!("failed to parse key: {s}");

Check warning on line 427 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L425-L427

Added lines #L425 - L427 were not covered by tests
};

let Ok(xpk) = Xpub::decode(&buf) else {
anyhow::bail!("failed to decode key: {s}");

Check warning on line 431 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L430-L431

Added lines #L430 - L431 were not covered by tests
};

Ok(xpk)
}

Check warning on line 435 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L434-L435

Added lines #L434 - L435 were not covered by tests

/// Parses an abbreviated amount string.
///
Expand All @@ -440,27 +444,27 @@
/// - `M` for million.
/// - `G` for billion.
/// - `T` for trillion.
fn parse_abbr_amt(s: &str) -> anyhow::Result<u64> {

Check warning on line 447 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L447

Added line #L447 was not covered by tests
// Thousand.
if let Some(v) = s.strip_suffix("K") {
return Ok(v.parse::<u64>()? * 1000);
}

Check warning on line 451 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L449-L451

Added lines #L449 - L451 were not covered by tests

// Million.
if let Some(v) = s.strip_suffix("M") {
return Ok(v.parse::<u64>()? * 1_000_000);
}

Check warning on line 456 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L454-L456

Added lines #L454 - L456 were not covered by tests

// Billion.
if let Some(v) = s.strip_suffix("G") {
return Ok(v.parse::<u64>()? * 1_000_000_000);
}

Check warning on line 461 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L459-L461

Added lines #L459 - L461 were not covered by tests

// Trillion, probably not necessary.
if let Some(v) = s.strip_suffix("T") {
return Ok(v.parse::<u64>()? * 1_000_000_000_000);
}

// Simple value.
Ok(s.parse::<u64>()?)
}

Check warning on line 470 in bin/datatool/src/util.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/util.rs#L464-L470

Added lines #L464 - L470 were not covered by tests
Loading