/ test / Circuit / ExtractBits.hs
ExtractBits.hs
 1  
 2  module Circuit.ExtractBits where
 3  
 4  --------------------------------------------------------------------------------
 5  
 6  import CircuitCommon
 7  
 8  --------------------------------------------------------------------------------
 9  -- global parameters
10  
11  circomFile :: FilePath
12  circomFile = circuitLibSourceDir </> "extract_bits.circom"
13  
14  -- | extracting the lowest @n@-bit of the canonical representation of a field element
15  type GP = Int
16  
17  mainComponent :: GP -> MainComponent
18  mainComponent n = MainComponent 
19    { _templateName   = "ExtractLowerBits_testfield65537"
20    , _templateParams = [n]
21    , _publicInputs   = ["inp"]
22    }
23  
24  --------------------------------------------------------------------------------
25  -- test cases and expected semantics
26  
27  type TestCase = Integer
28  type Output   = Int
29  
30  semantics :: GP -> TestCase -> Expected Output
31  semantics n a = Expecting $ fromInteger (mod a (2^n))
32  
33  testCases :: GP -> [TestCase]
34  testCases n = [0..20]
35  --testCases n =  [   a | a<-[0..2^(n+3)+7] ] 
36  --            ++ [ - a | a<-[1..2^(n+3)+7] ] 
37  
38  --------------------------------------------------------------------------------
39  -- inputs and outputs
40  
41  inputs :: GP -> TestCase -> Inputs Name Integer
42  inputs n a = Inputs $ toMapping "inp" a
43  
44  outputs :: Output -> Outputs Name Integer
45  outputs y = Outputs $ toMapping "out" y
46  
47  --------------------------------------------------------------------------------
48  
49  spec :: GP -> TestSpec TestCase Output
50  spec n = TestSpec circomFile (mainComponent n) (inputs n) outputs (semantics n) (testCases n)
51  
52  specs :: [ ( GP, TestSpec TestCase Output) ]
53  specs = [ (n, spec n) | n <- [2,3,4,5] ]
54  
55  --------------------------------------------------------------------------------
56