Skip to content

Commit 7a0b494

Browse files
committed
Add unknown address types.
Remove mustNewBytes Remove mustNewBytes
1 parent cbfa30e commit 7a0b494

15 files changed

+60
-1049
lines changed

pkg/types/ccipocr3/v2/common_types.go

+28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@ import (
77
"strings"
88
)
99

10+
// UnknownAddress represents a raw address with an unknown encoding.
11+
type UnknownAddress []byte
12+
13+
// NewUnknownAddressFromHex creates a new UnknownAddress from a hex string.
14+
func NewUnknownAddressFromHex(s string) (UnknownAddress, error) {
15+
b, err := NewBytesFromString(s)
16+
if err != nil {
17+
return nil, err
18+
}
19+
return UnknownAddress(b), nil
20+
}
21+
22+
// String returns the hex representation of the unknown address.
23+
func (a UnknownAddress) String() string {
24+
return Bytes(a).String()
25+
}
26+
27+
func (a UnknownAddress) MarshalJSON() ([]byte, error) {
28+
return Bytes(a).MarshalJSON()
29+
}
30+
31+
func (a *UnknownAddress) UnmarshalJSON(data []byte) error {
32+
return (*Bytes)(a).UnmarshalJSON(data)
33+
}
34+
35+
// UnknownEncodedAddress represents an encoded address with an unknown encoding.
36+
type UnknownEncodedAddress string
37+
1038
type Bytes []byte
1139

1240
func NewBytesFromString(s string) (Bytes, error) {

pkg/types/ccipocr3/v2/common_types_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,15 @@ func TestNewBytesFromString(t *testing.T) {
132132
require.Equal(t, tt.want, got)
133133
}
134134
})
135+
136+
t.Run(tt.name, func(t *testing.T) {
137+
got, err := NewUnknownAddressFromHex(tt.arg)
138+
if tt.wantErr {
139+
require.Error(t, err)
140+
} else {
141+
require.NoError(t, err)
142+
require.Equal(t, UnknownAddress(tt.want), got)
143+
}
144+
})
135145
}
136146
}

pkg/types/ccipocr3/v2/generic_types.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import (
55
"fmt"
66
"math/big"
77
"strconv"
8-
9-
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
108
)
119

1210
type TokenPrice struct {
13-
TokenID types.Account `json:"tokenID"`
14-
Price BigInt `json:"price"`
11+
TokenID UnknownEncodedAddress `json:"tokenID"`
12+
Price BigInt `json:"price"`
1513
}
1614

17-
func NewTokenPrice(tokenID types.Account, price *big.Int) TokenPrice {
15+
func NewTokenPrice(tokenID UnknownEncodedAddress, price *big.Int) TokenPrice {
1816
return TokenPrice{
1917
TokenID: tokenID,
2018
Price: BigInt{price},
@@ -113,18 +111,18 @@ type Message struct {
113111
Header RampMessageHeader `json:"header"`
114112
// Sender address on the source chain.
115113
// i.e if the source chain is EVM, this is an abi-encoded EVM address.
116-
Sender Bytes `json:"sender"`
114+
Sender UnknownAddress `json:"sender"`
117115
// Data is the arbitrary data payload supplied by the message sender.
118116
Data Bytes `json:"data"`
119117
// Receiver is the receiver address on the destination chain.
120118
// This is encoded in the destination chain family specific encoding.
121119
// i.e if the destination is EVM, this is abi.encode(receiver).
122-
Receiver Bytes `json:"receiver"`
120+
Receiver UnknownAddress `json:"receiver"`
123121
// ExtraArgs is destination-chain specific extra args, such as the gasLimit for EVM chains.
124122
ExtraArgs Bytes `json:"extraArgs"`
125123
// FeeToken is the fee token address.
126124
// i.e if the source chain is EVM, len(FeeToken) == 20 (i.e, is not abi-encoded).
127-
FeeToken Bytes `json:"feeToken"`
125+
FeeToken UnknownAddress `json:"feeToken"`
128126
// FeeTokenAmount is the amount of fee tokens paid.
129127
FeeTokenAmount BigInt `json:"feeTokenAmount"`
130128
// FeeValueJuels is the fee amount in Juels
@@ -161,19 +159,19 @@ type RampMessageHeader struct {
161159

162160
// OnRamp is the address of the onramp that sent the message.
163161
// NOTE: This is populated by the ccip reader. Not emitted explicitly onchain.
164-
OnRamp Bytes `json:"onRamp"`
162+
OnRamp UnknownAddress `json:"onRamp"`
165163
}
166164

167165
// RampTokenAmount represents the family-agnostic token amounts used for both OnRamp & OffRamp messages.
168166
type RampTokenAmount struct {
169167
// SourcePoolAddress is the source pool address, encoded according to source family native encoding scheme.
170168
// This value is trusted as it was obtained through the onRamp. It can be relied upon by the destination
171169
// pool to validate the source pool.
172-
SourcePoolAddress Bytes `json:"sourcePoolAddress"`
170+
SourcePoolAddress UnknownAddress `json:"sourcePoolAddress"`
173171

174172
// DestTokenAddress is the address of the destination token, abi encoded in the case of EVM chains.
175173
// This value is UNTRUSTED as any pool owner can return whatever value they want.
176-
DestTokenAddress Bytes `json:"destTokenAddress"`
174+
DestTokenAddress UnknownAddress `json:"destTokenAddress"`
177175

178176
// ExtraData is optional pool data to be transferred to the destination chain. Be default this is capped at
179177
// CCIP_LOCK_OR_BURN_V1_RET_BYTES bytes. If more data is required, the TokenTransferFeeConfig.destBytesOverhead

pkg/types/ccipocr3/v2/generic_types_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestCCIPMsg_String(t *testing.T) {
152152
Nonce: 1,
153153

154154
MsgHash: mustNewBytes32(t, "0x23"),
155-
OnRamp: mustNewBytes(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
155+
OnRamp: mustNewUnknownAddress(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
156156
},
157157
},
158158
`{"header":{"messageId":"0x0100000000000000000000000000000000000000000000000000000000000000","sourceChainSelector":"1","destChainSelector":"2","seqNum":"2","nonce":1,"msgHash":"0x2300000000000000000000000000000000000000000000000000000000000000","onRamp":"0x04d4cc5972ad487f71b85654d48b27d32b13a22f"},"sender":"0x","data":"0x","receiver":"0x","extraArgs":"0x","feeToken":"0x","feeTokenAmount":null,"feeValueJuels":null,"tokenAmounts":null}`,
@@ -168,18 +168,18 @@ func TestCCIPMsg_String(t *testing.T) {
168168
Nonce: 1,
169169

170170
MsgHash: mustNewBytes32(t, "0x23"),
171-
OnRamp: mustNewBytes(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
171+
OnRamp: mustNewUnknownAddress(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
172172
},
173-
Sender: mustNewBytes(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
174-
Receiver: mustNewBytes(t, "0x101112131415"), // simulate a non-evm receiver
173+
Sender: mustNewUnknownAddress(t, "0x04D4cC5972ad487F71b85654d48b27D32b13a22F"),
174+
Receiver: mustNewUnknownAddress(t, "0x101112131415"), // simulate a non-evm receiver
175175
Data: []byte("some data"),
176176
ExtraArgs: []byte("extra args"),
177-
FeeToken: mustNewBytes(t, "0xB5fCC870d2aC8745054b4ba99B1f176B93382162"),
177+
FeeToken: mustNewUnknownAddress(t, "0xB5fCC870d2aC8745054b4ba99B1f176B93382162"),
178178
FeeTokenAmount: BigInt{Int: big.NewInt(1000)},
179179
FeeValueJuels: BigInt{Int: big.NewInt(287)},
180180
TokenAmounts: []RampTokenAmount{
181181
{
182-
SourcePoolAddress: mustNewBytes(t, "0x3E8456720B88A1DAdce8E2808C9Bf73dfFFd807c"),
182+
SourcePoolAddress: mustNewUnknownAddress(t, "0x3E8456720B88A1DAdce8E2808C9Bf73dfFFd807c"),
183183
DestTokenAddress: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // simulate a non-evm token
184184
ExtraData: []byte("extra token data"),
185185
Amount: BigInt{Int: big.NewInt(2000)},
@@ -246,8 +246,8 @@ func mustNewBytes32(t *testing.T, s string) Bytes32 {
246246
return b32
247247
}
248248

249-
func mustNewBytes(t *testing.T, s string) Bytes {
250-
b, err := NewBytesFromString(s)
249+
func mustNewUnknownAddress(t *testing.T, s string) UnknownAddress {
250+
a, err := NewUnknownAddressFromHex(s)
251251
require.NoError(t, err)
252-
return b
252+
return a
253253
}

pkg/types/ccipocr3/v2/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type RMNCrypto interface {
2828
ctx context.Context,
2929
sigs []RMNECDSASignature,
3030
report RMNReport,
31-
signerAddresses []Bytes,
31+
signerAddresses []UnknownAddress,
3232
) error
3333
}
3434

pkg/types/ccipocr3/v2/rmn_types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ type RMNReport struct {
55
ReportVersion string // e.g. "RMN_V1_6_ANY2EVM_REPORT".
66
DestChainID BigInt // If applies, a chain specific id, e.g. evm chain id otherwise empty.
77
DestChainSelector ChainSelector
8-
RmnRemoteContractAddress Bytes
9-
OfframpAddress Bytes
8+
RmnRemoteContractAddress UnknownAddress
9+
OfframpAddress UnknownAddress
1010
RmnHomeContractConfigDigest Bytes32
1111
LaneUpdates []RMNLaneUpdate
1212
}
@@ -15,7 +15,7 @@ type RMNReport struct {
1515
// It is part of the payload that is signed and transmitted onchain.
1616
type RMNLaneUpdate struct {
1717
SourceChainSelector ChainSelector
18-
OnRampAddress Bytes // (for EVM should be abi-encoded)
18+
OnRampAddress UnknownAddress // (for EVM should be abi-encoded)
1919
MinSeqNr SeqNum
2020
MaxSeqNr SeqNum
2121
MerkleRoot Bytes32

pkg/types/ccipocr3/v2/v2/common_types.go

-148
This file was deleted.

0 commit comments

Comments
 (0)