<p>Do this:</p>

<pre><code>echo -n $PREV_OUT | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256
</code></pre>

<h3>Explanation</h3>

<p>You want to do this:</p>

<blockquote>
  <p>prevout (raw bytes) -> sha256 -> sha256 -> convert to hex</p>
</blockquote>

<p>You're doing this:</p>

<blockquote>
  <p>prevout (raw bytes) -> convert to hex -> sha256 -> sha256 -> convert to hex</p>
</blockquote>

<p><code>xxd -r -p</code> reverses the hex conversion.</p>

CC BY-SA 3.0
2017-01-05T23:19:59.010Z
2017-01-05T23:19:59.010Z
Nick ODell
<p>How do I compute the double sha256 shown in example of <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki" rel="nofollow noreferrer">bip 143</a>?</p>

<p>The <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#native-p2wpkh" rel="nofollow noreferrer">example in Native P2WPKH</a></p>

<pre><code>  hashPrevouts:
     dSHA256(fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000)
     = 96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37
</code></pre>

<p>I tried</p>

<pre><code>  export PREV_OUT=fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000
  echo -n $PREV_OUT |openssl dgst -sha256 -binary |openssl dgst -sha256
</code></pre>

<p>This is what I am getting</p>

<pre><code>  cf4cff3b2196ae87636af6088736f0f9102106375f306c032804845a2d3b92d4
</code></pre>

<sha256><segregated-witness><bip>
How to compute double sha256 shown in examples of bip 143?
tsknakamura
# How to compute double sha256 shown in examples of bip 143?

(Asked by: username_0 on 2017-01-05)

How do I compute the double sha256 shown in example of [bip 143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki)?

The [example in Native P2WPKH](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#native-p2wpkh)

```
  hashPrevouts:
     dSHA256(fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000)
     = 96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37

```

I tried

```
  export PREV_OUT=fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000
  echo -n $PREV_OUT |openssl dgst -sha256 -binary |openssl dgst -sha256

```

This is what I am getting

```
  cf4cff3b2196ae87636af6088736f0f9102106375f306c032804845a2d3b92d4

```

**Tags:** sha256, segregated-witness, bip


---

## 1 answers

### Answer by username_1 on 2017-01-05. Score: 5 | Accepted answer

Do this:

```
echo -n $PREV_OUT | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256

```

### Explanation

You want to do this:

> prevout (raw bytes) -> sha256 -> sha256 -> convert to hex

You're doing this:

> prevout (raw bytes) -> convert to hex -> sha256 -> sha256 -> convert to hex

`xxd -r -p` reverses the hex conversion.


---

