Skip to content

Commit

Permalink
feat: future proof the from & to address protocols
Browse files Browse the repository at this point in the history
This lets us add new address protocols to go-address without implicitly
accepting them in messages on the network.
  • Loading branch information
Stebalien committed Oct 19, 2022
1 parent a955a63 commit 4273f4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chain/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,18 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
return xerrors.New("invalid 'To' address")
}

if m.To.Protocol() > address.BLS {
return xerrors.New("'To' address protocol unsupported for network version")
}

if m.From == address.Undef {
return xerrors.New("'From' address cannot be empty")
}

if m.From.Protocol() > address.BLS {
return xerrors.New("'From' address protocol unsupported for network version")
}

if m.Value.Int == nil {
return xerrors.New("'Value' cannot be nil")
}
Expand Down
17 changes: 17 additions & 0 deletions chain/vm/syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,23 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime7.Conse
return nil, xerrors.Errorf("cannot decode first block header: %w", decodeErr)
}

// A _valid_ block must use an ID address, but that's not what we're checking here. We're
// just making sure that adding additional address protocols won't lead to consensus issues.
//
// When we add a new consensus protocol, we'll have to have a network-version switch here to
// support that protocol _after_ the upgrade.
if blockA.Miner.Protocol() > address.BLS {
return nil, xerrors.Errorf("address protocol unsupported in current network version: %d", blockA.Miner.Protocol())
}

if decodeErr := blockB.UnmarshalCBOR(bytes.NewReader(b)); decodeErr != nil {
return nil, xerrors.Errorf("cannot decode second block header: %f", decodeErr)
}

if blockB.Miner.Protocol() > address.BLS {
return nil, xerrors.Errorf("address protocol unsupported in current network version: %d", blockB.Miner.Protocol())
}

// workaround chain halt
if build.IsNearUpgrade(blockA.Height, build.UpgradeOrangeHeight) {
return nil, xerrors.Errorf("consensus reporting disabled around Upgrade Orange")
Expand Down Expand Up @@ -170,6 +183,10 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime7.Conse
return nil, xerrors.Errorf("cannot decode extra: %w", decodeErr)
}

if blockC.Miner.Protocol() > address.BLS {
return nil, xerrors.Errorf("address protocol unsupported in current network version: %d", blockC.Miner.Protocol())
}

if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockC.Height &&
types.CidArrsContains(blockB.Parents, blockC.Cid()) && !types.CidArrsContains(blockB.Parents, blockA.Cid()) {
consensusFault = &runtime7.ConsensusFault{
Expand Down

0 comments on commit 4273f4d

Please sign in to comment.