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

Check blocked accounts #181 #183

Merged
merged 5 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions evm_loader/program/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ fn process_instruction<'a>(
do_finalize(program_id, accounts)
},
EvmInstruction::Call {bytes} => {
StorageAccount::check_for_blocked_accounts(program_id, accounts)?;
let mut account_storage = ProgramAccountStorage::new(program_id, accounts)?;
if let Sender::Solana(_addr) = account_storage.get_sender() {
// Success execution
Expand All @@ -235,6 +236,7 @@ fn process_instruction<'a>(

let trx: UnsignedTransaction = rlp::decode(unsigned_msg).map_err(|e| E!(ProgramError::InvalidInstructionData; "DecoderError={:?}", e))?;

StorageAccount::check_for_blocked_accounts(program_id, &accounts[1..])?;
let account_storage = ProgramAccountStorage::new(program_id, &accounts[1..])?;
let from_addr = verify_tx_signature(signature, unsigned_msg).map_err(|e| E!(ProgramError::MissingRequiredSignature; "Error={:?}", e))?;
check_ethereum_authority(
Expand All @@ -258,6 +260,7 @@ fn process_instruction<'a>(
let sysvar_info = find_sysvar_info(accounts)?;

let trx: UnsignedTransaction = rlp::decode(unsigned_msg).map_err(|e| E!(ProgramError::InvalidInstructionData; "DecoderError={:?}", e))?;
StorageAccount::check_for_blocked_accounts(program_id, accounts)?;
let mut account_storage = ProgramAccountStorage::new(program_id, accounts)?;

check_secp256k1_instruction(sysvar_info, unsigned_msg.len(), 1_u16)?;
Expand All @@ -282,6 +285,7 @@ fn process_instruction<'a>(
let trx: UnsignedTransaction = rlp::decode(unsigned_msg).map_err(|e| E!(ProgramError::InvalidInstructionData; "DecoderError={:?}", e))?;

let mut storage = StorageAccount::new(storage_info, accounts, caller, trx.nonce)?;
StorageAccount::check_for_blocked_accounts(program_id, &accounts[1..])?;
let account_storage = ProgramAccountStorage::new(program_id, &accounts[1..])?;

check_secp256k1_instruction(sysvar_info, unsigned_msg.len(), 9_u16)?;
Expand Down
13 changes: 13 additions & 0 deletions evm_loader/program/src/storage_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ impl<'a> StorageAccount<'a> {
}
}

pub fn check_for_blocked_accounts(program_id: &Pubkey, accounts: &[AccountInfo]) -> Result<(), ProgramError> {
for account_info in accounts.iter().filter(|a| a.owner == program_id) {
let data = account_info.try_borrow_data()?;
if let AccountData::Account(account) = AccountData::unpack(&data)? {
if account.blocked.is_some() {
return Err!(ProgramError::InvalidAccountData; "trying to execute transaction on blocked account {}", account_info.key);
}
}
}

Ok(())
}

pub fn unblock_accounts_and_destroy(self, program_id: &Pubkey, accounts: &[AccountInfo]) -> Result<(), ProgramError> {
for account_info in accounts.iter().filter(|a| a.owner == program_id) {
let mut data = account_info.try_borrow_mut_data()?;
Expand Down
42 changes: 41 additions & 1 deletion evm_loader/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_caseFailAfterCancel(self):
result = self.call_begin(storage, 10, msg, instruction)
result = self.call_continue(storage, 10)
result = self.call_cancel(storage)

err = "custom program error: 0x1"
with self.assertRaisesRegex(Exception,err):
result = self.call_continue(storage, 10)
Expand All @@ -360,5 +360,45 @@ def test_caseSuccessRunOtherTransactionAfterCancel(self):
self.call_partial_signed(input)


def test_caseFailOnBlockedWithOtherStorageIterative(self):
func_name = abi.function_signature_to_4byte_selector('addReturn(uint8,uint8)')
input = (func_name + bytes.fromhex("%064x" % 0x1) + bytes.fromhex("%064x" % 0x1))

(from_addr, sign, msg) = self.get_call_parameters(input)
instruction = from_addr + sign + msg

storage = self.create_storage_account(sign[-8:].hex())

result = self.call_begin(storage, 10, msg, instruction)
result = self.call_continue(storage, 10)

err = "invalid account data for instruction"
with self.assertRaisesRegex(Exception,err):
result = self.call_partial_signed(input)
print(result)

result = self.call_cancel(storage)


def test_caseFailOnBlockedWithOtherStorageNonIterative(self):
func_name = abi.function_signature_to_4byte_selector('addReturn(uint8,uint8)')
input = (func_name + bytes.fromhex("%064x" % 0x1) + bytes.fromhex("%064x" % 0x1))

(from_addr, sign, msg) = self.get_call_parameters(input)
instruction = from_addr + sign + msg

storage = self.create_storage_account(sign[-8:].hex())

result = self.call_begin(storage, 10, msg, instruction)
result = self.call_continue(storage, 10)

err = "invalid account data for instruction"
with self.assertRaisesRegex(Exception,err):
result = self.call_signed(input)
print(result)

result = self.call_cancel(storage)


if __name__ == '__main__':
unittest.main()