Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pdp/contract/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import (
)

type PDPContracts struct {
PDPVerifier common.Address
PDPVerifier common.Address
AllowedPublicRecordKeepers []common.Address
}

func ContractAddresses() PDPContracts {
switch build.BuildType {
case build.BuildCalibnet:
return PDPContracts{
PDPVerifier: common.HexToAddress("0x445238Eca6c6aB8Dff1Aa6087d9c05734D22f137"),
AllowedPublicRecordKeepers: []common.Address{
common.HexToAddress("0x80617b65FD2EEa1D7fDe2B4F85977670690ed348"), // FilecoinWarmStorageService
},
}
case build.BuildMainnet:
// Compatible contract not yet deployed
Expand All @@ -34,3 +38,20 @@ const NumChallenges = 5
func SybilFee() *big.Int {
return must.One(types.ParseFIL("0.1")).Int
}

// IsPublicService checks if a service label indicates a public service
func IsPublicService(serviceLabel string) bool {
return serviceLabel == "public"
}

// IsRecordKeeperAllowed checks if a recordkeeper address is in the whitelist
// Returns true if the address is allowed, or if there's no whitelist for the network
func IsRecordKeeperAllowed(recordKeeper common.Address) bool {
// Check if the recordkeeper is in the whitelist
for _, allowed := range ContractAddresses().AllowedPublicRecordKeepers {
if recordKeeper == allowed {
return true
}
}
return false
}
6 changes: 6 additions & 0 deletions pdp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
return
}

// Check if the recordkeeper is in the whitelist for public services
if contract.IsPublicService(serviceLabel) && !contract.IsRecordKeeperAllowed(recordKeeperAddr) {
http.Error(w, "recordKeeper address not allowed for public service", http.StatusForbidden)
return
}

// Decode extraData if provided
extraDataBytes := []byte{}
if reqBody.ExtraData != nil {
Expand Down