Skip to content

Commit

Permalink
Fix legacy to support Tendermint 37 (#1463)
Browse files Browse the repository at this point in the history
* Updated cosmjs packages to support tendermint 37.

* Fixed cosmodal commit hash.

* Backport decodeMessages vulnerability.
  • Loading branch information
NoahSaso committed Nov 9, 2023
1 parent 77ad4f9 commit 51a6504
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 204 deletions.
8 changes: 4 additions & 4 deletions apps/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"ts:watch": "ts --watch"
},
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.28.1",
"@cosmjs/encoding": "^0.28.1",
"@cosmjs/proto-signing": "^0.28.1",
"@cosmjs/stargate": "^0.28.1",
"@cosmjs/cosmwasm-stargate": "^0.31.3",
"@cosmjs/encoding": "^0.31.3",
"@cosmjs/proto-signing": "^0.31.3",
"@cosmjs/stargate": "^0.31.3",
"@dao-dao/icons": "*",
"@dao-dao/types": "^0.0.8",
"@dao-dao/ui": "*",
Expand Down
6 changes: 3 additions & 3 deletions apps/dapp/selectors/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export const contractInstantiateTime = selectorFamily<Date | undefined, string>(
return undefined
}

const events = await client.searchTx({
tags: [{ key: 'instantiate._contract_address', value: address }],
})
const events = await client.searchTx([
{ key: 'instantiate._contract_address', value: address },
])
if (events.length == 0) {
// Failed to locate the instantiate transaction. This happens if the
// RPC node doesn't have historical data this far back.
Expand Down
24 changes: 10 additions & 14 deletions apps/dapp/selectors/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ export const proposalStartBlockSelector = selectorFamily<
return 0
}

const events = await client.searchTx({
tags: [
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'propose' },
],
})
const events = await client.searchTx([
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'propose' },
])

if (events.length != 1) {
return 0
Expand Down Expand Up @@ -172,13 +170,11 @@ export const proposalExecutionTXHashSelector = selectorFamily<
// No TX Hash if proposal not yet executed.
if (!client || proposal?.status !== 'executed') return null

const events = await client.searchTx({
tags: [
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'execute' },
],
})
const events = await client.searchTx([
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'execute' },
])

if (events.length > 1) {
console.error('More than one execution', events)
Expand Down
6 changes: 3 additions & 3 deletions apps/dapp/selectors/treasury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export const transactions = selectorFamily({
(address: string) =>
async ({ get }) => {
const client = get(cosmWasmClientSelector)
const response = (await client.searchTx({
sentFromOrTo: address,
})) as IndexedTx[]
const response = (await client.searchTx(
`message.module='bank' AND (transfer.sender='${address}' OR transfer.recipient='${address}')`
)) as IndexedTx[]
return response
},
})
Expand Down
38 changes: 15 additions & 23 deletions apps/dapp/util/messagehelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,39 +408,31 @@ function isBinaryType(msgType?: WasmMsgType): boolean {
export function decodeMessages(
msgs: ProposalResponse['msgs']
): { [key: string]: any }[] {
const decodedMessageArray: any[] = []
const proposalMsgs = Object.values(msgs)
for (const msgObj of proposalMsgs) {
if (isWasmMsg(msgObj)) {
const msgType = getWasmMsgType(msgObj.wasm)
return msgs.map((msg) => {
if (isWasmMsg(msg)) {
const msgType = getWasmMsgType(msg.wasm)
if (msgType && isBinaryType(msgType)) {
const base64Msg = (msgObj.wasm as any)[msgType]
if (base64Msg) {
const msg = parseEncodedMessage(base64Msg.msg)
if (msg) {
decodedMessageArray.push({
...msgObj,
const base64MsgContainer = (msg.wasm as any)[msgType]
if (base64MsgContainer && 'msg' in base64MsgContainer) {
const parsedMsg = parseEncodedMessage(base64MsgContainer.msg)
if (parsedMsg) {
return {
...msg,
wasm: {
...msgObj.wasm,
...msg.wasm,
[msgType]: {
...base64Msg,
msg,
...base64MsgContainer,
msg: parsedMsg,
},
},
})
}
}
}
}
} else {
decodedMessageArray.push(msgObj)
}
}

const decodedMessages = decodedMessageArray.length
? decodedMessageArray
: proposalMsgs

return decodedMessages
return msg
})
}

export function decodedMessagesString(msgs: ProposalResponse['msgs']): string {
Expand Down
8 changes: 4 additions & 4 deletions apps/sda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"ts:watch": "ts --watch"
},
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.28.1",
"@cosmjs/encoding": "^0.28.1",
"@cosmjs/proto-signing": "^0.28.1",
"@cosmjs/stargate": "^0.28.1",
"@cosmjs/cosmwasm-stargate": "^0.31.3",
"@cosmjs/encoding": "^0.31.3",
"@cosmjs/proto-signing": "^0.31.3",
"@cosmjs/stargate": "^0.31.3",
"@dao-dao/icons": "*",
"@dao-dao/state": "*",
"@dao-dao/types": "^0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@keplr-wallet/stores": "^0.10.3",
"@walletconnect/browser-utils": "^1.7.8",
"@walletconnect/client": "^1.7.8",
"cosmodal": "https://github.com/NoahSaso/cosmodal#7abc9d43f31693f56d3809dc7a87eeedce3c3ca2",
"cosmodal": "https://github.com/NoahSaso/cosmodal#a3db5393bedf755613f76c5adff0a3de126df09d",
"react": "^18.1.0",
"recoil": "^0.7.2"
},
Expand Down
12 changes: 5 additions & 7 deletions packages/state/recoil/selectors/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ export const proposalExecutionTXHashSelector = selectorFamily<
// No TX Hash if proposal not yet executed.
if (!client || proposal?.proposal.status !== Status.Executed) return

const events = await client.searchTx({
tags: [
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'execute' },
],
})
const events = await client.searchTx([
{ key: 'wasm._contract_address', value: contractAddress },
{ key: 'wasm.proposal_id', value: proposalId.toString() },
{ key: 'wasm.action', value: 'execute' },
])

if (events.length > 1) {
console.error('More than one execution', events)
Expand Down
38 changes: 15 additions & 23 deletions packages/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,31 @@ function isBinaryType(msgType?: WasmMsgType): boolean {
export function decodeMessages(
msgs: ProposalResponse['msgs']
): { [key: string]: any }[] {
const decodedMessageArray: any[] = []
const proposalMsgs = Object.values(msgs)
for (const msgObj of proposalMsgs) {
if (isWasmMsg(msgObj)) {
const msgType = getWasmMsgType(msgObj.wasm)
return msgs.map((msg) => {
if (isWasmMsg(msg)) {
const msgType = getWasmMsgType(msg.wasm)
if (msgType && isBinaryType(msgType)) {
const base64Msg = (msgObj.wasm as any)[msgType]
if (base64Msg) {
const msg = parseEncodedMessage(base64Msg.msg)
if (msg) {
decodedMessageArray.push({
...msgObj,
const base64MsgContainer = (msg.wasm as any)[msgType]
if (base64MsgContainer && 'msg' in base64MsgContainer) {
const parsedMsg = parseEncodedMessage(base64MsgContainer.msg)
if (parsedMsg) {
return {
...msg,
wasm: {
...msgObj.wasm,
...msg.wasm,
[msgType]: {
...base64Msg,
msg,
...base64MsgContainer,
msg: parsedMsg,
},
},
})
}
}
}
}
} else {
decodedMessageArray.push(msgObj)
}
}

const decodedMessages = decodedMessageArray.length
? decodedMessageArray
: proposalMsgs

return decodedMessages
return msg
})
}

export function decodedMessagesString(msgs: ProposalResponse['msgs']): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"prettier": "@dao-dao/config/prettier",
"license": "MIT",
"dependencies": {
"cosmodal": "https://github.com/NoahSaso/cosmodal#7abc9d43f31693f56d3809dc7a87eeedce3c3ca2"
"cosmodal": "https://github.com/NoahSaso/cosmodal#a3db5393bedf755613f76c5adff0a3de126df09d"
}
}
Loading

0 comments on commit 51a6504

Please sign in to comment.