-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relayers OFAC #1313
Merged
Merged
Relayers OFAC #1313
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
417e8d9
ofac
claravanstaden b14e018
ofac
claravanstaden df886a1
adds log
claravanstaden f3e5104
imports
claravanstaden d0f307c
space
claravanstaden 2ff9c5c
Merge branch 'beacon-state-download-log' into relayers-ofac
claravanstaden b522003
decode
claravanstaden 9db4e62
fix test
claravanstaden fc90b21
refactor
claravanstaden a89995a
tests work
claravanstaden e9894eb
ofac
claravanstaden a3c706b
ethereum side
claravanstaden 70040c7
decode message
claravanstaden e019378
parachain side
claravanstaden 50aba82
finish off relayers ofac
claravanstaden 06c517a
revert testing change
claravanstaden 1e9558e
fixes
claravanstaden 9363111
return err
claravanstaden ee432a9
return early
claravanstaden 5da080d
add log
claravanstaden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package parachain | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/decred/base58" | ||
"golang.org/x/crypto/blake2b" | ||
) | ||
|
||
func SS58Encode(pubKeyHex string, ss58Prefix uint8) (string, error) { | ||
if strings.HasPrefix(pubKeyHex, "0x") { | ||
pubKeyHex = pubKeyHex[2:] | ||
} | ||
|
||
pubKey, err := hex.DecodeString(pubKeyHex) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to decode hex: %w", err) | ||
} | ||
|
||
address := append([]byte{ss58Prefix}, pubKey...) | ||
|
||
hashInput := append([]byte("SS58PRE"), address...) | ||
|
||
hash := blake2b.Sum512(hashInput) | ||
checksum := hash[:2] | ||
|
||
fullAddress := append(address, checksum...) | ||
|
||
ss58Addr := base58.Encode(fullAddress) | ||
return ss58Addr, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package parachain | ||
|
||
import ( | ||
assert "github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestSS58Prefix(t *testing.T) { | ||
address := "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" | ||
|
||
ss58Address, err := SS58Encode(address, 1) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "A1k3praCLftTgBTb6aVavh3UNKwXN599Fqov17MkEy6bwCU", ss58Address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package parachain | ||
|
||
import ( | ||
"testing" | ||
|
||
gethCommon "github.com/ethereum/go-ethereum/common" | ||
assert "github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetDestination(t *testing.T) { | ||
registerTokenPayload := "00a736aa000000000000774667629726ec1fabebcec0d9139bd1c8f72a2300e87648170000000000000000000000" | ||
decodePayloadAndCompareDestinationAddress(t, registerTokenPayload, "") // register token does not have a destination | ||
|
||
sendTokenPayload := "00a736aa000000000001774667629726ec1fabebcec0d9139bd1c8f72a23008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4800c16ff2862300000000000000000000e87648170000000000000000000000" | ||
bobAddress := "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" | ||
decodePayloadAndCompareDestinationAddress(t, sendTokenPayload, bobAddress) | ||
|
||
sendTokenToPayload := "00a736aa000000000001774667629726ec1fabebcec0d9139bd1c8f72a2301d00700001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c00286bee000000000000000000000000000064a7b3b6e00d000000000000000000e87648170000000000000000000000" | ||
ferdieAddress := "0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c" | ||
decodePayloadAndCompareDestinationAddress(t, sendTokenToPayload, ferdieAddress) | ||
|
||
sendNativeTokenPayload := "00a736aa0000000000022121cfe35065c0c33465fbada265f08e9613428a4b9eb4bb717cd7db2abf622e008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48065cd1d00000000000000000000000000e87648170000000000000000000000" | ||
decodePayloadAndCompareDestinationAddress(t, sendNativeTokenPayload, bobAddress) | ||
} | ||
|
||
func decodePayloadAndCompareDestinationAddress(t *testing.T, payload, expectedAddress string) { | ||
data := gethCommon.Hex2Bytes(payload) | ||
|
||
destination, err := GetDestination(data) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, expectedAddress, destination) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package ofac | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type OFAC struct { | ||
enabled bool | ||
apiKey string | ||
} | ||
|
||
type Response struct { | ||
Identifications []struct { | ||
Category string `json:"category"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` | ||
} `json:"identifications"` | ||
} | ||
|
||
func New(enabled bool, apiKey string) *OFAC { | ||
return &OFAC{enabled, apiKey} | ||
} | ||
|
||
func (o OFAC) IsBanned(source, destination string) (bool, error) { | ||
if !o.enabled { | ||
return false, nil | ||
} | ||
|
||
if source != "" { | ||
isSourcedBanned, err := o.isOFACListed(source) | ||
if err != nil { | ||
return true, err | ||
} | ||
if isSourcedBanned { | ||
log.WithField("source", source).Warn("found ofac banned source address") | ||
return true, nil | ||
} | ||
} | ||
|
||
if destination != "" { | ||
isDestinationBanned, err := o.isOFACListed(destination) | ||
if err != nil { | ||
return true, err | ||
} | ||
if isDestinationBanned { | ||
log.WithField("destination", destination).Warn("found ofac banned destination address") | ||
return true, nil | ||
} | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
func (o OFAC) isOFACListed(address string) (bool, error) { | ||
client := &http.Client{} | ||
|
||
req, err := http.NewRequest("GET", fmt.Sprintf("https://public.chainalysis.com/api/v1/address/%s", address), nil) | ||
if err != nil { | ||
return true, err | ||
} | ||
|
||
req.Header.Add("Accept", "application/json") | ||
req.Header.Add("X-API-Key", o.apiKey) | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
return true, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return true, err | ||
} | ||
|
||
var response Response | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
return true, err | ||
} | ||
|
||
return len(response.Identifications) > 0, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in the UI we do not post the hex version of the account. We post the SS58 version. Not sure what the correct thing to do there is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw here Chainalysis does not support non-EVM chains. 😬 https://go.chainalysis.com/chainalysis-oracle-docs.html
Compatible networks
Edit: Nevermind, I see this is not the API but an oracle.Checking to see which Polkadot addresses they support...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
SS58
version is probably right, will add it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 1e9558e.