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

autopilot hashed sender option (3) #1046

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions x/autopilot/keeper/liquidstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,6 @@ func (k Keeper) IBCTransferStToken(
channelId = hostZone.TransferChannelId
}

// Generate a hashed address for the sender to the next hop,
// to prevent impersonation at downstream zones
// Note: The channel ID here is different than the one used in PFM
// (we use the outbound channelID, they use the inbound channelID)
// DOUBLE CHECK ME that it shouldn't matter
hashedAddress, err := types.GenerateHashedAddress(channelId, transferMetadata.Sender)
if err != nil {
return err
}

// First we need to bank send to the hashed address
originalReceiver, err := sdk.AccAddressFromBech32(transferMetadata.Receiver)
if err != nil {
return err
}
hashedSender, err := sdk.AccAddressFromBech32(hashedAddress)
if err != nil {
return err
}
if err := k.bankKeeper.SendCoins(ctx, originalReceiver, hashedSender, sdk.NewCoins(stToken)); err != nil {
return err
}

// Use the default transfer timeout of 10 minutes
timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + transfertypes.DefaultRelativePacketTimeoutTimestamp

Expand All @@ -144,7 +121,7 @@ func (k Keeper) IBCTransferStToken(
SourcePort: transfertypes.PortID,
SourceChannel: channelId,
Token: stToken,
Sender: hashedAddress,
Sender: transferMetadata.Receiver,
Receiver: autopilotMetadata.IbcReceiver,
TimeoutTimestamp: timeoutTimestamp,
Memo: "autopilot-liquid-stake-and-forward",
Expand Down
28 changes: 25 additions & 3 deletions x/autopilot/module_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,31 @@ func (im IBCModule) OnRecvPacket(

//// At this point, we are officially dealing with an autopilot packet

// Modify the packet data by replacing the JSON metadata field with a receiver address
// to allow the packet to continue down the stack
tokenPacketData.Receiver = autopilotMetadata.Receiver
// Update the reciever in the packet data so that we can pass the packet down the stack
// (since the "receiver" may have technically been a full JSON memo)
switch routingInfo := autopilotMetadata.RoutingInfo.(type) {
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
case types.StakeibcPacketMetadata:
// For autopilot liquid stake and forward, we'll use a hashed receiver address instead
// that will also be used as the sender in the forwarding step
// This is to prevent impersonation at downstream zones
// We can identify the forwarding step by whether there's a non-empty IBC receiver field
if routingInfo.Action == types.LiquidStake && routingInfo.IbcReceiver != "" {
sampocs marked this conversation as resolved.
Show resolved Hide resolved
hashedReceiver, err := types.GenerateHashedAddress(packet.DestinationChannel, tokenPacketData.Sender)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
}
tokenPacketData.Receiver = hashedReceiver
} else {
// For all other stakeibc actions, use the original receiver
tokenPacketData.Receiver = autopilotMetadata.Receiver
}
default:
// For non stakeibc autopilot actions, use the original receiver
tokenPacketData.Receiver = autopilotMetadata.Receiver
}

// Now that the receiver's been updated on the transfer metadata,
// modify the original packet so that we can send it down the stack
bz, err := transfertypes.ModuleCdc.MarshalJSON(&tokenPacketData)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
Expand Down