Skip to content

Commit

Permalink
Normalize allowlist lookups to use lowercase non-checksummed authenti…
Browse files Browse the repository at this point in the history
…cated address (#838)
  • Loading branch information
pschork authored Oct 28, 2024
1 parent 9bd44f4 commit bee55ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 5 additions & 2 deletions disperser/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"strconv"
"strings"
"time"

"github.com/Layr-Labs/eigenda/common"
Expand Down Expand Up @@ -164,9 +165,11 @@ func ReadAllowlistFromFile(f string) (Allowlist, error) {
}

for _, entry := range allowlistEntries {
rateInfoByQuorum, ok := allowlist[entry.Account]
// normalize to lowercase (non-checksummed) address or IP address
account := strings.ToLower(entry.Account)
rateInfoByQuorum, ok := allowlist[account]
if !ok {
allowlist[entry.Account] = map[core.QuorumID]PerUserRateInfo{
allowlist[account] = map[core.QuorumID]PerUserRateInfo{
core.QuorumID(entry.QuorumID): {
Name: entry.Name,
Throughput: common.RateParam(entry.ByteRate),
Expand Down
5 changes: 5 additions & 0 deletions disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (s *DispersalServer) getAccountRate(origin, authenticatedAddress string, qu

// Check if the address is in the allowlist
if len(authenticatedAddress) > 0 {
// normalize to lowercase (non-checksummed) address or IP address
authenticatedAddress = strings.ToLower(authenticatedAddress)

quorumRates, ok := s.rateConfig.Allowlist[authenticatedAddress]
if ok {
rateInfo, ok := quorumRates[quorumID]
Expand All @@ -339,6 +342,8 @@ func (s *DispersalServer) getAccountRate(origin, authenticatedAddress string, qu
rates.Name = rateInfo.Name
return rates, key, nil
}
} else {
s.logger.Warn("authenticated address not found in allowlist", "authenticatedAddress", authenticatedAddress)
}
}

Expand Down
32 changes: 30 additions & 2 deletions disperser/apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ func TestParseAllowlist(t *testing.T) {
"quorumID": 1,
"blobRate": 0.1,
"byteRate": 4092
},
{
"name": "bar",
"account": "0xcb14cFAaC122E52024232583e7354589AedE74Ff",
"quorumID": 1,
"blobRate": 0.1,
"byteRate": 4092
}
]
`)
Expand All @@ -466,7 +473,6 @@ func TestParseAllowlist(t *testing.T) {
assert.Contains(t, rateConfig.Allowlist, "5.5.5.5")
assert.Contains(t, rateConfig.Allowlist["0.1.2.3"], uint8(0))
assert.Contains(t, rateConfig.Allowlist["0.1.2.3"], uint8(1))
assert.Contains(t, rateConfig.Allowlist["5.5.5.5"], uint8(1))
assert.NotContains(t, rateConfig.Allowlist["5.5.5.5"], uint8(0))
assert.Equal(t, rateConfig.Allowlist["0.1.2.3"][0].Name, "eigenlabs")
assert.Equal(t, rateConfig.Allowlist["0.1.2.3"][0].BlobRate, uint32(0.01*1e6))
Expand All @@ -477,6 +483,13 @@ func TestParseAllowlist(t *testing.T) {
assert.Equal(t, rateConfig.Allowlist["5.5.5.5"][1].Name, "foo")
assert.Equal(t, rateConfig.Allowlist["5.5.5.5"][1].BlobRate, uint32(0.1*1e6))
assert.Equal(t, rateConfig.Allowlist["5.5.5.5"][1].Throughput, uint32(4092))

// verify checksummed address is normalized to lowercase
assert.Contains(t, rateConfig.Allowlist, "0xcb14cfaac122e52024232583e7354589aede74ff")
assert.Contains(t, rateConfig.Allowlist["0xcb14cfaac122e52024232583e7354589aede74ff"], uint8(1))
assert.Equal(t, rateConfig.Allowlist["0xcb14cfaac122e52024232583e7354589aede74ff"][1].Name, "bar")
assert.Equal(t, rateConfig.Allowlist["0xcb14cfaac122e52024232583e7354589aede74ff"][1].BlobRate, uint32(0.1*1e6))
assert.Equal(t, rateConfig.Allowlist["0xcb14cfaac122e52024232583e7354589aede74ff"][1].Throughput, uint32(4092))
}

func TestLoadAllowlistFromFile(t *testing.T) {
Expand Down Expand Up @@ -513,6 +526,7 @@ func TestLoadAllowlistFromFile(t *testing.T) {
assert.Contains(t, al["0.1.2.3"], uint8(1))
assert.Contains(t, al["5.5.5.5"], uint8(1))
assert.NotContains(t, al["5.5.5.5"], uint8(0))
assert.NotContains(t, al, "0xcb14cfaac122e52024232583e7354589aede74ff")
assert.Equal(t, al["0.1.2.3"][0].Name, "eigenlabs")
assert.Equal(t, al["0.1.2.3"][0].BlobRate, uint32(0.01*1e6))
assert.Equal(t, al["0.1.2.3"][0].Throughput, uint32(1024))
Expand All @@ -538,6 +552,13 @@ func TestLoadAllowlistFromFile(t *testing.T) {
"quorumID": 1,
"blobRate": 1,
"byteRate": 1234
},
{
"name": "bar",
"account": "0xcb14cFAaC122E52024232583e7354589AedE74Ff",
"quorumID": 1,
"blobRate": 0.1,
"byteRate": 4092
}
]
`)
Expand All @@ -556,6 +577,13 @@ func TestLoadAllowlistFromFile(t *testing.T) {
assert.Equal(t, al["7.7.7.7"][1].Name, "world")
assert.Equal(t, al["7.7.7.7"][1].BlobRate, uint32(1*1e6))
assert.Equal(t, al["7.7.7.7"][1].Throughput, uint32(1234))

// verify checksummed address is normalized to lowercase
assert.Contains(t, al, "0xcb14cfaac122e52024232583e7354589aede74ff")
assert.Contains(t, al["0xcb14cfaac122e52024232583e7354589aede74ff"], uint8(1))
assert.Equal(t, al["0xcb14cfaac122e52024232583e7354589aede74ff"][1].Name, "bar")
assert.Equal(t, al["0xcb14cfaac122e52024232583e7354589aede74ff"][1].BlobRate, uint32(0.1*1e6))
assert.Equal(t, al["0xcb14cfaac122e52024232583e7354589aede74ff"][1].Throughput, uint32(4092))
}

func overwriteFile(t *testing.T, f *os.File, content string) {
Expand Down Expand Up @@ -677,7 +705,7 @@ func newTestServer(transactor core.Writer) *apiserver.DispersalServer {
BlobRate: 5 * 1e6,
},
},
"0x1aa8226f6d354380dDE75eE6B634875c4203e522": map[uint8]apiserver.PerUserRateInfo{
"0x1aa8226f6d354380dde75ee6b634875c4203e522": map[uint8]apiserver.PerUserRateInfo{
0: {
Name: "eigenlabs",
Throughput: 100 * 1024,
Expand Down

0 comments on commit bee55ed

Please sign in to comment.