Skip to content

Commit

Permalink
Merge pull request #31 from renproject/imp/use-sha256
Browse files Browse the repository at this point in the history
Use sha256 instead of sha3-256
  • Loading branch information
jazg committed Oct 1, 2019
2 parents fe1d619 + 171b151 commit ad22662
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions block/block.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package block

import (
"crypto/sha256"
"encoding/base64"
"fmt"
"time"

"github.com/renproject/id"
"golang.org/x/crypto/sha3"
)

// Kind defines the different kinds of Block that exist.
Expand Down Expand Up @@ -190,7 +190,7 @@ func New(header Header, data Data, prevState State) Block {
}
}

// Hash returns the 256-bit SHA3 Hash of the Header and Data.
// Hash returns the 256-bit SHA2 Hash of the Header and Data.
func (block Block) Hash() id.Hash {
return block.hash
}
Expand Down Expand Up @@ -243,5 +243,5 @@ var (

// ComputeHash of a block basing on its header, data and previous state.
func ComputeHash(header Header, data Data, prevState State) id.Hash {
return sha3.Sum256([]byte(fmt.Sprintf("BlockHash(Header=%v,Data=%v,PreviousState=%v)", header, data, prevState)))
return sha256.Sum256([]byte(fmt.Sprintf("BlockHash(Header=%v,Data=%v,PreviousState=%v)", header, data, prevState)))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ethereum/go-ethereum v1.9.5
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/renproject/id v0.1.0
github.com/renproject/id v0.1.1
github.com/renproject/phi v0.1.0
github.com/sirupsen/logrus v1.4.2
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ethereum/go-ethereum v1.9.5 h1:4oxsF+/3N/sTgda9XTVG4r+wMVLsveziSMcK83hPbsk=
github.com/ethereum/go-ethereum v1.9.5/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY=
Expand All @@ -14,14 +15,18 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/renproject/id v0.1.0 h1:lq8yzXPechAJlqcFUAukPGL8s9E1HaZM95YgbypoFwQ=
github.com/renproject/id v0.1.0/go.mod h1:i4OJzgjl4XLcU7nfU9UshX7PaBVpnTk3gEVj8dKa6f8=
github.com/renproject/id v0.1.1 h1:KaV31Xp7SSlyUs5O0vHIw9rhhzrJ0lTOkQXVgbgyPEU=
github.com/renproject/id v0.1.1/go.mod h1:i4OJzgjl4XLcU7nfU9UshX7PaBVpnTk3gEVj8dKa6f8=
github.com/renproject/phi v0.1.0 h1:ZOn7QeDribk/uV46OhQWcTLxyuLg7P+xR1Hfl5cOQuI=
github.com/renproject/phi v0.1.0/go.mod h1:Hrxx2ONVpfByficRjyRd1trecalYr0lo7Z0akx8UXqg=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
8 changes: 4 additions & 4 deletions process/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package process

import (
"crypto/ecdsa"
"crypto/sha256"
"encoding"
"encoding/json"
"fmt"

"github.com/ethereum/go-ethereum/crypto"
"github.com/renproject/hyperdrive/block"
"github.com/renproject/id"
"golang.org/x/crypto/sha3"
)

type MessageType uint64
Expand Down Expand Up @@ -115,7 +115,7 @@ func (propose *Propose) Signatory() id.Signatory {
}

func (propose *Propose) SigHash() id.Hash {
return sha3.Sum256([]byte(propose.String()))
return sha256.Sum256([]byte(propose.String()))
}

func (propose *Propose) Sig() id.Signature {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (prevote *Prevote) Signatory() id.Signatory {
}

func (prevote *Prevote) SigHash() id.Hash {
return sha3.Sum256([]byte(prevote.String()))
return sha256.Sum256([]byte(prevote.String()))
}

func (prevote *Prevote) Sig() id.Signature {
Expand Down Expand Up @@ -223,7 +223,7 @@ func (precommit *Precommit) Signatory() id.Signatory {
}

func (precommit *Precommit) SigHash() id.Hash {
return sha3.Sum256([]byte(precommit.String()))
return sha256.Sum256([]byte(precommit.String()))
}

func (precommit *Precommit) Sig() id.Signature {
Expand Down
4 changes: 2 additions & 2 deletions testutil/replica/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"fmt"
mrand "math/rand"
"sync"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/renproject/hyperdrive/testutil"
"github.com/renproject/id"
"github.com/renproject/phi"
"golang.org/x/crypto/sha3"
)

func Contain(list []int, target int) bool {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (m MockObserver) DidCommitBlock(height block.Height, shard replica.Shard) {
if !ok {
panic("DidCommitBlock should be called only when the block has been added to storage")
}
digest := sha3.Sum256(b.Data())
digest := sha256.Sum256(b.Data())
blockchain.InsertBlockStatAtHeight(height, digest[:])

// Insert executed state of the previous height
Expand Down

0 comments on commit ad22662

Please sign in to comment.