<p>It depends on what your scripts are. If you are for example talking about a single-sig wrapped segwit address, the redeemscript can be recalculated from the corresponding public key. The wallet would derive some number of keys from the backup, then derive the corresponding redeemscripts and addresses. As the wallet is scanning the blockchain, whenever it gets a hit for any of the addresses, it will backfill the wallet with more "unused addresses" beyond the used address. The count of the unused addresses to scan for is defined by something usually called the "gap limit".</p>

<p>To regenerate redeemscripts of multisig addresses, the backup needs to include the full set and order of the involved public keys! Even if you have a sufficient quorum of the keys to spend, you cannot craft a valid transaction without the remaining keys due to the missing redeemscript. Most wallets today are set up using hierarchical deterministic key derivation, so again, the wallet would be able to regenerate as many addresses as needed from the original tuple of extended pubkeys. Of course that also requires the backup to store which derivation path was used.</p>

<p>If you are talking about arbitrary scripts, the backup better have the full redeemscript, otherwise you'll likely be out of luck.</p>

CC BY-SA 4.0
2020-06-06T02:26:15.923Z
2020-06-07T04:05:44.960Z
2020-06-07T04:05:44.960Z
Murch
<p>i'm trying to understand how wallets remember a redeem script for p2sh/p2wsh for spending, after recovering from their seed, because the utxo set only has the hash in it, right? there are a nearly infinite number of script possibilities, aren't there? what do i miss?</p>

<wallet><script><p2sh><p2wsh>
how to find p2sh/p2wsh in utxo set after wallet recovery
talentpierre
# how to find p2sh/p2wsh in utxo set after wallet recovery

(Asked by: username_0 on 2020-06-05)

i'm trying to understand how wallets remember a redeem script for p2sh/p2wsh for spending, after recovering from their seed, because the utxo set only has the hash in it, right? there are a nearly infinite number of script possibilities, aren't there? what do i miss?

**Tags:** wallet, script, p2sh, p2wsh


---

## 1 answers

### Answer by username_1 on 2020-06-06. Score: 0 | Accepted answer

It depends on what your scripts are. If you are for example talking about a single-sig wrapped segwit address, the redeemscript can be recalculated from the corresponding public key. The wallet would derive some number of keys from the backup, then derive the corresponding redeemscripts and addresses. As the wallet is scanning the blockchain, whenever it gets a hit for any of the addresses, it will backfill the wallet with more "unused addresses" beyond the used address. The count of the unused addresses to scan for is defined by something usually called the "gap limit".

To regenerate redeemscripts of multisig addresses, the backup needs to include the full set and order of the involved public keys! Even if you have a sufficient quorum of the keys to spend, you cannot craft a valid transaction without the remaining keys due to the missing redeemscript. Most wallets today are set up using hierarchical deterministic key derivation, so again, the wallet would be able to regenerate as many addresses as needed from the original tuple of extended pubkeys. Of course that also requires the backup to store which derivation path was used.

If you are talking about arbitrary scripts, the backup better have the full redeemscript, otherwise you'll likely be out of luck.


---

