Skip to content

Commit

Permalink
Merge pull request #5557 from filecoin-project/feat/future-proof-addr…
Browse files Browse the repository at this point in the history
…ess-protocol

feat: future proof the from & to address protocols
  • Loading branch information
diwufeiwen authored Jan 3, 2023
2 parents 03b404b + b55f0da commit 71c7b99
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/filecoin-project/go-fil-markets v1.24.0-v17
github.com/filecoin-project/go-jsonrpc v0.1.5
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/pubsub v1.0.0
github.com/filecoin-project/specs-actors v0.9.15
github.com/filecoin-project/specs-actors/v2 v2.3.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4
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
14 changes: 14 additions & 0 deletions pkg/consensusfault/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,21 @@ func (s *ConsensusFaultChecker) VerifyConsensusFault(ctx context.Context, h1, h2
if innerErr != nil {
return nil, errors.Wrapf(innerErr, "failed to decode h1")
}
networkVersion := s.fork.GetNetworkVersion(ctx, curEpoch)

// 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(b1.Miner, networkVersion) {
return nil, fmt.Errorf("address protocol unsupported in current network version: %d", b1.Miner.Protocol())
}

innerErr = b2.UnmarshalCBOR(bytes.NewReader(h2))
if innerErr != nil {
return nil, errors.Wrapf(innerErr, "failed to decode h2")
}
if !abi.AddressValidForNetworkVersion(b2.Miner, networkVersion) {
return nil, fmt.Errorf("address protocol unsupported in current network version: %d", b2.Miner.Protocol())
}

// workaround chain halt
forkUpgrade := s.fork.GetForkUpgrade()
Expand Down Expand Up @@ -115,6 +126,9 @@ func (s *ConsensusFaultChecker) VerifyConsensusFault(ctx context.Context, h1, h2
if innerErr != nil {
return nil, errors.Wrapf(innerErr, "failed to decode extra")
}
if !abi.AddressValidForNetworkVersion(b3.Miner, networkVersion) {
return nil, fmt.Errorf("address protocol unsupported in current network version: %d", b3.Miner.Protocol())
}
b3PKey := types.NewTipSetKey(b3.Parents...)
if b1.Height == b3.Height && b3PKey.Equals(b1PKey) && !b2PKey.Has(b1.Cid()) && b2PKey.Has(b3.Cid()) {
fault = &runtime7.ConsensusFault{
Expand Down
2 changes: 1 addition & 1 deletion venus-devtool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/filecoin-project/go-data-transfer v1.15.2
github.com/filecoin-project/go-fil-markets v1.24.1-rc1
github.com/filecoin-project/go-jsonrpc v0.1.8
github.com/filecoin-project/go-state-types v0.9.8
github.com/filecoin-project/go-state-types v0.9.9
github.com/filecoin-project/lotus v1.18.0
github.com/filecoin-project/venus v0.0.0-00010101000000-000000000000
github.com/ipfs/go-block-format v0.0.3
Expand Down
4 changes: 2 additions & 2 deletions venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4
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 v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q=
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
Expand Down
8 changes: 8 additions & 0 deletions venus-shared/internal/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
return fmt.Errorf("'To' address cannot be empty")
}

if !abi.AddressValidForNetworkVersion(m.To, version) {
return fmt.Errorf("'To' address protocol unsupported for network version")
}

if m.To == ZeroAddress && version >= network.Version7 {
return fmt.Errorf("invalid 'To' address")
}
Expand All @@ -156,6 +160,10 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
return fmt.Errorf("'From' address cannot be empty")
}

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

if m.Value.Int == nil {
return fmt.Errorf("'Value' cannot be nil")
}
Expand Down

0 comments on commit 71c7b99

Please sign in to comment.