Skip to content
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

ccip - EVM Implementation of RMNCrypto interface #14416

Merged
merged 14 commits into from
Sep 17, 2024
Prev Previous commit
Next Next commit
no panics
  • Loading branch information
dimkouv committed Sep 16, 2024
commit 2eaaf3e4e418067928f317b2ccdbafa6649d24c6
37 changes: 20 additions & 17 deletions core/capabilities/ccip/ccipevm/rmncrypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@ import (
const encodingUtilsAbiRaw = `[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DoNotDeploy","type":"error"},{"inputs":[{"internalType":"bytes32","name":"rmnReportVersion","type":"bytes32"},{"components":[{"internalType":"uint256","name":"destChainId","type":"uint256"},{"internalType":"uint64","name":"destChainSelector","type":"uint64"},{"internalType":"address","name":"rmnRemoteContractAddress","type":"address"},{"internalType":"address","name":"offrampAddress","type":"address"},{"internalType":"bytes32","name":"rmnHomeContractConfigDigest","type":"bytes32"},{"components":[{"internalType":"uint64","name":"sourceChainSelector","type":"uint64"},{"internalType":"bytes","name":"onRampAddress","type":"bytes"},{"internalType":"uint64","name":"minSeqNr","type":"uint64"},{"internalType":"uint64","name":"maxSeqNr","type":"uint64"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"internalType":"struct Internal.MerkleRoot[]","name":"destLaneUpdates","type":"tuple[]"}],"internalType":"struct RMNRemote.Report","name":"rmnReport","type":"tuple"}],"name":"_rmnReport","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
const addressEncodeAbiRaw = `[{"name":"method","type":"function","inputs":[{"name": "", "type": "address"}]}]`

// EVMRMNCrypto is the RMNCrypto implementation for EVM chains.
type EVMRMNCrypto struct {
encodingUtilsABI abi.ABI
addressEncodeABI abi.ABI
}
var (
EncodingUtilsABI abi.ABI
AddressEncodeABI abi.ABI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

)

// Interface compliance check
var _ cciptypes.RMNCrypto = (*EVMRMNCrypto)(nil)
func init() {
var err error

func NewEVMRMNCrypto() *EVMRMNCrypto {
encodingUtilsABI, err := abi.JSON(strings.NewReader(encodingUtilsAbiRaw))
EncodingUtilsABI, err = abi.JSON(strings.NewReader(encodingUtilsAbiRaw))
if err != nil {
panic(fmt.Errorf("failed to parse encoding utils ABI: %v", err))
}

addressEncodeABI, err := abi.JSON(strings.NewReader(addressEncodeAbiRaw))
AddressEncodeABI, err = abi.JSON(strings.NewReader(addressEncodeAbiRaw))
if err != nil {
panic(fmt.Errorf("failed to parse address encode ABI: %v", err))
}
}

return &EVMRMNCrypto{
encodingUtilsABI: encodingUtilsABI,
addressEncodeABI: addressEncodeABI,
}
// EVMRMNCrypto is the RMNCrypto implementation for EVM chains.
type EVMRMNCrypto struct{}

// Interface compliance check
var _ cciptypes.RMNCrypto = (*EVMRMNCrypto)(nil)

func NewEVMRMNCrypto() *EVMRMNCrypto {
return &EVMRMNCrypto{}
}

type evmRMNRemoteReport struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TODO also to use the types from the gethwrappers when they're available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Expand All @@ -64,7 +67,7 @@ type evmInternalMerkleRoot struct {
}

func (r *EVMRMNCrypto) VerifyReportSignatures(
ctx context.Context,
_ context.Context,
sigs []cciptypes.RMNECDSASignature,
report cciptypes.RMNReport,
signerAddresses []cciptypes.Bytes,
Expand All @@ -83,7 +86,7 @@ func (r *EVMRMNCrypto) VerifyReportSignatures(
evmLaneUpdates := make([]evmInternalMerkleRoot, len(report.LaneUpdates))
for i, lu := range report.LaneUpdates {
onRampAddress := common.BytesToAddress(lu.OnRampAddress)
onRampAddrAbi, err := abiEncodeMethodInputs(r.addressEncodeABI, onRampAddress)
onRampAddrAbi, err := abiEncodeMethodInputs(AddressEncodeABI, onRampAddress)
if err != nil {
return fmt.Errorf("ΑΒΙ encode onRampAddress: %w", err)
}
Expand All @@ -105,7 +108,7 @@ func (r *EVMRMNCrypto) VerifyReportSignatures(
DestLaneUpdates: evmLaneUpdates,
}

abiEnc, err := r.encodingUtilsABI.Methods["_rmnReport"].Inputs.Pack(rmnVersionHash, evmReport)
abiEnc, err := EncodingUtilsABI.Methods["_rmnReport"].Inputs.Pack(rmnVersionHash, evmReport)
if err != nil {
return fmt.Errorf("failed to ABI encode args: %w", err)
}
Expand Down
Loading