Author

Topic: primecoin- deciphering the block to get the origin (Read 2972 times)

newbie
Activity: 2
Merit: 0
Bump for interest. Were you able to solve the problem and successfully calculate the block header hash?
newbie
Activity: 1
Merit: 0
What am I doing wrong?
I've implemented the GO code but I'm unable to find a header hash that divides the origin.
This is the first time I have used GO, so perhaps you can spot the problem with my code?

Can someone please give me the header hash for block 383313?

My code looks like this:

Code:
package main
import
(
"fmt"
"crypto/sha256"
"encoding/base64"
"encoding/binary"
"math/big"
)

func main() {

//Block:383313
//Version:2
//PrevBlockHash:9c4fc11576808cf7c139f0aff73de45e924d15f872d8c3cb541c88e3e1b0d7aa
//MerkleRoot:b15059d72023db53072feb6f1d2aec768971e9462f060830fcce0fb9c7372d35
//Time:January 31, 2014, 08:21:42
//Bits:0a6657d6
//Nonce:33557011
//Origin:511894124314277474466966190582380266982082554847978849190464099863530478638974696162270693661640

origin, err0 := base64.StdEncoding.DecodeString("511894124314277474466966190582380266982082554847978849190464099863530478638974696162270693661640")
prevBlock, err1 := base64.StdEncoding.DecodeString("9c4fc11576808cf7c139f0aff73de45e924d15f872d8c3cb541c88e3e1b0d7aa")
merkleRoot, err2 := base64.StdEncoding.DecodeString("b15059d72023db53072feb6f1d2aec768971e9462f060830fcce0fb9c7372d35")

bh := BlockHeader{2, prevBlock, merkleRoot, 1391156502, 174479318, 33557011}

        fmt.Println("Header hash byte[]:")
fmt.Println(HeaderHash(bh))

        fmt.Println("Decode errors:")
fmt.Println(err0)
fmt.Println(err1)
fmt.Println(err2)

s := HeaderHash(bh)
//fmt.Println(s)
//fmt.Println(new(big.Int).SetBytes(s))

       //Reverse the hash
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}

        headerInt := new(big.Int).SetBytes(s)
        originInt := new(big.Int).SetBytes(origin)    

        fmt.Println("Header hash reversed:")
fmt.Println(s)
        fmt.Println("Header hash as Integer:")
fmt.Println(headerInt)

m:=big.NewInt(0)
t:=big.NewInt(0)
        m.Mod(originInt, headerInt)

       if m == t {
          fmt.Println(">>>Origin is divisable by header hash.<<<")
       } else {
          fmt.Println(">>>Origin is NOT divisable by header hash.<<<")}

}

type BlockHeader struct {

Version        uint32
HashPrevBlock  []byte
HashMerkleRoot []byte
Timestamp      uint32
Bits           uint32
Nonce          uint32
}


func HeaderHash(bh BlockHeader) []byte {

hash := sha256.New()
binary.Write(hash, binary.LittleEndian, bh.Version)
hash.Write(bh.HashPrevBlock)
hash.Write(bh.HashMerkleRoot)
binary.Write(hash, binary.LittleEndian, bh.Timestamp)
binary.Write(hash, binary.LittleEndian, bh.Bits)
binary.Write(hash, binary.LittleEndian, bh.Nonce)

data := sha256.Sum256(hash.Sum(nil))
return data[:]
}


Output:
Code:
Header hash byte[]:
[34 140 82 79 175 251 189 163 152 248 127 16 244 18 158 157 152 174 143 152 249 172 44 241 81 121 251 85 246 224 7 7]
Decode errors:



Header hash reversed:
[7 7 224 246 85 251 121 81 241 44 172 249 152 143 174 152 157 158 18 244 16 127 248 152 163 189 251 175 79 82 140 34]
Header hash as Integer:
3180110501919869770927571415789333083034902861520772082565710950573131598882
>>>Origin is NOT divisable by header hash.<<<

Program exited.
newbie
Activity: 2
Merit: 0
I sent a PM yesterday, but now I can reply for the public:

Here is the Go source to compute Header hash:

Code:
type BlockHeader struct {
   // Standard Bitcoin fields.
   Version        uint32
   HashPrevBlock  []byte
   HashMerkleRoot []byte
   Timestamp      uint32
   Bits           uint32
   Nonce          uint32
}

// HeaderHash calculates the block header hash.
// This is the fixed multiplier when searching for primes.
// NOTE: When converting to an Int the hash must be reversed.
func (bh *BlockHeader) HeaderHash() []byte {
   hash := sha256.New()
   binary.Write(hash, binary.LittleEndian, bh.Version)
   hash.Write(bh.HashPrevBlock)
   hash.Write(bh.HashMerkleRoot)
   binary.Write(hash, binary.LittleEndian, bh.Timestamp)
   binary.Write(hash, binary.LittleEndian, bh.Bits)
   binary.Write(hash, binary.LittleEndian, bh.Nonce)

   data := sha256.Sum256(hash.Sum(nil))
   return data[:]
}

Get the values of the fields from the block:
http://primecoin.21stcenturymoneytalk.org/index.php?block_hash=963d17ba4dc753138078a2f56afb3af9674e2546822badff26837db9a0152106

To get an integer from the hash you need to do:

Code:
// hashToBig converts a hash number to an integer
func hashToBig(hash []byte) *big.Int {
   tmp := make([]byte, len(hash))
   copy(tmp, hash)
   reverse(tmp)
   return new(big.Int).SetBytes(tmp)
}


Hope it helps, I can give more examples if still unclear when I have time.
newbie
Activity: 49
Merit: 0
u can access the www.primecoin.org to get useful information. i also love primecoin
legendary
Activity: 1176
Merit: 1280
May Bitcoin be touched by his Noodly Appendage
newbie
Activity: 1
Merit: 0
Can someone please respond to this question?Huh I tried the same thing, the prime origin is not divisible by the block hash (current or previous).

I have spend a whole day trying to figure this out! Apparently the "header hash" is not the same as the "block hash" from getblock. But it's not clear how to generate "header hash" from any primecoind outputs.
newbie
Activity: 7
Merit: 0
I am new to primecoins (and more generally crypto currencies) and have a few questions:


A) I am trying to understand how to get the block header hash from a given primecoin block.

For example, using primecoind, I can get block info:

./primecoind getblock b56ce048d64313380d2a947cbb99bda97825646d89c6fd4222d154fc7f145bdd
{
    "hash" : "b56ce048d64313380d2a947cbb99bda97825646d89c6fd4222d154fc7f145bdd",
    "confirmations" : 347122,
    "size" : 198,
    "height" : 10000,
    "version" : 2,
    "merkleroot" : "478aa31ca6011384884c60a5a3c864475640dfa546be26631f1cc58366b3d2ad",
    "tx" : [
        "478aa31ca6011384884c60a5a3c864475640dfa546be26631f1cc58366b3d2ad"
    ],
    "time" : 1373505507,
    "nonce" : 627,
    "bits" : "07a62bc2",
    "difficulty" : 7.64910519,
    "transition" : 7.97894430,
    "primechain" : "TWN07.ecf7e1",
    "primeorigin" : "3137429839290119515389894171750697301735643977360059424820833454775626872284966 6432245972690",
    "previousblockhash" : "835228e99c1617650f8d72a3167fc92a8a3cf4bebcf60860a645d5b5309f8f87",
    "nextblockhash" : "54d6ec1f98ba10f897f7d8ea0991a042438f38b066702fc53fa05b52f93c3525"
}

My understanding (?) is that the primeorigin should be divisible by the `block header hash' of the previous block.
But how do I determine the block header hash? I don't think it is the " "previousblockhash" which, in this example, is "835228e99c1617650f8d72a3167fc92a8a3cf4bebcf60860a645d5b5309f8f87" because when I convert this hex string to decimal I don't get a number that divides the given primeorigin.

B) I am also after a more detailed description of the primecoin specs. Sunny King's paper is very broad and not at the level that describes the particulars of implementation. For example, for the Cunningham prime chains, would the primecoin network accept any prime chains where the origin is *any* multiple of the block header hash (so long as the other requirements such as difficulty, size of primes etc are satisfied)? I noticed that primorials are built into the multiple in primecoind's search for prime chains, but I am guessing that it is not an actual requirement.

C) Also, I am trying to reverse engineer how primecoind searches for Cunningham chains. Can anyone point me to documentation or a description of the actual implementation.

D) Finally, what precisely do primespersec and chainsperday refer to here:
./primecoind getmininginfo
{
    "blocks" : 357131,
    "chainspermin" : 5,
    "chainsperday" : 0.02283714,
    "currentblocksize" : 4614,
    "currentblocktx" : 5,
    "difficulty" : 10.38302714,
    "errors" : "",
    "generate" : true,
    "genproclimit" : -1,
    "primespersec" : 854,
    "pooledtx" : 5,
    "sieveextensions" : 9,
    "sievepercentage" : 10,
    "sievesize" : 1000000,
    "testnet" : false
}

Thanks in advance for your help.
   
Jump to: