studying – Inconsistent habits testing Taproot Workshop – Part: 0.2 Elliptic Curve Math

on

|

views

and

comments


Workshop hyperlink: https://github.com/bitcoinops/taproot-workshop/

Within the part 0.2.4 Programming Train: Distributivity of scalar operations we implement the next code:

a_key = ECKey().set(a)

b = random.randrange(1, SECP256K1_ORDER)
b_key = ECKey().set(b)

c = random.randrange(1, SECP256K1_ORDER)
c_key = ECKey().set(c)

# Left: Compute a - b as ints (modulo the sepc256k1 group order)
a_minus_b =  (a - b) % SECP256K1_ORDER# TODO: implement

# Left: Compute (a - b) * c as ints (modulo the sepc256k1 group order)
left =  (a_minus_b * c) % SECP256K1_ORDER# TODO: implement

# Proper: Compute a * c - b * c as ECKeys
proper = (a * c % SECP256K1_ORDER) - (b * c % SECP256K1_ORDER) # TODO: implement 
#should you dont modulo curve order in each parenthesis your quantity (in all probability) turns into too giant for the curve
#due to this fact calling .secret on it is not going to work even should you forged it to ECKey Object (so the assertion can't even occur on this case)
#you'd solely be capable to name .secret on a worth throughout the curve order

print("Left: {}".format(left))
print("Proper: {}".format(proper))


proper = ECKey().set(proper)
# Left/Proper: Assert equality
assert left == proper.secret
print("nSuccess!")

Observe that the traces with #TODO: implement are the one ones I’ve modified.

When attempting this code block a couple of instances I seen that it fails sometimes with:

Left: 84229569338898829804715923445734053841060795723920762893503652295039608159004
Proper: -31562519898417365618855061562953854011776768555154141489101510846478553335333
---------------------------------------------------------------------------
AttributeError                            Traceback (most up-to-date name final)
Cell In[32], line 28
     26 proper = ECKey().set(proper)
     27 # Left/Proper: Assert equality
---> 28 assert left == proper.secret
     29 print("nSuccess!")

AttributeError: 'ECKey' object has no attribute 'secret'

The attribute error means that the generated secret is exterior the curve order and was not correctly was the ECKey

However for not less than 50% of the time it returns one thing like:

Left: 51082417157028894624564857296082907029625179491897309339882235219613900809295
Proper: 51082417157028894624564857296082907029625179491897309339882235219613900809295

Success!

What’s inflicting this inconsistency?

Share this
Tags

Must-read

US regulators open inquiry into Waymo self-driving automobile that struck youngster in California | Expertise

The US’s federal transportation regulator stated Thursday it had opened an investigation after a Waymo self-driving car struck a toddler close to an...

US robotaxis bear coaching for London’s quirks earlier than deliberate rollout this yr | London

American robotaxis as a consequence of be unleashed on London’s streets earlier than the tip of the yr have been quietly present process...

Nvidia CEO reveals new ‘reasoning’ AI tech for self-driving vehicles | Nvidia

The billionaire boss of the chipmaker Nvidia, Jensen Huang, has unveiled new AI know-how that he says will assist self-driving vehicles assume like...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here