Bitcoin Forum
May 04, 2024, 02:01:02 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: primecoin- deciphering the block to get the origin  (Read 2959 times)
zeta_r_123 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
January 13, 2014, 05:19:00 AM
 #1

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.
   
1714831262
Hero Member
*
Offline Offline

Posts: 1714831262

View Profile Personal Message (Offline)

Ignore
1714831262
Reply with quote  #2

1714831262
Report to moderator
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
primefan
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
January 13, 2014, 07:45:44 AM
 #2

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.
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1233


May Bitcoin be touched by his Noodly Appendage


View Profile
January 13, 2014, 07:48:47 AM
 #3

http://www.peercointalk.org

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
chinacoinbase
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile
January 13, 2014, 07:51:06 AM
 #4

u can access the www.primecoin.org to get useful information. i also love primecoin
brtzsnr
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
January 14, 2014, 10:39:36 AM
Last edit: January 14, 2014, 01:00:10 PM by brtzsnr
 #5

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.
dredger
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
February 05, 2014, 12:32:01 PM
 #6

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:
<nil>
<nil>
<nil>
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.
primecole
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 18, 2014, 10:26:42 AM
 #7

Bump for interest. Were you able to solve the problem and successfully calculate the block header hash?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!