Skip to content

Commit aa0cb5c

Browse files
committed
Clean up full_stack_target InMemorySigner builder
The code was a bit too long to begin with, and rustfmt made a total mess of it, so instead we should be building with more intermediate variables.
1 parent 98fb236 commit aa0cb5c

File tree

1 file changed

+21
-77
lines changed

1 file changed

+21
-77
lines changed

fuzz/src/full_stack.rs

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -435,85 +435,29 @@ impl SignerProvider for KeyProvider {
435435
[ctr; 32]
436436
}
437437

438-
fn derive_channel_signer(&self, channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
438+
fn derive_channel_signer(&self, keys_id: [u8; 32]) -> Self::EcdsaSigner {
439439
let secp_ctx = Secp256k1::signing_only();
440-
let ctr = channel_keys_id[0];
440+
let ctr = keys_id[0];
441441
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
442-
TestChannelSigner::new_with_revoked(
443-
DynSigner::new(if inbound {
444-
InMemorySigner::new(
445-
&secp_ctx,
446-
SecretKey::from_slice(&[
447-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
448-
0, 0, 0, 0, 0, 1, ctr,
449-
])
450-
.unwrap(),
451-
SecretKey::from_slice(&[
452-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453-
0, 0, 0, 0, 0, 2, ctr,
454-
])
455-
.unwrap(),
456-
SecretKey::from_slice(&[
457-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
458-
0, 0, 0, 0, 0, 3, ctr,
459-
])
460-
.unwrap(),
461-
SecretKey::from_slice(&[
462-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
463-
0, 0, 0, 0, 0, 4, ctr,
464-
])
465-
.unwrap(),
466-
SecretKey::from_slice(&[
467-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
468-
0, 0, 0, 0, 0, 5, ctr,
469-
])
470-
.unwrap(),
471-
[
472-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
473-
0, 0, 0, 0, 0, 6, ctr,
474-
],
475-
channel_keys_id,
476-
channel_keys_id,
477-
)
478-
} else {
479-
InMemorySigner::new(
480-
&secp_ctx,
481-
SecretKey::from_slice(&[
482-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
483-
0, 0, 0, 0, 0, 7, ctr,
484-
])
485-
.unwrap(),
486-
SecretKey::from_slice(&[
487-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
488-
0, 0, 0, 0, 0, 8, ctr,
489-
])
490-
.unwrap(),
491-
SecretKey::from_slice(&[
492-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
493-
0, 0, 0, 0, 0, 9, ctr,
494-
])
495-
.unwrap(),
496-
SecretKey::from_slice(&[
497-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
498-
0, 0, 0, 0, 0, 10, ctr,
499-
])
500-
.unwrap(),
501-
SecretKey::from_slice(&[
502-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
503-
0, 0, 0, 0, 0, 11, ctr,
504-
])
505-
.unwrap(),
506-
[
507-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
508-
0, 0, 0, 0, 0, 12, ctr,
509-
],
510-
channel_keys_id,
511-
channel_keys_id,
512-
)
513-
}),
514-
state,
515-
false,
516-
)
442+
443+
let (a, b, c, d, e, f);
444+
let mut key = [0; 32];
445+
key[31] = ctr;
446+
key[30] = 1 + if inbound { 0 } else { 6 };
447+
a = SecretKey::from_slice(&key).unwrap();
448+
key[30] = 2 + if inbound { 0 } else { 6 };
449+
b = SecretKey::from_slice(&key).unwrap();
450+
key[30] = 3 + if inbound { 0 } else { 6 };
451+
c = SecretKey::from_slice(&key).unwrap();
452+
key[30] = 4 + if inbound { 0 } else { 6 };
453+
d = SecretKey::from_slice(&key).unwrap();
454+
key[30] = 5 + if inbound { 0 } else { 6 };
455+
e = SecretKey::from_slice(&key).unwrap();
456+
key[30] = 6 + if inbound { 0 } else { 6 };
457+
f = key;
458+
let signer = InMemorySigner::new(&secp_ctx, a, b, c, d, e, f, keys_id, keys_id);
459+
460+
TestChannelSigner::new_with_revoked(DynSigner::new(signer), state, false)
517461
}
518462

519463
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {

0 commit comments

Comments
 (0)