Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Check for signer keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Nov 30, 2018
1 parent 81e3192 commit 2b90dc4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prettier": "^1.14.3"
},
"dependencies": {
"@solana/web3.js": "0.13.2",
"@solana/web3.js": "0.13.4",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
Expand Down
5 changes: 5 additions & 0 deletions program-bpf/src/tictactoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ extern bool entrypoint(const uint8_t *input) {
return false;
}

if (!ka[0].is_signer) {
sol_log("Transaction not signed by key 0");
return false;
}

if (instruction_data_len < sizeof(uint32_t) + sizeof(CommandData)) {
sol_log("Error: invalid instruction_data_len");
sol_log_64(instruction_data_len, sizeof(uint32_t) + sizeof(CommandData), 0, 0, 0);
Expand Down
20 changes: 15 additions & 5 deletions program-native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use simple_serde::SimpleSerde;
use solana_sdk::account::KeyedAccount;
use solana_sdk::pubkey::Pubkey;

fn expect_n_accounts(info: &mut [KeyedAccount], n: usize) -> Result<()> {
fn xpect_n_accounts(info: &mut [KeyedAccount], n: usize) -> Result<()> {
if info.len() < n {
error!(
"Error: Expected at least {} accounts, received {}",
Expand Down Expand Up @@ -131,9 +131,11 @@ fn process_instruction(info: &mut [KeyedAccount], input: &[u8], tick_height: u64

match game_state {
State::Uninitialized => {
let game = game::Game::create(&info[2].key);
let game = game::Game::create(&info[2].unsigned_key());
match dashboard_state {
State::Dashboard(ref mut dashboard) => dashboard.update(&info[1].key, &game),
State::Dashboard(ref mut dashboard) => {
dashboard.update(&info[1].unsigned_key(), &game)
}
_ => {
error!(
"Invalid dashboard state for InitGame: {:?}",
Expand Down Expand Up @@ -169,7 +171,7 @@ fn process_instruction(info: &mut [KeyedAccount], input: &[u8], tick_height: u64

match game_state {
State::Game(ref mut game) => {
let player = info[0].key;
let player = info[0].signer_key().unwrap();
match command {
Command::Advertise => Ok(()), // Nothing to do here beyond the dashboard_update() below
Command::Join => game.join(*player, tick_height),
Expand All @@ -182,7 +184,9 @@ fn process_instruction(info: &mut [KeyedAccount], input: &[u8], tick_height: u64
}?;

match dashboard_state {
State::Dashboard(ref mut dashboard) => dashboard.update(&info[1].key, &game),
State::Dashboard(ref mut dashboard) => {
dashboard.update(&info[1].unsigned_key(), &game)
}
_ => {
error!("Invalid dashboard stat: {:?}", dashboard_state);
Err(ProgramError::InvalidInput)
Expand All @@ -209,6 +213,12 @@ fn entrypoint(
tick_height: u64,
) -> bool {
logger::setup();

if keyed_accounts[0].signer_key().is_none() {
error!("key 0 did not sign the transaction");
return false;
}

match process_instruction(keyed_accounts, data, tick_height) {
Err(err) => {
error!("{:?}", err);
Expand Down

0 comments on commit 2b90dc4

Please sign in to comment.