-
Notifications
You must be signed in to change notification settings - Fork 5
Hotfix no.2 - support user friendly address in plugin hot path (#672) #674
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package codec | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "encoding/binary" | ||
| "encoding/hex" | ||
| "errors" | ||
|
|
@@ -61,6 +62,28 @@ func NewAddressCodec() ccipocr3.ChainSpecificAddressCodec { | |
| return addressCodec{} | ||
| } | ||
|
|
||
| // AddressBytesToStringWithBurning converts a byte slice representing a TON address into its string representation. | ||
| // It first attempts to parse the bytes with `4 byte workchain (int32) + 32 byte data` TON address | ||
| // If that fails, we expect user-friendly format (36 bytes): 1 byte flags + 1 byte workchain + 32 bytes data + 2 bytes CRC16, by validating the format and CRC16 checksum. | ||
| // If parsing fails (invalid format, length, or CRC16), returns the zero address to indicate funds should be burned. | ||
| // This is only used in the hot path in plugin (executecodec.go and msghasher.go) where we want to avoid errors and just burn funds if the address is invalid | ||
| func AddressBytesToStringWithBurning(bytes []byte) *address.Address { | ||
| // First try parsing as raw format (4 byte workchain + 32 byte data) | ||
| if addr, err := AddressBytesToTONAddress(bytes); err == nil { | ||
| return addr | ||
| } | ||
|
|
||
| // user-friendly address encoding Validation with CRC16 checksum | ||
| addrStr := base64.RawURLEncoding.EncodeToString(bytes) | ||
| addr, err := address.ParseAddr(addrStr) | ||
| if err != nil { | ||
| // Checksum failed or invalid address format - return zero address to mark funds as burned | ||
| return tvm.ZeroAddress | ||
| } | ||
|
Comment on lines
+70
to
+82
|
||
|
|
||
| return addr | ||
| } | ||
|
|
||
| // AddressBytesToString converts a byte slice representing a TON address into its string representation, only supporting standard TON addresses. | ||
| func (a addressCodec) AddressBytesToString(bytes []byte) (string, error) { | ||
| if len(bytes) != tvm.AddressLength { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ import ( | |
| "math/big" | ||
| "strings" | ||
|
|
||
| "github.com/xssnick/tonutils-go/address" | ||
| "github.com/xssnick/tonutils-go/tlb" | ||
| "github.com/xssnick/tonutils-go/tvm/cell" | ||
|
|
||
|
|
@@ -101,36 +100,18 @@ func (e *executePluginCodecV1) Encode(ctx context.Context, report ccipocr3.Execu | |
| return nil, fmt.Errorf("pack extra data: %w", err) | ||
| } | ||
|
|
||
| destTokenAddrStr, err := e.addressCodec.AddressBytesToString(tokenAmount.DestTokenAddress) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("convert dest token address: %w", err) | ||
| } | ||
|
|
||
| DestPoolTonAddr, err := address.ParseAddr(destTokenAddrStr) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid dest token address %s: %w", destTokenAddrStr, err) | ||
| } | ||
|
|
||
| destPoolTonAddr := AddressBytesToStringWithBurning(tokenAmount.DestTokenAddress) | ||
| tokenAmounts = append(tokenAmounts, ocr.Any2TVMTokenTransfer{ | ||
| SourcePoolAddress: poolAddrCell, | ||
| ExtraData: extraData, | ||
| DestPoolAddress: DestPoolTonAddr, | ||
| DestPoolAddress: destPoolTonAddr, | ||
| Amount: tokenAmount.Amount.Int, | ||
| DestGasAmount: destGasAmount, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| tonReceiverAddrStr, err := e.addressCodec.AddressBytesToString(msg.Receiver) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error convert receiver address: %w", err) | ||
| } | ||
|
|
||
| tonReceiverAddr, err := address.ParseAddr(tonReceiverAddrStr) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid receiver address %s: %w", tonReceiverAddrStr, err) | ||
| } | ||
|
|
||
| tonReceiverAddr := AddressBytesToStringWithBurning(msg.Receiver) | ||
| header := ocr.RampMessageHeader{ | ||
|
Comment on lines
+103
to
115
|
||
| MessageID: msg.Header.MessageID[:], | ||
| SourceChainSelector: uint64(msg.Header.SourceChainSelector), | ||
|
|
@@ -139,6 +120,7 @@ func (e *executePluginCodecV1) Encode(ctx context.Context, report ccipocr3.Execu | |
| Nonce: msg.Header.Nonce, | ||
| } | ||
|
|
||
| var err error | ||
| var gasLimitBigInt *big.Int | ||
| var extraArgsDecodeMap map[string]any | ||
| if len(msg.ExtraArgs) > 0 { | ||
|
|
||
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.
AddressBytesToStringWithBurningreturns*address.Address, but both the function name and the doc comment say it converts to a “string representation”. This mismatch is misleading for callers; either rename it (e.g.,AddressBytesToAddressWithBurning) and adjust the comment, or change the return type to a string to match the name/documentation.