aszepieniec / stark-anatomy

Tutorial for STARKs with supporting code in python
Apache License 2.0
181 stars 49 forks source link

The generator and primitive _nth_root #12

Closed Federico2014 closed 1 year ago

Federico2014 commented 1 year ago

I have a question about the generator and primitive _nth_root, it says the code also needs to supply the user with a generator for the entire multiplicative group, What is the entire multiplicative group, is it Fp? If the root is the generator of Fp, how to derive the primitive_nth_root? why is the 407 omitted in the primitive_nth_root function? Can you tell me, thanks

  def generator( self ):
        assert(self.p == 1 + 407 * ( 1 << 119 )), "Do not know generator for other fields beyond 1+407*2^119"
        return FieldElement(85408008396924667383611388730472331217, self)

    def primitive_nth_root( self, n ):
        if self.p == 1 + 407 * ( 1 << 119 ):
            assert(n <= 1 << 119 and (n & (n-1)) == 0), "Field does not have nth root of unity where n > 2^119 or not power of two."
            root = FieldElement(85408008396924667383611388730472331217, self)
            order = 1 << 119
            while order != n:
                root = root^2
                order = order/2
            return root
        else:
            assert(False), "Unknown field, can't return root of unity."
aszepieniec commented 1 year ago

The entire multiplicative group is $\mathbb{F}_p^ = \mathbb{F}_p \backslash \lbrace 0 \rbrace$. A generator for it is a single element $g$ such that $\langle g \rangle = \lbrace g^i | i \in \mathbb{Z} \rbrace = \mathbb{F}_p^$. The order of $g$ is always $p-1$ so in fact it is also correct to say $\langle g \rangle = \lbrace g^i | 0 \leq i < p-1 \rbrace$ because the powers of $g$ outside this range fold onto powers of $g$ inside this range.

The function generator returns not a generator for the entire multiplicative group but only for the subgroup of order $2^{119}$.

Federico2014 commented 1 year ago

Ok, I see, thanks so much. It makes me quite confused when I read it the first time.