Ensure key[0] is signed
This commit is contained in:
parent
99445f475b
commit
41689256c6
|
@ -15,6 +15,7 @@ pub enum StorageProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum StorageError {
|
pub enum StorageError {
|
||||||
|
InvalidArgument,
|
||||||
InvalidUserData,
|
InvalidUserData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +41,11 @@ pub fn process_instruction(
|
||||||
pix: usize,
|
pix: usize,
|
||||||
_accounts: &mut [&mut Account],
|
_accounts: &mut [&mut Account],
|
||||||
) -> Result<(), StorageError> {
|
) -> Result<(), StorageError> {
|
||||||
|
// accounts_keys[0] must be signed
|
||||||
|
if tx.signed_key(pix, 0).is_none() {
|
||||||
|
Err(StorageError::InvalidArgument)?;
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(syscall) = deserialize(tx.userdata(pix)) {
|
if let Ok(syscall) = deserialize(tx.userdata(pix)) {
|
||||||
match syscall {
|
match syscall {
|
||||||
StorageProgram::SubmitMiningProof { sha_state } => {
|
StorageProgram::SubmitMiningProof { sha_state } => {
|
||||||
|
|
|
@ -70,12 +70,20 @@ pub fn process_instruction(
|
||||||
instruction_index: usize,
|
instruction_index: usize,
|
||||||
accounts: &mut [&mut Account],
|
accounts: &mut [&mut Account],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
// all vote instructions require that accounts_keys[0] be a signer
|
||||||
|
if tx.signed_key(instruction_index, 0).is_none() {
|
||||||
|
Err(Error::InvalidArguments)?;
|
||||||
|
}
|
||||||
|
|
||||||
match deserialize(tx.userdata(instruction_index)) {
|
match deserialize(tx.userdata(instruction_index)) {
|
||||||
Ok(VoteInstruction::RegisterAccount) => {
|
Ok(VoteInstruction::RegisterAccount) => {
|
||||||
|
if !check_id(&accounts[1].owner) {
|
||||||
|
error!("accounts[1] is not assigned to the VOTE_PROGRAM");
|
||||||
|
Err(Error::InvalidArguments)?;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: a single validator could register multiple "vote accounts"
|
// TODO: a single validator could register multiple "vote accounts"
|
||||||
// which would clutter the "accounts" structure. See github issue 1654.
|
// which would clutter the "accounts" structure. See github issue 1654.
|
||||||
accounts[1].owner = id();
|
|
||||||
|
|
||||||
let mut vote_state = VoteProgram {
|
let mut vote_state = VoteProgram {
|
||||||
votes: VecDeque::new(),
|
votes: VecDeque::new(),
|
||||||
node_id: *tx.from(),
|
node_id: *tx.from(),
|
||||||
|
|
Loading…
Reference in New Issue