Skip to content

Commit b5d8d58

Browse files
authored
chore!: PDP service contract whitelist (#545)
Using current Alpha release FilecoinWarmStorageService contract address on calibnet Co-authored-by: zenground0 <[email protected]>
1 parent b73be8c commit b5d8d58

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pdp/contract/addresses.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import (
1212
)
1313

1414
type PDPContracts struct {
15-
PDPVerifier common.Address
15+
PDPVerifier common.Address
16+
AllowedPublicRecordKeepers []common.Address
1617
}
1718

1819
func ContractAddresses() PDPContracts {
1920
switch build.BuildType {
2021
case build.BuildCalibnet:
2122
return PDPContracts{
2223
PDPVerifier: common.HexToAddress("0x445238Eca6c6aB8Dff1Aa6087d9c05734D22f137"),
24+
AllowedPublicRecordKeepers: []common.Address{
25+
common.HexToAddress("0x80617b65FD2EEa1D7fDe2B4F85977670690ed348"), // FilecoinWarmStorageService
26+
},
2327
}
2428
case build.BuildMainnet:
2529
// Compatible contract not yet deployed
@@ -34,3 +38,20 @@ const NumChallenges = 5
3438
func SybilFee() *big.Int {
3539
return must.One(types.ParseFIL("0.1")).Int
3640
}
41+
42+
// IsPublicService checks if a service label indicates a public service
43+
func IsPublicService(serviceLabel string) bool {
44+
return serviceLabel == "public"
45+
}
46+
47+
// IsRecordKeeperAllowed checks if a recordkeeper address is in the whitelist
48+
// Returns true if the address is allowed, or if there's no whitelist for the network
49+
func IsRecordKeeperAllowed(recordKeeper common.Address) bool {
50+
// Check if the recordkeeper is in the whitelist
51+
for _, allowed := range ContractAddresses().AllowedPublicRecordKeepers {
52+
if recordKeeper == allowed {
53+
return true
54+
}
55+
}
56+
return false
57+
}

pdp/handlers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
170170
return
171171
}
172172

173+
// Check if the recordkeeper is in the whitelist for public services
174+
if contract.IsPublicService(serviceLabel) && !contract.IsRecordKeeperAllowed(recordKeeperAddr) {
175+
http.Error(w, "recordKeeper address not allowed for public service", http.StatusForbidden)
176+
return
177+
}
178+
173179
// Decode extraData if provided
174180
extraDataBytes := []byte{}
175181
if reqBody.ExtraData != nil {

0 commit comments

Comments
 (0)