Skip to content

Commit

Permalink
feat: future proof against new 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 Nov 8, 2022
1 parent f6d9a12 commit c6f2710
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 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 !abi.AddressValidForNetworkVersion(m.To, version) {
return xerrors.New("'To' address protocol unsupported for network version")
}

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

if !abi.AddressValidForNetworkVersion(m.From, version) {
return xerrors.New("'From' address protocol unsupported for network version")
}

if m.Value.Int == nil {
return xerrors.New("'Value' cannot be nil")
}
Expand Down
14 changes: 14 additions & 0 deletions chain/vm/syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,20 @@ 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.
if !abi.AddressValidForNetworkVersion(blockA.Miner, ss.networkVersion) {
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 !abi.AddressValidForNetworkVersion(blockB.Miner, ss.networkVersion) {
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 +180,10 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime7.Conse
return nil, xerrors.Errorf("cannot decode extra: %w", decodeErr)
}

if !abi.AddressValidForNetworkVersion(blockC.Miner, ss.networkVersion) {
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.9.8
github.com/filecoin-project/go-state-types v0.9.9
github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.9.8 h1:xkdITiR7h691z1tWOhNCJxHI+cq+Mq7ATkpHQ7f1gu8=
github.com/filecoin-project/go-state-types v0.9.8/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-state-types v0.9.9 h1:gd7Mo6f9jHHpLahttBE88YeQA77i4GK6W5kFdQDnuME=
github.com/filecoin-project/go-state-types v0.9.9/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
Expand Down

0 comments on commit c6f2710

Please sign in to comment.