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

Audit preparedness: assessing key cases #5361

Open
4 tasks
Tracked by #5173
michaeljklein opened this issue Jun 28, 2024 · 1 comment
Open
4 tasks
Tracked by #5173

Audit preparedness: assessing key cases #5361

michaeljklein opened this issue Jun 28, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@michaeljklein
Copy link
Contributor

michaeljklein commented Jun 28, 2024

Problem

Given listing from: #5360

Happy Case

Add the lists of tests to the omnibus issue for implementation

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the enhancement New feature or request label Jun 28, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 28, 2024
@michaeljklein michaeljklein self-assigned this Jun 28, 2024
@michaeljklein
Copy link
Contributor Author

michaeljklein commented Jul 3, 2024

Assorted TODO's:

  • Make dummy-ID for (monomorphizer) FuncId (other than 0)
  • Make monomorphizer AST's Program::take_function_body error when called twice on the same function (FuncId)

Places to Test

Top-level Groups

  • Binary
  • Arithmetic
  • Crypto
  • Memory access
  • Arrays/slices
  • Semantic (EnableSideEffects, IsUnconstrained, etc)
  • Other
// acvm-repo/acir/src/circuit/opcodes.rs
pub enum Opcode<F> {
  • AssertZero(Expression<F>): Test on different expression types
  • BlackBoxFuncCall(BlackBoxFuncCall)
  • Directive(Directive<F>)
  • MemoryOp { op: MemOp<F>, .. }: Read/write memory test
  • MemoryInit { .. }: Ensure all initialized memory actually initialized and is required for memory operations
  • BrilligCall { .. }
  • Call { .. }
// ssa/ir/instruction.rs
pub(crate) enum Intrinsic {
  • ArrayLen

  • AsSlice: good coverage

  • SlicePushBack

  • SlicePushFront

  • SlicePopBack

  • SlicePopFront

  • SliceInsert

  • SliceRemove

  • AssertConstant: good coverage

  • StaticAssert: good coverage

  • ApplyRangeConstraint

  • AsWitness

  • IsUnconstrained

  • DerivePedersenGenerators

  • StrAsBytes

  • ToBits(Endian)

  • ToRadix(Endian)

  • BlackBox(BlackBoxFunc)

  • FromField: isomorphism with AsField

  • AsField

// ssa/ir/instruction.rs
pub(crate) enum Instruction {
  • Binary(Binary): See Binary enum below

  • Cast(ValueId, Type): test that it's effectively a no-op when allowed / ensure unsafe casts disallowed

  • Not(ValueId): not ONES == ZEROES; not ZEROES == ONES; not (not x) == x; not x != x

  • Truncate { value: ValueId, bit_size: u32, max_bit_size: u32 }: ensure result has expected max_bit_size

  • Constrain(ValueId, ValueId, Option<ConstrainError>): sanity-check successful/failing cases

  • RangeCheck { value: ValueId, max_bit_size: u32, assert_message: Option<String> }: sanity-check successful/failing cases

  • Allocate: 1) ensure an allocation happens, 2) check that an Allocate is required to Load/Store

  • Load { address: ValueId }: Load/store random-access memory test.
    For all logs of (Read(Index) | Write(Index, Value)),
    all reads return the Value of the last Write to that Index,
    otherwise the default value if there is no last Write.

  • Store { address: ValueId, value: ValueId }: see Load

  • ArrayGet { array: ValueId, index: ValueId }: get/set random-access memory test

  • ArraySet { array: ValueId, index: ValueId, value: ValueId, mutable: bool }: see ArraySet

  • IncrementRc { value: ValueId }: 1) ensure Brillig RC is incremented, 2) ensure no-op in ACIR

  • DecrementRc { value: ValueId }: 1) ensure Brillig RC is decremented, 2) ensure no-op in ACIR

  • EnableSideEffects { condition: ValueId }: ensure it enables/disables side effects in affected block

  • Call { func: ValueId, arguments: Vec<ValueId> }: ensure call to failing function fails

  • IfElse { then_condition: ValueId, then_value: ValueId, else_condition: ValueId, else_value: ValueId }:

    1. ensure that else_condition == !then_condition
    2. ensure only the passing branch is executed.
      Use a) always-failing asserts, b) mutable array setting
// "kind" in binary::Binary (op)
pub(crate) enum BinaryOp {
  • Sanity-check that behavior of these match for example inputs 0..8 (or are None): get_field_function, get_u128_function, get_i128_function

Automorphisms:

  • Test associativity

  • Test (anti-)commutativity

  • Test identity

  • Add

  • Sub

  • Mul

  • Div

  • Mod

  • And

  • Or

  • Xor

  • Shl

  • Shr

Comparisons:

  • Test (anti-)reflexivity
  • Test transitivity
  • Test (anti-)commutativity
  • Eq
  • Lt
pub enum Directive<F> {
  • ToLeRadix
pub enum BlackBoxFunc {
  • AES128Encrypt

  • SHA256

  • Blake2s

  • Blake3

  • SchnorrVerify

  • PedersenCommitment

  • PedersenHash

  • EcdsaSecp256k1

  • EcdsaSecp256r1

  • Keccak256

  • Keccakf1600

  • Poseidon2Permutation

  • Sha256Compression

  • RecursiveAggregation

  • AND

  • XOR

  • RANGE

  • MultiScalarMul

  • EmbeddedCurveAdd

  • BigIntAdd

  • BigIntSub

  • BigIntMul

  • BigIntDiv

  • BigIntFromLeBytes

  • BigIntToLeBytes

acir-gen Cases:

  • Ssa::into_acir(self, brillig: &Brillig)
  • convert_acir_main
  • convert_brillig_main
  • convert_ssa_block_params (test against behavior from docstring)
  • add_numeric_input_var (check range constraint)
  • handle_constant_index (ensure equivalent to when not used / slow-version of adding a constant, constraining to equivalent with var, etc. see docstring)
  • handle_array_operation get/set
  • convert_array_operation_inputs (test with a couple types of nesting / included tuples/struct-types)
  • array_get / array_set (get gets last set value)
  • array_get_value / array_set_value (get gets last set value)
  • init_element_type_sizes_array (check_array_is_initialized on result)
  • copy_dynamic_array (check_array_is_initialized on result)
  • initialize_array (check_array_is_initialized on result)
  • flattened_slice_size / flattened_value_size (various nesting)
  • convert_ssa_binary (test expected operation occurs)
  • check_unsigned_overflow (1. test key successful/failing cases, 2. ensure non-tested operations cannot exceed size) ((consider adding a bool argument to unconditionally range-constrain var, then test that both versions are equivalent))
  • type_of_binary_operation (see docstring for cases)
  • convert_ssa_intrinsic_call
  • array_element_type (test docstring properties)

SSA Passes:

  • Ssa::defunctionalize
  • Ssa::remove_paired_rc
  • Ssa::separate_runtime
  • Ssa::resolve_is_unconstrained
  • Ssa::inline_functions
  • Ssa::mem2reg
  • Ssa::as_slice_optimization
  • Ssa::evaluate_static_assert_and_assert_constant
  • Ssa::unroll_loops_iteratively
  • Ssa::simplify_cfg
  • Ssa::flatten_cfg
  • Ssa::remove_bit_shifts
  • Ssa::mem2reg
  • Ssa::inline_functions_with_no_predicates
  • Ssa::remove_if_else
  • Ssa::fold_constants
  • Ssa::remove_enable_side_effects
  • Ssa::fold_constants_using_constraints
  • Ssa::dead_instruction_elimination
  • Ssa::array_set_optimization

Monomorphizer:

  • constructor
  • unpack_pattern / unpack_tuple_pattern (ensure they convert key examples to expected accesses)
  • resolve_trait_method_reference (ensure it handles assumed traits)
  • function_call
  • try_evaluate_call
  • try_evaluate_call: "modulus_num_bits"
  • try_evaluate_call: "zeroed"
  • try_evaluate_call: "modulus_le_bits"
  • try_evaluate_call: "modulus_be_bits"
  • try_evaluate_call: "modulus_be_bytes"
  • try_evaluate_call: "modulus_le_bytes"
  • lambda_with_setup (test key cases of zero/trivial/two-var env, as well as 2-3 lambdas in a row / nested)
  • zeroed_value_of_type: sanity-check that result is all-zero, ensure it's constant
  • create_zeroed_function: ensure it behaves as described in docstring
  • perform_instantiation_bindings
  • undo_instantiation_bindings (ensure it reverses the effect of perform_instantiation_bindings)

github-merge-queue bot pushed a commit that referenced this issue Aug 26, 2024
#5421)

# Description

## Problem\*

Small issues or typos encountered during
#5361

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Maxim Vezenov <[email protected]>
Co-authored-by: jfecher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant