Skip to content

Commit

Permalink
Remove verification for createNewBlock
Browse files Browse the repository at this point in the history
The value returned must be assumed untrusted because the service
is lacking the context to verify it belongs to the chain.
Verifications must be done upstream.
  • Loading branch information
Gaylor Bosson committed Mar 20, 2019
1 parent d12b914 commit 8c8057a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
21 changes: 4 additions & 17 deletions byzcoin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import (
uuid "gopkg.in/satori/go.uuid.v1"
)

// for testing purpose until we have proper interfaces
var testCorruptSSBReply *skipchain.StoreSkipBlockReply

var pairingSuite = suites.MustFind("bn256.adapter").(*pairing.SuiteBn256)

// This is to boost the acceptable timestamp window when dealing with
Expand Down Expand Up @@ -890,24 +887,14 @@ func (s *Service) createNewBlock(scID skipchain.SkipBlockID, r *onet.Roster, tx
return nil, err
}

if testCorruptSSBReply != nil {
ssbReply = testCorruptSSBReply
}

if ssbReply.Latest == nil {
return nil, errors.New("got an empty reply")
}

// simple integrity check because the block will be used to cache
// the state changes
if !ssbReply.Latest.CalculateHash().Equal(ssbReply.Latest.Hash) {
return nil, errors.New("block in reply is corrupted")
}

// and check that we got the expected block
if ssbReply.Latest.Index != sb.Index {
return nil, errors.New("got a different block")
}
// we're not doing more verification because the block should not be used
// as is. It's up to the client to fetch the forward link of the previous
// block to insure the new one has been validated but at this moment we
// can't do it because it might not be propagated to this node yet
}
if err != nil {
return nil, err
Expand Down
18 changes: 0 additions & 18 deletions byzcoin/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,7 @@ func TestService_CreateGenesisBlock(t *testing.T) {
genesisMsg.BlockInterval = 100 * time.Millisecond
genesisMsg.MaxBlockSize = 1 * 1e6

// corrupted reply
testCorruptSSBReply = &skipchain.StoreSkipBlockReply{}
_, err = service.CreateGenesisBlock(genesisMsg)
require.Error(t, err)
require.Equal(t, "got an empty reply", err.Error())

testCorruptSSBReply.Latest = skipchain.NewSkipBlock()
_, err = service.CreateGenesisBlock(genesisMsg)
require.Error(t, err)
require.Equal(t, "block in reply is corrupted", err.Error())

testCorruptSSBReply.Latest.Index = 1
testCorruptSSBReply.Latest.Hash = testCorruptSSBReply.Latest.CalculateHash()
_, err = service.CreateGenesisBlock(genesisMsg)
require.Error(t, err)
require.Equal(t, "got a different block", err.Error())

// finally passing
testCorruptSSBReply = nil
resp, err = service.CreateGenesisBlock(genesisMsg)
require.Nil(t, err)
assert.Equal(t, CurrentVersion, resp.Version)
Expand Down

0 comments on commit 8c8057a

Please sign in to comment.