You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The group-size could be updated to use the detect_missing_tx_field_validations
"""Detector for finding execution paths missing GroupSize check."""fromtypingimportList, TYPE_CHECKINGfromfunctoolsimportlru_cachefromtealer.detectors.abstract_detectorimport (
AbstractDetector,
DetectorClassification,
DetectorType,
)
fromtealer.teal.basic_blocksimportBasicBlockfromtealer.teal.instructions.instructionsimport (
Gtxn,
Gtxna,
Gtxnas,
Gtxns,
Gtxnsa,
Gtxnsas,
)
fromtealer.teal.tealimportTealfromtealer.utils.algorand_constantsimportMAX_GROUP_SIZEfromtealer.utils.analysesimportis_int_push_insfromtealer.analyses.utils.stack_ast_builderimportconstruct_stack_ast, UnknownStackValuefromtealer.detectors.utilsimport (
detect_missing_tx_field_validations,
detector_terminal_description
)
ifTYPE_CHECKING:
fromtealer.utils.outputimportSupportedOutputfromtealer.teal.instructions.instructionsimportInstructionfromtealer.teal.context.block_transaction_contextimportBlockTransactionContextclassMissingGroupSize(AbstractDetector): # pylint: disable=too-few-public-methods# ...@lru_cache(maxsize=None)@staticmethoddef_accessed_using_absolute_index(bb: BasicBlock) ->bool:
"""Return True if a instruction in bb access a field using absolute index a. gtxn t f, gtxna t f i, gtxnas t f, b. gtxns f, gtxnsa f i, gtxnsas f Instructions in (a) take transaction index as a immediate argument. Return True if bb contains any one of those instructions. Instructions in (b) take transaction index from the stack. `gtxns f` and `gtxnsa f i` take only one argument and it is the transaction index. `gtxnsas f` takes two arguments and transaction index is the first argument. Return True if the transaction index is pushed by an int instruction. """stack_gtxns_ins: List["Instruction"] = []
forinsinbb.instructions:
ifisinstance(ins, (Gtxn, Gtxna, Gtxnas)):
returnTrueifisinstance(ins, (Gtxns, Gtxnsa, Gtxnsas)):
stack_gtxns_ins.append(ins)
ifnotstack_gtxns_ins:
returnFalseast_values=construct_stack_ast(bb)
forinsinstack_gtxns_ins:
index_value=ast_values[ins].args[0]
ifisinstance(index_value, UnknownStackValue):
continueis_int, _=is_int_push_ins(index_value.instruction)
ifis_int:
returnTruereturnFalsedefdetect(self) ->"SupportedOutput":
"""Detect execution paths with missing GroupSize check. Returns: ExecutionPaths instance containing the list of vulnerable execution paths along with name, check, impact, confidence and other detector information. """defchecks_group_size(block_ctx: "BlockTransactionContext") ->bool:
# return True if group-size is checked in the path# otherwise return FalsereturnMAX_GROUP_SIZEnotinblock_ctx.group_sizespaths_without_check: List[List[BasicBlock]] =detect_missing_tx_field_validations(
self.teal.bbs[0], checks_group_size
)
# paths_without_check contain all the execution paths not checking the GroupSize# Only report paths which also use absolute_indexpaths_to_report: List[List[BasicBlock]] = []
forpathinpaths_without_check:
forbbinpath:
ifself._accessed_using_absolute_index(bb):
paths_to_report.append(path)
breakdescription=detector_terminal_description(self)
filename="missing_group_size"results=self.generate_result(paths_to_report, description, filename)
construct_stack_ast.cache_clear()
returnresults
The text was updated successfully, but these errors were encountered:
detect_missing_tx_field_validations
andsearch_paths
already address the issues with the generation of execution paths.tealer/tealer/detectors/utils.py
Lines 51 to 229 in c590caa
group-size
detector implements a function to generate execution paths. This function does not address the recently uncovered issues.tealer/tealer/detectors/groupsize.py
Lines 119 to 164 in c590caa
The
group-size
could be updated to use thedetect_missing_tx_field_validations
The text was updated successfully, but these errors were encountered: