diff --git a/block/block.go b/block/block.go index f5a0f064..db2451e0 100644 --- a/block/block.go +++ b/block/block.go @@ -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. @@ -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 } @@ -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))) } diff --git a/go.mod b/go.mod index ba9fbd7b..6af57b31 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index dfb78612..dd814782 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/process/message.go b/process/message.go index bc302cd0..a225684e 100644 --- a/process/message.go +++ b/process/message.go @@ -2,6 +2,7 @@ package process import ( "crypto/ecdsa" + "crypto/sha256" "encoding" "encoding/json" "fmt" @@ -9,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/renproject/hyperdrive/block" "github.com/renproject/id" - "golang.org/x/crypto/sha3" ) type MessageType uint64 @@ -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 { @@ -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 { @@ -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 { diff --git a/testutil/replica/replica.go b/testutil/replica/replica.go index 56815995..2866e9ba 100644 --- a/testutil/replica/replica.go +++ b/testutil/replica/replica.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/ecdsa" "crypto/rand" + "crypto/sha256" "fmt" mrand "math/rand" "sync" @@ -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 { @@ -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