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

feat(xcvm): validate tip address sent by untrusted users #4077

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ pub(crate) fn handle_execute_program(
env: Env,
info: MessageInfo,
execute_program: msg::ExecuteProgramMsg,
tip: Addr,
tip: String,
) -> Result {
let this = msg::Gateway::new(env.contract.address);
let tip = deps.api.addr_validate(&tip)?;
let call_origin = CallOrigin::Local { user: info.sender.clone() };
let transfers = transfer_from_user(
&deps,
Expand Down
2 changes: 1 addition & 1 deletion code/xcvm/cosmwasm/contracts/pingpong/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> R
};
Ok(Response::default().add_message(wasm_execute(
gateway,
&xc_core::gateway::ExecuteMsg::ExecuteProgram { execute_program, tip: info.sender },
&xc_core::gateway::ExecuteMsg::ExecuteProgram { execute_program, tip: info.sender.into() },
Default::default(),
)?))
}
Expand Down
12 changes: 6 additions & 6 deletions code/xcvm/lib/core/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum ExecuteMsg {
ExecuteProgram {
/// Program to execute.
execute_program: ExecuteProgramMsg,
tip: Addr,
tip: String,
},

/// Request to execute a program on behalf of given user.
Expand Down Expand Up @@ -243,7 +243,7 @@ mod tests {
program: XcProgram { tag: b"noop".to_vec(), instructions: [].into() },
assets: <_>::default(),
},
tip: Addr::unchecked("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
tip: String::from("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
};
let program = serde_json_wasm::to_string(&program).expect("serde");
let expected = serde_json_wasm::to_string(
Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
program: XcProgram { tag: b"noop_with_asset".to_vec(), instructions: [].into() },
assets: vec![(pica_on_centauri, 1_000_000_000u128)].into(),
},
tip: Addr::unchecked("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
tip: String::from("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
};

let program = serde_json_wasm::to_string(&program).expect("serde");
Expand Down Expand Up @@ -332,7 +332,7 @@ mod tests {
},
assets: vec![(pica_on_centauri, 1_000_000_000u128)].into(),
},
tip: Addr::unchecked("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
tip: String::from("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
};

let program = serde_json_wasm::to_string(&program).expect("serde");
Expand Down Expand Up @@ -420,7 +420,7 @@ mod tests {
},
assets: vec![(pica_on_centauri, 1_000_000_000u128)].into(),
},
tip: Addr::unchecked("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
tip: String::from("centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
};

//pica_on_osmosis
Expand Down Expand Up @@ -520,7 +520,7 @@ mod tests {
},
assets: vec![(osmo_on_osmosis, 1_000_000_000u128)].into(),
},
tip: Addr::unchecked("osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
tip: String::from("osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"),
};

let program = serde_json_wasm::to_string(&program).expect("serde");
Expand Down
Loading