Skip to content

Commit

Permalink
added check that server address matches what we expect (derived from …
Browse files Browse the repository at this point in the history
…signature)
  • Loading branch information
Gil committed Mar 23, 2022
1 parent d3563f2 commit a5be984
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 50 deletions.
1 change: 0 additions & 1 deletion relayer/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func (s *Sentry) SendRelay(
// call user
defer clientSession.Lock.Unlock()
reply, err := cb(clientSession)
// TODO: check servicer pubkey is correct!

return reply, err
}
Expand Down
10 changes: 9 additions & 1 deletion relayer/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package relayer
import (
context "context"
"encoding/json"
"errors"
"log"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
Expand Down Expand Up @@ -65,7 +67,13 @@ func sendRelay(
if err != nil {
return nil, err
}
log.Println(serverKey)
serverAddr, err := sdk.AccAddressFromHex(serverKey.Address().String())
if err != nil {
return nil, err
}
if serverAddr.String() != clientSession.Client.Acc {
return nil, errors.New("server address mismatch in reply")
}

return reply, nil
})
Expand Down
32 changes: 16 additions & 16 deletions vue/src/store/generated/lavanet/lava/lavanet.lava.servicer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,20 @@ export default {
throw new SpVuexError('QueryClient:QueryGetPairing', 'API Node Unavailable. Could not perform query: ' + e.message);
}
},
async sendMsgUnstakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgUnstakeServicer(value);
const msg = await txClient.msgProofOfWork(value);
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Send', 'Could not broadcast Tx: ' + e.message);
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
Expand All @@ -372,35 +372,35 @@ export default {
}
}
},
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgUnstakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProofOfWork(value);
const msg = await txClient.msgUnstakeServicer(value);
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: ' + e.message);
throw new SpVuexError('TxClient:MsgUnstakeServicer:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
async MsgUnstakeServicer({ rootGetters }, { value }) {
async MsgProofOfWork({ rootGetters }, { value }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgUnstakeServicer(value);
const msg = await txClient.msgProofOfWork(value);
return msg;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Create', 'Could not create message: ' + e.message);
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message);
}
}
},
Expand All @@ -419,18 +419,18 @@ export default {
}
}
},
async MsgProofOfWork({ rootGetters }, { value }) {
async MsgUnstakeServicer({ rootGetters }, { value }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProofOfWork(value);
const msg = await txClient.msgUnstakeServicer(value);
return msg;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message);
throw new SpVuexError('TxClient:MsgUnstakeServicer:Create', 'Could not create message: ' + e.message);
}
}
},
Expand Down
32 changes: 16 additions & 16 deletions vue/src/store/generated/lavanet/lava/lavanet.lava.servicer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,18 @@ export default {
},


async sendMsgUnstakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgUnstakeServicer(value)
const msg = await txClient.msgProofOfWork(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgUnstakeServicer:Send', 'Could not broadcast Tx: '+ e.message)
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -460,32 +460,32 @@ export default {
}
}
},
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgUnstakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProofOfWork(value)
const msg = await txClient.msgUnstakeServicer(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: '+ e.message)
throw new SpVuexError('TxClient:MsgUnstakeServicer:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},

async MsgUnstakeServicer({ rootGetters }, { value }) {
async MsgProofOfWork({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgUnstakeServicer(value)
const msg = await txClient.msgProofOfWork(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgUnstakeServicer:Create', 'Could not create message: ' + e.message)
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message)

}
}
Expand All @@ -504,16 +504,16 @@ export default {
}
}
},
async MsgProofOfWork({ rootGetters }, { value }) {
async MsgUnstakeServicer({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProofOfWork(value)
const msg = await txClient.msgUnstakeServicer(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgUnstakeServicer:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message)
throw new SpVuexError('TxClient:MsgUnstakeServicer:Create', 'Could not create message: ' + e.message)

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StdFee } from "@cosmjs/launchpad";
import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";
export declare const MissingWalletError: Error;
export declare const registry: Registry;
interface TxClientOptions {
Expand All @@ -15,9 +15,9 @@ interface SignAndBroadcastOptions {
}
declare const txClient: (wallet: OfflineSigner, { addr: addr }?: TxClientOptions) => Promise<{
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }?: SignAndBroadcastOptions) => any;
msgUnstakeServicer: (data: MsgUnstakeServicer) => EncodeObject;
msgStakeServicer: (data: MsgStakeServicer) => EncodeObject;
msgProofOfWork: (data: MsgProofOfWork) => EncodeObject;
msgStakeServicer: (data: MsgStakeServicer) => EncodeObject;
msgUnstakeServicer: (data: MsgUnstakeServicer) => EncodeObject;
}>;
interface QueryClientOptions {
addr: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";
const types = [
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],
];
export const MissingWalletError = new Error("wallet is required");
export const registry = new Registry(types);
Expand All @@ -29,9 +29,9 @@ const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657
const { address } = (await wallet.getAccounts())[0];
return {
signAndBroadcast: (msgs, { fee, memo } = { fee: defaultFee, memo: "" }) => client.signAndBroadcast(address, msgs, fee, memo),
msgUnstakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial(data) }),
msgStakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial(data) }),
msgProofOfWork: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial(data) }),
msgStakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial(data) }),
msgUnstakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial(data) }),
};
};
const queryClient = async ({ addr: addr } = { addr: "http://localhost:1317" }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";


const types = [
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],

];
export const MissingWalletError = new Error("wallet is required");
Expand Down Expand Up @@ -45,9 +45,9 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =

return {
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
msgUnstakeServicer: (data: MsgUnstakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial( data ) }),
msgStakeServicer: (data: MsgStakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial( data ) }),
msgProofOfWork: (data: MsgProofOfWork): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial( data ) }),
msgStakeServicer: (data: MsgStakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial( data ) }),
msgUnstakeServicer: (data: MsgUnstakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial( data ) }),

};
};
Expand Down

0 comments on commit a5be984

Please sign in to comment.