Skip to content

Commit

Permalink
Add validation for total account lamports
Browse files Browse the repository at this point in the history
  • Loading branch information
mjain-jump committed Apr 12, 2024
1 parent 085447f commit 9626f0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute_single_instruction(
),
):
_, instruction_context = generate_test_case(file)
assert instruction_context is not None, f"Unable to read {file.name}"
assert instruction_context is not None, f"Unable to read/validate {file.name}"

# Initialize output buffers and shared library
initialize_process_output_buffers(randomize_output_buffer=randomize_output_buffer)
Expand Down Expand Up @@ -81,7 +81,7 @@ def debug_instruction(

# Decode the file and pass it into GDB
_, instruction_context = generate_test_case(file)
assert instruction_context is not None, f"Unable to read {file.name}"
assert instruction_context is not None, f"Unable to read/validate {file.name}"
debug_host(shared_library, instruction_context, gdb=debugger)


Expand Down
14 changes: 14 additions & 0 deletions src/test_suite/validation_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import test_suite.invoke_pb2 as pb


ULONG_MAX = 18446744073709551615


def is_valid(instruction_context: pb.InstrContext) -> bool:
"""
Checks whether an instruction context message is valid.
Expand All @@ -20,4 +23,15 @@ def is_valid(instruction_context: pb.InstrContext) -> bool:
if not account.address or len(account.address) != 32:
return False

# Sum of lamports should not exceed ulong max value
total_lamports = 0
for instruction_account in instruction_context.instr_accounts:
account_lamports = instruction_context.accounts[
instruction_account.index
].lamports
total_lamports += account_lamports

if total_lamports > ULONG_MAX:
return False

return instruction_context.data and instruction_context.instr_accounts

0 comments on commit 9626f0e

Please sign in to comment.