Skip to content

Commit

Permalink
feat: verify eth filter's block index is in hex
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed May 30, 2023
1 parent 2f54f77 commit 9d0cabc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/submodule/eth/eth_event_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -236,6 +237,9 @@ func (e *ethEventAPI) installEthFilterSpec(ctx context.Context, filterSpec *type
} else if *filterSpec.FromBlock == "pending" {
return nil, api.ErrNotSupported
} else {
if !strings.HasPrefix(*filterSpec.FromBlock, "0x") {
return nil, fmt.Errorf("FromBlock is not a hex")
}
epoch, err := types.EthUint64FromHex(*filterSpec.FromBlock)
if err != nil {
return nil, fmt.Errorf("invalid epoch")
Expand All @@ -251,6 +255,9 @@ func (e *ethEventAPI) installEthFilterSpec(ctx context.Context, filterSpec *type
} else if *filterSpec.ToBlock == "pending" {
return nil, api.ErrNotSupported
} else {
if !strings.HasPrefix(*filterSpec.ToBlock, "0x") {
return nil, fmt.Errorf("ToBlock is not a hex")
}
epoch, err := types.EthUint64FromHex(*filterSpec.ToBlock)
if err != nil {
return nil, fmt.Errorf("invalid epoch")
Expand Down
4 changes: 2 additions & 2 deletions venus-shared/actors/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,12 @@ func (h EthSubscriptionID) String() string {
}

type EthFilterSpec struct {
// Interpreted as an epoch or one of "latest" for last mined block, "earliest" for first,
// Interpreted as an epoch (in hex) or one of "latest" for last mined block, "earliest" for first,
// "pending" for not yet committed messages.
// Optional, default: "latest".
FromBlock *string `json:"fromBlock,omitempty"`

// Interpreted as an epoch or one of "latest" for last mined block, "earliest" for first,
// Interpreted as an epoch (in hex) or one of "latest" for last mined block, "earliest" for first,
// "pending" for not yet committed messages.
// Optional, default: "latest".
ToBlock *string `json:"toBlock,omitempty"`
Expand Down

0 comments on commit 9d0cabc

Please sign in to comment.