Programming Bitcoin: Chapter 2

Recorded: Jan. 22, 2024 Duration: 2:00:15

Player

Snippets

It's not going to get used.
It's not going to get used.
It's not going to get used.
It's not going to get used.
It's not going to get used.
It's not going to get used.
It's not going to get used.
It's not going to get used.
Hey everybody and welcome to Chapter 2 of Programming Bitcoin.
So while we're waiting for our co-host Portland Hoddle to join, make sure that you get everything
ready for today's lesson.
So you're going to have your book open and your Jupiter notebook running and you're also
going to have Portland slides open as well that he made for us for today and those are up
in the nest.
Here's Portland.
And I have added him as a co-host.
Hey Portland.
Please accept the co-host position.
Good evening.
Hey G.E.G.E.
Good evening.
Good evening.
I heard we're talking about elliptical curves today.
We are elliptical curves baby.
That reminds me of that, what is that cardio machine that used to be really popular?
I don't know if people still do that.
I always think of that elliptical machine thing whenever people talk about elliptical
Oh, the Peloton body?
At the gym.
At the gym, you know, it's like next to the cardio and it was popular for a while.
So yeah, we're talking about elliptic curve, not cryptography, but we're talking about building
blocks that we will use to build elliptic curve cryptography.
So next week we're going to talk about cryptography, but this week we're just talking
about these curves.
So I definitely had to brush up on a lot of math that I have not used since high school
and college.
Like I haven't really thought about derivatives or calculus or any of this in a very, very,
very long time.
How about you Portland?
When was the last time that you used derivatives?
Last time I used derivatives, I like actually went through and like did your d over dx style
equation or?
I mean, for me it hasn't, for me it hasn't been since college.
It's been since college as well.
I'm pretty sure like I've done derivatives implicitly in code before, like, oh, the rate
of change of this, but I haven't actually sat down and like done the equation other
than sometimes we'll have Wolfram alpha or another service do it for me, which I'm
sorry to say, yeah, I can still do them.
And the nice part was doing this chapter, the actually a lot of it seemed to come back
pretty easy.
And then also if Jimmy Song mentions in chapter two that you don't actually have to know
the calculus or derivatives to do this stuff.
And the reason why is because he doesn't that kind of an interesting way.
He actually gives you the solution to the entire equation first and then he'll go
into the proof afterwards.
So you can he'll show you like, OK, this is how to get the slope at this point.
And he'll just like literally give you the derived formula for that.
And that's really nice because that means you can just put it right into code without
having to do that higher level mathematics.
But at the same time, he does go through down below that section and he literally goes
through the entire proof of how you get the slope and how you kind of find that
third point on the curve.
Yeah, so I think for me, like.
I've been studying this topic for a while and I already knew about elliptic curves and how
to do point addition, but there are a few things that I never really understood until
I went through this chapter.
And so one of the things I never understood was why you flip the result over the
freaking y axis, the flipping.
I just always thought, OK, we do this thing.
No earthly idea why I just got to accept it as a fact of life.
And now I understand the flipping and I'm so happy, so, so, so happy.
So let's just kind of go over just a very brief overview of what we're going to be
talking about today, elliptic curves.
So elliptic curves are curves that follow the equation y squared equals x cubed plus
a x plus b where a and b are constants.
Now, in the case of Bitcoin, those constants are going to be zero and seven
respectively. So we're going to talk about elliptic curves.
We can graph them.
We can look at them.
We can plot points onto the curve.
But what we actually want to do today is define math operations on points on this
curve. And so what I said last week when we talked about finite fields and when we
defined math operators across finite fields was imagine that you just took
acid and you landed in Wonderland and up is down and down is up and left is right
and right is left.
And math is different.
It's a little strange.
It's not exactly the math that you learned as a kid.
It's not necessarily super hard math.
It's just kind of weird.
And so when we define addition over elliptic curves, it's not regular addition.
Like we do with regular numbers, it's point addition.
And so it's kind of like we're doing addition in Wonderland.
It's made up math that works for elliptic curves.
But again, it's just made up to work on elliptic curves.
It's not regular, real addition.
It's addition such that we have some of the properties that we're used to addition
having. And we'll talk about those, the identity property, the communitivity
property, the associativity property, the invertibility property.
But again, it's like it's like a duck, like it kind of looks like a duck.
It kind of quacks like a duck.
It kind of has duck feathers, but it's not it's not a duck that we're used to.
This duck is like it has weird technicolor feathers because we're on acid
and we're in Wonderland and the duck is ducking, but it's a weird, a weird duck.
So we're going to define addition in particular.
And addition has these kind of funny corner cases where, you know, in most cases,
you're adding two points together and we have a formula that gives us,
for all intents and purposes, that weird addition that we're trying to define.
But then there's a few exceptions, things we got to look out for that are
corner cases where we might have a few things we need to define specifically.
So that said, what I suggested to everybody for today
was that you actually go through the chapter before the lecture.
And for anyone that did that right on, like congrats to you,
because you're going to get so much more from today if you've already read the chapter.
If you haven't already read the chapter, just be sure to read it before next Sunday
when we delve into elliptic curve cryptography, which is going to be really cool.
You're going to finally see, oh, this is why we're learning all this weird math.
This is why we learned finite fields.
This is why we learned elliptic curves.
We're pulling it all together to do something really extraordinary with it.
So that said, I'm leaving these episodes up on Twitter for a limited time only.
I'm not going to let them persist, but I'm giving you like about a week or so
to review the lectures or if you can't make it for whatever reason,
if you're not in the same time zone or country as us,
you have a few days to catch up, but they're not going to be left up.
So make sure that you are as up to date as possible.
You'll have about a week or so to get caught up.
So yeah, huge like pat on the back to everybody that has gone through the chapter.
They've gone through the Jupyter Notebook.
And after we talk about elliptic curves, we're going to take questions
and be sure to ask questions.
If you have any questions with Jupyter Notebook or Git or GitHub
or any of the DevOps stuff or anything at all,
be sure to ask those questions so you don't fall behind.
So yeah, Portland, what do you think about this chapter just kind of overall?
Like would you agree that it is a weird flavor of math that is similar
but certainly not the same to what we're used to?
Yeah, so the interesting thing about the math applied in this chapter
is normally when you add points together.
For example, you have like a slope and you add these two
or so you have two points, you make a slope out of it.
You can just kind of like add things together directly.
And because you're doing math on a curve and everything has to exist on a curve,
the result must be on the curve.
Suddenly, you have to kind of skew what you define as addition, right?
And so addition no longer is just like any two points on the XY.
It's a point on this curve that is in the XY space
that satisfies the condition of the curve.
And so you kind of have to wrap your head around that.
And then what comes along with that is along with the operation of just purely addition,
it's what all these...
Well, I don't mean this in a bad way,
but like there are a couple of corner cases that you got to deal with.
And one of them, for example, you'll see at the end,
the answer is literally just hard code it.
Like literally just make a just return the infinity.
That's all you do.
But yeah, so you have to kind of like to make this math work in a special way,
and that's what this chapter is all about.
So yeah, it was a really excellent way to really make your mind work.
It took a second, but once I started getting into it,
I was like, all this makes perfect sense.
And the diagrams and basically graphics Jimmy Song uses,
especially there's one in the middle that shows the associative property.
And that one right there, like just watching like picture one and picture two,
like if you get anything from this chapter,
those are the two pictures, just like look at those until your brain gets it.
And once your brain gets that, boom, like the whole thing makes sense.
Because if you just follow it, like in a linear order,
you'll get to that point where Jimmy Song starts defining addition.
And he's like, okay, so you just add the two things together
and you find like the slope and it ends up at a point on the curve.
Okay, great.
And then you just like take that thing and then you just flip it.
You just invert it along the X axis or Y axis.
And then that's just how it is.
I'll tell you later.
But once you go through those diagrams, it makes it very clear
that that's exactly why you take that resultant and then you flip it.
So the flipping is probably one of the more important things
you can get out of this chapter.
So that diagram with the flipping are my own opinion, probably the big ones.
Yeah, I agree.
The flipping for me was the mind equals blown moment of, oh my gosh,
I love those aha moments for myself.
They're so joyful and so exciting.
So one thing I will say is that we did this weird type of math over finite fields.
We're about to do some weird math with elliptic curves,
but we're doing elliptic curves today over an infinite plane.
That curve, right?
It stretches out to infinity in every direction.
So what's going to be fun next week is to combine finite fields and elliptic curves
to define an elliptic curve over a finite field.
Won't that be so fun?
So that all said, we have these equations.
We have Y squared equals X cubed plus AX plus B.
And you can pop that bad boy onto a graph and then you can plot points onto that graph.
So, okay, pretty easy.
But when you want to start doing things like add point A to point B,
how can you define point addition with elliptic curves?
So the bottom line is we want addition to have some certain properties.
Like we described, one of those properties is going to be the commutative property of
addition.
And we learned this when we were little kids where A plus B is the same as B plus A.
Okay, that's important.
So we want to make sure that when we add two points,
we get the same result when we add A plus B and B plus A.
We want to make sure that we have the rule of associativity.
And what that means is when we're adding three points together, let's say A, B, and C,
we want to make sure that the order in which we add those points does not change the result.
In other words, we want A plus B plus C to have the same answer as if we were to add B
plus C plus A, whereby we added the B plus C part first.
And of course, we know with regular numbers, one plus two plus three is the same as
two plus three plus one.
We want to make sure that's the same also for points on an elliptic curve.
And so in order to make all of these properties fit,
we are going to define what we call point addition across elliptic curves.
But like I said before, we're just making this up.
Some guy just made this up.
Some guy was just like, okay, there's this elliptic curve.
I'm going to define what I'm calling addition.
But you're suspending your disbelief a little bit because it's not
the regular addition that we learned when we were little kids.
So we have these curves.
We have some points on the curve.
We want to define A plus B, whereby A and B are two different points.
So let's start with the case whereby A and B are not the same points on the curve.
So how do we define point addition?
Well, we take point A and point B, and we just draw a straight line through those points.
And so this brought me back to pre-algebra.
So Portland, do you remember when we were little kids,
how we learned to find a straight line between two points?
There was a slope equation because we're finding what we're calling the slope
of the line between two points.
Do you remember learning that when you were a kid?
Well, I barely remember.
I have to brush up on all of this.
But when we were kids, we learned that we had two points.
And those points have coordinates, right, x, y, and then x2, y2.
So all you do is you just take those coordinates and you subtract them.
So y2 minus y1 divided by x2 minus x1, that gives you the slope of the line.
And from there, you have a straight line.
And you find where that straight line intersects in a third point on the elliptic curve.
All right?
So that's going to give you a third point.
Now, here's where it gets even stranger.
You take that point, and because elliptic curves are symmetrical over the y-axis,
meaning for any one given x-coordinate, you're going to have a positive and a negative y.
So you're going to invert that third point over the y-axis.
So if the third point that intersects with the slope that you just calculated is positive,
you're going to invert it to make it negative.
If it happens to be negative, you're going to invert it to make it positive.
And for as long as I've known anything about elliptic curves, I've known this to be true,
but I just accepted it as some detail that I couldn't fully explain why was the case.
I just knew that we did it.
And today, I finally actually learned for the first time why we invert that point.
So should we talk about why we invert that point?
Well, here's why we invert that point.
The reason we invert that point is we want the commutative property of addition
and the associativity property of addition to hold true for point addition.
Now, if we didn't invert that point over the y-axis, what would happen?
A plus B plus C would not equal B plus C plus A.
Those would be two completely different points on the curve
that would have no real relation to one another.
They wouldn't be anywhere near one another at all.
So that property of associativity would have been broken.
And if we don't want that property to be broken,
we have to invert the point over the y-axis.
So what I would suggest you all do is take three points, A plus B plus C.
Go through what it would look like to add A plus B plus C
without inverting the point.
See where that lands.
And then add B plus C plus A and see where that lands.
Just go through that exercise on your own
and see how far off those two points are.
See how they are nowhere near one another.
Now go through the same process whereby you invert the result
and see just like magic how they're the same freaking point,
which is to say that rule of associativity has not been broken.
And like Portland said, the flippening,
this has been the most exciting point for me
in my journey of understanding elliptic curves.
Anything to add?
Oh, Portland actually is not on stage.
I've been asking him questions and he hasn't been responding
and that would explain why he's not responding.
So Portland, I requested you to come back up and co-host.
Hey, Portland, anything to add about what we've said so far about point addition?
Any points you'd like to make?
Yes, points I'd like to make is there's kind of a few simple things
I wanted to bring up.
And one is how did the curve end up being mirrored
along the basically x-axis, right? Or the y-axis.
So that, and the reason why it's flipped
is because of the fact that the first part of it is y-squared.
So it's not a cubic equation.
It's very similar.
But as soon as you put that y-squared in front,
it suddenly becomes symmetrical across itself.
So that is one really nice property.
And then the second thing I thought that was pretty interesting
about this kind of math was the addition is nonlinear.
So as you're like adding points, sometimes like the point
can be further out.
It can be like adding two together.
It'll be far out.
And then sometimes you'll add two points
and it'll be in between them.
Yeah, it's just interesting to see how it's just not,
it's nonlinear in terms of the way.
So when you, yeah, when you say nonlinear,
what that means is you have two points
and it's kind of just from looking at those points,
it's pretty hard to determine where the result
of the addition is going to be.
They could kind of be almost anywhere on the graph,
given two points on the curve,
the results of the addition of those two points.
And I think this to me really foreshadows
why we're going to be using elliptic curves in Bitcoin.
To me this is foreshadowing why elliptic curves
are being used for cryptography
because it's hard to predict
where these operations are going to take us.
Those are the only two things.
There are some other points as well in terms of the property.
There's the inversibility property.
Did we go over that yet?
Or are we going to?
We haven't.
And so when I said that you're going to be taking acid
and going to Wonderland, this is what I mean.
So addition's not addition.
Up isn't up.
Down isn't down.
Zero is not zero.
Zero is the quote, point at infinity.
And this is where you get that invertibility property.
So this was something that I never really fully understood.
I always just thought it was a strange thing
that cryptographers would say about elliptic curve math.
That you have zero on this graph somewhere
but it's the point of infinity.
I never really truly understood what that means.
But I would say my working understanding
of the point at infinity
is that it's a point on the graph
that you can't really see.
And you're kind of just imagining
that it's like way, way, way far kind of off the map somewhere.
How do you sort of visualize that point at infinity
or that identity point or that zero point?
I just associate it as zero.
In terms of its actual representation,
that's actually something I still struggle with.
What does it actually mean?
I see, for example, that it's used
and I know why it's used
but I still don't understand conceptually exactly what it is.
And I apologize for not putting that piece together.
Well, it's okay.
It's like we're in Wonderland and things are weird.
And so you kind of have to suspend your disbelief a little bit.
Okay, it's the zero point
but it's not really zero.
It's zero such that in regular math,
when you add zero to a number,
you get that same number back out of that equation.
And same here, correct?
22 plus zero is 22.
But this is a curve, right?
So we're not actually using zero.
We're finding some point such that a point on the curve
plus the quote identity point
will yield that same point on the curve, right?
Because any number plus zero should yield the same number.
But because we're having to suspend our disbelief
because we're in Wonderland,
because we took acid and things were strange,
it's not really zero.
It's the identity point or the point at infinity.
And so I've had to, again, suspend my disbelief
and just imagine that this point is just far away off somewhere
that I can't see.
And it's, again, just this corner case
that we're defining the properties of this point
that doesn't actually really even exist on the curve.
It's just kind of like in our code, for example,
we have some if else statements to define some weird edge cases.
I think the point at infinity is just going to be one of them.
It's just a weird, weird corner case.
And because you can't really define infinity in Python,
what we've done in the code is we've just set the point at infinity
to be none with a capital N.
Its x value is none.
Its y value is none.
And because this point isn't really a real point on the curve,
it's just this kind of strange construct,
this mental construct,
we always have to define those edge cases separately in the code.
We're always checking to see, like, is this the identity point?
And if it is, we're going to maybe do something
a little different with the result.
And we can check that in Python simply by saying,
is its x coordinate none?
Is its y coordinate none?
Oh, that's that weird point.
I didn't turn this point differently.
And if we're getting this weird point at infinity
or this identity point, well, if we're adding it to a point,
then we're just going to return that point.
You just hard code that.
You literally just hard code that into your program.
So can I ask a question?
Just because I want to hopefully cement my visualization
of the infinity point.
So I've been treating it as basically like a zero operator
for all intents and purposes.
Because that's kind of the way it works.
But visualizing it, where would this thing actually be on?
Like, would it be to the left side, to the right side?
Or where does this thing exist?
And how is it infinitely far out?
I don't know.
Yeah, that's a good question.
So I think when you add a point to another point,
that point, those points are on the curve, right?
So you're kind of imagining that the point is
on the curve somewhere.
But I'm just kind of imagining that it's like far off.
To where my eyes can't see.
So is this the infinity point per se?
Is it literally just a point created
or a part of the definition of what is elliptic curve math
to satisfy this condition?
Like it doesn't actually exist in any real form.
This is a construct that we've created
so that we can satisfy the conditions of this.
Okay, that makes more sense.
Yes, exactly.
That's why it's so freaking weird.
It's an extra point on the curve that satisfies these conditions,
but it's like imaginary.
Okay, thank you.
This is where the acid comes into play.
When I say it's imaginary,
I don't mean it's imaginary as in an imaginary number.
I mean, it's like we imagined it.
We're imagining it because we're in one.
It's a point with a bunch of interesting properties,
essentially.
It's different than all other points, essentially.
Because when you add it to anything,
you literally just take the other side
and just basically use that again.
You duplicate the point.
Okay, thank you.
Appreciate that.
Yeah, so we talked about this weird point at infinity,
which we sometimes call zero.
We sometimes call the identity point.
That satisfies the invertibility property of elliptic curves.
So that satisfies kind of two things here.
The identity, which is to say any number plus zero is itself,
as well as the invertibility property of addition.
So the point at identity were used
in a number of different places.
We talked about any number plus zero is itself,
but also any number plus the inverse of that number
should be zero, right?
So if I take negative two plus two, I should get zero.
If I take negative 10 plus 10, I should get zero.
If I take negative a million plus a million, I should get zero.
But in elliptic curve math,
if I were to add a point on the curve
plus its inverse on the curve,
and everything is flipped over that y-axis.
So for any given x,
there's going to be two points
with two different y-coordinates.
If I take those two points with the same x
and I add them together,
I want to get the identity point.
I want to get zero.
So I'm kind of imagining
that there's this point on the curve somewhere.
It's not actually there,
but we're kind of defining it as a corner case.
And in Python, we're just literally defining a case
whereby two points that have the same x
but different y's when you add them together,
you get that point at infinity.
And in Python, we're simply just defining
that point to have none,
just none as its x and none as its y.
So super weird,
but if we didn't define these corner cases,
we wouldn't be able to do the things
that we want our math to do.
We wouldn't be able to invert points
and have them yield the quote zero or identity point.
We wouldn't be able to add zero
or the identity point to a number
and get that number.
And there's other places
where I think we use the point at infinity as well.
So I think this part is one of the weirdest parts.
I think finding two points on the curve,
drawing a line through them,
finding where it intersects on the elliptic curve,
flipping that across the y-axis.
I don't think that part's that weird.
It's kind of weird.
Well, maybe I've just...
I think actually, if I go back a few years ago
to when I first learned this,
I thought it was really weird.
I think it's just become more normal to me
because I see it quite often.
But I do think that definitely
that identity point is super weird.
It's weird math.
So Portland, are you able to talk?
I think you switch your devices or something.
I think Portland's switching over his devices.
Okay, so we talked about point addition
and the different properties we want addition to have.
We can code that in Python.
And the way that we code that in Python
is first we define a point.
A point has an x-coordinate, a y-coordinate.
It also has an a and a b.
The a and a b are going to be the arguments
that define the elliptic curve itself, right?
Because y squared equals x cubed plus ax plus b.
So in other words, when we're adding points
on an elliptic curve,
we need to make sure that those two points
are on the same curve.
The points aren't on the same curve,
which is to say the a and b
of those two points aren't the same.
Guess what?
We can't add those points together.
We cannot define addition between two points
that are not on the same elliptic curve.
So if the points are not on the same curve,
we're just going to return an error, actually.
Just an error saying, hey, lady,
these points are not on the same curve.
I don't know how to add points
that aren't on the same curve.
Now, if the points are on the same curve
and they're not equal to one another,
then we have an equation that we can use.
I mentioned that we find these slope,
and let me add Portland back up
because he's kind of coming and going.
Hey, Portland, you're back.
I'm going to add you as a co-host.
Okay, so the first case that Jimmy Song defines
is point addition where the two points
do not have the same x-coordinate.
Because remember, we talked about
how if they have the same x-coordinate,
you have them together,
you get that weird identity point.
So we're going to come to that one later.
But we're first going to implement in Python
point addition where the x-coordinates are not the same.
And we're on the same curve.
You got to be on the same curve, okay?
So if those points are not the same,
he goes through what the formula is
for finding the results,
and then he derives that formula
and writes a proof,
proving that the formula
is in fact the correct formula to use.
So what do you think, Portland?
How should we delve into
like why this formula is selected?
Or should we just kind of do some hand waving
and say, just don't worry about it.
Just use this formula.
I think we can dive into it.
I think it's fine.
Absolutely.
I think we should start with
the easy portion first about it.
Kind of this is just the way you do it.
And then we can go into the actual why it works.
I think the easy part for me
was finding a slope.
Because I remember doing that as a kid.
Oh, yeah.
One second, bring up the slide.
And if you have your book open,
it's on page 35.
Sorry, my browser crashed.
I'm assuming where X1 is not equal to X2,
And finding that.
Because that's the first case
that we defined in our class
in Python for point addition.
So I figured we'd start there.
So essentially, it's just you're
taking Y2 minus Y1
over X2 minus X1.
The same thing you use
even in calculus for derivatives,
essentially, it's just a slope of a line.
And then from there,
you use a derived equation
that is explained in the proof down below
at how they arrive at that.
And you basically plug in the power squared
minus the X minus the other X as well.
So that is the second point's X.
And then you're able to solve for that X.
And then you plug it in to solve for Y
for step three.
Yeah, I think that is the simple form of it.
And then, yeah, they do have the proof as well.
I think just below that.
Yeah, so I think the first part,
the Y2 minus Y1 over X2 minus X1,
that's the slope of the line,
a straight line that you draw
across those two points.
So for any two points that you have,
elliptic curve or not,
there's always going to be a straight line
that intersects through both of them.
And we learned how to find the quote,
slope of that straight line
in pre-algebra when we were kids.
It's this S formula.
So we have the slope.
And then once we have the slope,
we can actually plug that equation
into the elliptic curve equation.
We can substitute X and Y
when we have the slope of the straight line
and plug that into the graph
for the elliptic curve line.
So why are we plugging the straight line
into the elliptic curved line?
Why are we doing that?
That's because we're looking for values of X and Y
that satisfy both equations.
Okay, we want to find all the points
that are true for both the straight line
and the elliptic curve line.
And we're actually going to get
more than one result.
There's not just going to be one X and Y
that satisfied both of those equations.
It's going to actually be three,
in most cases, not all cases,
but in most cases,
there's going to be three intersections.
Now, the cool thing is we already know
are two of the intersections, A and B.
We want to find the third set of X, Y coordinates.
That's the third intersection, C.
So because we have these equations
of the straight line and the curved line,
and because we have the first two sets
of X and Y coordinates
for the first two points,
we can plug those points into the equation as well
to get the third set of coordinates,
the third point.
And you can go through this proof
and you can see exactly why the formula is as it is.
And the formula ends up being pretty simple.
It's just the third point
on the intersection of those two lines
is going to be S squared,
which is the slope,
minus the first X
minus the second X.
The first X is point A.
The second X is the X for point B.
And then the third Y coordinate
is just going to be the slope
times the first X coordinate,
which is A minus X3.
That's actually the third X coordinate.
That's the new one for C
minus the first Y.
And so the equations are really simple.
And Jimmy Song goes through
where the equations come from.
So when I actually wrote this in Python,
it was just a really simple equation
that I could write.
And boom, it's bits out the result
of that point addition now.
And the point addition does take into it a fact
that we are inverting the result
over the Y axis as always.
Okay, so I don't know anything else to say about that.
I think it's pretty straightforward.
Yeah, I think in essence,
just I think the most important thing
to connect here is the actual mathematics,
which is what we just described
and how it relates to those lines
we just showed,
or are in the slides
or even in the book, right?
It's just when you draw
one of these things through,
you'll have three points
where it crosses.
You know two of the points
to make that line
and it'll cross the curve
three total times.
So you're just finding that last point
just as with addition,
where you have two things you know
and you're solving for a third.
Oh, I was talking.
I was talking to no.
I was talking to the point at infinity
way out there where no one could hear.
I was making you guys
contemplate the concept of infinity.
So what I was saying was very simply,
we just defined point addition
for the case whereby the two X coordinates
of the two points
that you're adding together
are not the same.
It's pretty straightforward.
There's other going to be cases
that we're going to also define.
So the next case
that I think we want to define
is going to be where we're adding
a point to itself.
And if you add a point to itself,
what that means is the X coordinate
and the Y coordinate are both equal.
And this is really important.
This is so freaking important
for Bitcoin.
Oh my God, because in Bitcoin,
this happens a lot.
Adding points to themselves.
This have just needless to say
this happens a lot in Bitcoin.
So get excited for applying
this to Bitcoin next week.
So the case whereby point one
is equal to point two,
we need to figure out
how to do addition with that.
Because when we defined point addition
for two points that weren't the same,
we found where they intersected
on the curve when we drew
a straight line
between those two points.
But what line are we going to draw
when the points are the same?
How are we going to find
the slope of the line that we draw
to find where it intersects?
A tangential line.
A tangent line.
Okay, so this prompted me
to go back to calculus and say,
what the heck is a tangent?
What the heck is a tangent?
Do you want to take a stab
at this Portland?
Like, how would you define a tangent?
Like, oh, very.
It's a slope.
But it is essentially,
it touches no other
I can't define it.
No, I don't think I know off the top
of my head what a tangent is.
I just know that it's,
I don't know.
Well, I see where you're trying
to go with that,
because like, usually we kind of
did define tangent
in the way that you described,
which is a line that touches
a curve at a single point
and doesn't cross at that point.
Like, that's the way that
you were essentially describing it.
But where it gets a little weird
is with elliptic curves,
it does intersect the line,
the elliptic curve line later,
just not at the point
that you're defining
the slope of the tangent.
And so I think maybe
that's where it gets a little weird.
Oh, I think that's actually just fine.
I just was actually just trying
to define the actual like,
how do you come up with this angle
that is the tangent
on the point that you have,
which is, well, P1, P2.
So, but yeah,
you basically find that tangent line
and you just follow it
until it hits something, correct?
Unless it is the last special case.
Yeah, yeah.
So you find the tangent point
and we learned how to do this as kids.
And so tangent, I think,
was something we learned.
I think we learned it in calculus.
That would be, did we learn it?
We learned it in trigonometry.
Yeah, then we learned it
in calculus as well,
because in calculus,
we have some cool ways
of actually defining formulas
to find the tangent.
And the tangent,
I think what it's defining
is the slope of the curve at that point.
So you have a point on the curve
and you draw this tangent line,
which is a straight line,
and there's a cool formula
using calculus to define
the slope of that line
and we call that the tangent.
And you do this using derivatives.
So I haven't used derivatives in a while.
Like, it's been a minute.
I mean, it comes back to me, of course,
but I can't,
I just can't say
that I've been using this really
since I was in college.
But it brought me back to remembering
how to derive in calculus.
So we're going to just use
the same elliptic curve equation
that we always have,
which is y squared plus x cubed
plus ax plus b
with a and b being constants.
And we can take the derivative
of both sides.
And then when we solve
for the dx over dy,
we get the slope of the tangent curve.
And the slip of the tangent curve
is 3x squared plus a divided by 2y.
And, you know,
what I would say is to use Bitcoin
or even to be like
an applied cryptographer,
this is the cool thing
about being an applied cryptographer
is as an applied cryptographer,
you can just take the equations
that an actual cryptographer
came up with
and you can just use them in the code.
You don't really have to know.
You don't have to really know
you can literally just be like,
okay, there's a cryptographer
who's figured out
why we're using these equations.
I'm going to just let them
do their job
and I'm going to do my job
as a computer scientist
or software engineer
or an applied cryptographer
and just take those equations
and implement them in code.
And as an applied cryptographer,
I can write a library
and not have to know
exactly why those equations
were chosen,
even why the heck we're doing
point addition over elliptic curves.
Just someone that knows
more about cryptography
than I do figured it out.
That's the bottom line.
They figured it out.
Okay, so we find the slope
of the tangent point
on the elliptic curve
and that slope,
that straight line
with the slope that we calculated
is going to intersect the curve
at one point somewhere.
Okay, so the flippening
then is going to happen
whereby we take the point
where the tangent line
intersects the curve
and we flip it across the y-axis.
So if it's positive,
it becomes negative.
If it's negative,
it becomes positive
and this is important
because we always do this
with point addition.
So this is really easy
to write in Python.
You simply just take
that slope equation
and you just write it in code.
It's like one line of code
and that also accounts
for the fact
that we are flippening it
over the axis
and yeah.
There's one little optimization
in terms of just
I guess style
that Jimmy Song mentioned
and that is that
because of the fact
that your two points
share the same x-coordinate
in the second to last step
where you do x cubed
equals the slope squared
minus x2.
He literally just did 2x1.
So he just doubled it
because that's the same point
and that in the previous step
was you actually did x1 minus x2.
So yeah, yeah.
So I thought about that
because when I was implementing
this in Python,
I thought we're not really
dealing with the other,
the second x and y
and you don't have to
because they're the same.
So you could have easily said x2
Yeah, absolutely.
Use whichever one you want.
Yeah, you can use whichever one you want
because they're literally the same.
I don't know.
Is there anything else to say
about adding two points
that are the same point?
I don't think so.
I think if you want
look at the section
where they do the actual derivative
the dy dx for this.
If you want a better,
I guess understanding
of what's actually happening.
But technically, no,
you do not need to understand this
as long as you're able
to implement these functions
to build your Bitcoin library.
That is just fine.
Yeah, that's such a good point.
And so if anyone's feeling
like discouraged or annoyed
by the fact that there's calculus here
and there's algebra and geometry.
Don't despair
because like Portland said,
you don't really truly
have to fully understand
all of this stuff
to be able to write Bitcoin applications.
I'd say the average Bitcoin programmer
doesn't really understand
where this math comes from.
And that's probably a good thing
because like I said,
we leave that to the experts.
We leave that to the cryptographers.
Let them figure out
why we're doing this.
That's their job.
And we'll just do what we do best,
which is write code.
That's the way I see it anyway.
I have no ambitions
to become a cryptographer.
Do you, Portland?
No, I mean like, of course,
I want to understand this
to the highest degree possible.
But at some point,
I got to understand
I live in a real world with real time
and there's trade offs
everywhere I look, right?
So I could either build
more cool stuff
or I could spend several days
deep diving into why somebody did
this one special thing.
And several years given here.
Well, at least somebody took years to do it.
They can tell you how you need
to find it out in a week.
But yeah, you're technically correct.
It could be you don't know
how long it's going to take you, right?
It could you might.
Well, you wouldn't.
Okay, sorry.
You wouldn't be able to build anything
because yeah, Portland, you're a builder.
You're always building cool Bitcoin stuff.
You wouldn't be able to do any of that.
If you truly wanted to understand
cryptography to the extent
that cryptographers do,
you'd have to say
I'm not really going to build anything,
maybe for a decade.
So I had a friend
who was a Bitcoin programmer
and he was frustrated
that he understood cryptography.
He's a math guy.
He understands how to implement it.
He probably pretty much understands
pretty well like why it was designed
the way it was designed
for different cryptographic primitives.
But what frustrated him was that
although even though he could understand
on a math level
why those choices were made,
he didn't feel that he could invent
new cryptographic primitives.
And that frustrated him so much
that he went back to school
to get his PhD.
Now, if that's his passion in life,
of course, that's the right path for him.
But I'm saying this to say
that if you go into a PhD program
and you're devoting your life
to being able to invent new cryptography,
then you're not going to have the bandwidth
to be able to do cool Bitcoin stuff
like write Bitcoin applications.
So you kind of have to...
I don't want to say
that they're mutually exclusive,
but I think it would be
a little bit of a distraction
to just say I'm going to dive
so deep into this rabbit hole
to understand it
that you might not realize
that it could take years
or decades of your life.
If I'm correct, though...
I choose not to.
Peter Woolley, though, right?
Like, didn't even
with the latest transport encryption,
he kind of...
Is that applied cryptography?
Or is that actually...
Did he create new methods
of encrypting traffic?
I thought Peter Weller was...
I considered him to be
an applied cryptographer.
Yeah, which isn't...
And by the way,
if someone's an applied cryptographer,
it's not taking away at all
from their genius.
It's not like a dig.
Like, I'm an applied cryptographer
in that I can apply cryptography
to my projects.
We all are at this point.
So go ahead.
I want to jump back to...
We were talking about
the optimization that was made
by doing the 2X
for the same point.
That Jimmy Song made as well.
And that was in the section
where he describes, okay,
like, how do you handle
the negation case, right?
So if you have the same X,
but your Ys differ.
And in the way it's implemented,
it basically...
He just literally says,
if the X is equal,
but the Ys don't equal,
just return none and none.
And then it made me think like,
why is he able just to go,
oh, I don't care what the other Ys,
as long as they're not equal.
I know why.
And the reason why is
because you're checking
for the validity
that both Ys exist on the curve anyways,
which would mean that
the other Y that you see
is on the other side of the curve
with 100% certainty.
Is that correct?
Oh, hello?
Well, I know why.
Because there's another case...
You make a great point.
And I actually went through
the same question, my own mind.
And the reason why you check
for both coordinates X and Y
is because there's another case
whereby the X's are the same
and the Y's are also the same.
And that's the case
where you draw the tangent
on the slope for that point
and find where it intersects.
So that's the reason why.
But then you're bringing up
a third case,
which is you could...
You're bringing up yet a third case,
which is the case whereby
someone has defined a point
that's not actually on the curve.
I was just like, how did you just go
and just go, oh, yeah, it's fine.
Just return, none, none.
And it's because he's assuming
you're on the curve
because of the way the class
that you build for this.
So when you actually define the point,
it makes sure that your point
is on the curve.
So you can't put points
that aren't on the curve there.
So, yeah, that's why he's able
just to completely not actually check
if they are on the curve again
because it's already been defined.
So, yeah, thank you.
Sorry, that actually made more sense
when I said it out loud.
Yeah, okay.
So we defined point addition
for the case whereby X1, Y1, X2, Y2
are not the same.
That was the first case.
We define point addition
where the X's are the same
but the Y's are different.
And that's kind of a weird case
whereby we return the point at infinity.
And the reason we do that
is because we want this invertability
property to hold for point addition
whereby if you take a number
and a negative number,
say number two and negative two,
add them together,
you expect to get zero.
We don't really have zero.
We have this weird identity point.
So in this case,
we're just going to literally
hard code this in Python.
You're just literally going to
hard code this and say,
okay, if the X's are the same
but the Y's are different,
just return none.
That's the point at infinity.
It's a little strange, but it works.
So those are the cases we've defined.
We do have yet one additional case
and that is the case where
the tangent line is vertical.
And this happens
where the Y coordinate is zero.
And so that tangent slope
is just going to be like
a vertical line going up and down.
And you handle this in a special case
and you literally just check
to see if the Y is zero.
If the Y is zero,
then you're going to just return none,
which is the point at infinity.
So lots of weird kind of cases here,
but I'd say the case that we use the most
is the addition where
you're adding a point to itself.
And this is where things
get really, really fun for Bitcoin
because in Bitcoin,
we love adding points to themselves
and we'll see why next week.
So I feel like that gets us
pretty much through the whole chapter.
What else Portland?
What have we not covered?
I actually had an observation just now.
So I'm looking at this code, right?
So we just went over this section
where the X's are equal,
but the Y's are not equal.
And you return none, none, right?
Because basically they're flipped.
You're on the other side of the curve.
But the same thing actually is true
of that last point as well,
the one with the vertical tangent line
because the X's would technically be equal.
Both are essentially zero.
And then the Y's are also equal,
but you again return none, none.
So is there any case where X equals X
that you don't return the zero point
when adding them together?
And that is when the X's are equal
and the Y's are equal.
They're both equal.
Yes, you're correct.
You're correct.
Yeah. Okay. Yeah.
Because same point.
Okay. Thank you.
I apologize for forgetting that case.
No, that's okay because that's okay
because the last case is again,
just a weird edge case whereby there's
this weird exception that you're adding a point to itself.
And usually when you add a point to itself,
you find its tangent and then see
where that tangent intersects the elliptic curve.
But in this weird exception where Y is zero,
that tangent does not intersect the curve anywhere
because it just goes up and down.
And so because it doesn't intersect anywhere,
we're imagining that there's this other point out there
somewhere just on the edge of the world,
the point at infinity.
And we're imagining that this is a real point
that's on the curve, but it's not.
And we're just defining it in Python as being none.
Its X coordinate is none.
Its Y coordinate is none.
Like I said, we're on acid.
We're in wonderland.
Shit's a little weird.
Okay. So just go with it.
Just go with it.
If you ever meet the guy or woman who invented this,
we'll just be like, what the fuck were you on?
Like you were on something.
Very weird.
And yeah.
So I think we covered everything.
I think this might be a good time for us
to say some kind of concluding words about the chapter
and then invite people to have any questions
or comments they might want to share.
Those questions or comments can be about the chapter.
They can also be about Git or GitHub
or Jupyter Notebook or even Python.
And the questions can also be,
after we get through the elliptic curve stuff,
if you have any residual questions about finite field math,
now would be a good time to bring those up as well
so that we will be all caught up for next week,
which is chapter three, elliptic curve cryptography,
where we're taking the elliptic curve
and we're plotting it over a finite field.
And when I'm talking about Alice in Wonderland on acid,
this is where you're really going to go on an acid trip
because that elliptic curve plotted over the real numbers
is going to look very, very, very different
for the elliptic curve plotted over a finite field.
So buckle up.
It's actually pretty beautiful, the combination of these two
and how you take this really nice, smooth thing
and then you turn it into complete chaos and security
through that method.
But I was going to ask my question real quick
is you mentioned earlier that Bitcoin uses a lot
of same point addition.
So like P1 equals P2.
What is that used for frequently in Bitcoin, I guess?
So the reason...
Yeah, and I don't want to get too far ahead of myself,
but the reason I'll say that is because
when we start to define other math operators,
such as multiplication, for example,
the math operators are weird, right?
So we can't really multiply two points,
but we can take a point and we can add it to itself
a bunch of times.
So that's why I said in Bitcoin,
you're going to see this thing where you're taking a point
and adding it to itself over and over and over and over again.
You're going to see this happen a lot.
This happens a lot.
So just kind of visualizing that in my head real quick.
So let's say you're doing seven times a point.
You're going to basically add that point to itself
like seven times because this is pretty non-linear.
Does that mean that each resultant becomes
like more and more random compared to the original?
Or is it...
Yes, it's bouncing all over the place.
Okay, that's sick.
Every time you add it to yourself,
the result is just shooting across Wonderland.
That's amazing.
With no...
Okay, cool.
I'm excited.
Because it's like you said, Portland,
it's not linear.
Because regular multiplication,
you see like this nice slope.
And then with this, it's just going to go...
That's pretty cool.
Okay, time for questions from everybody else.
That was my grand question.
I guess concluding thoughts real quick?
Yeah, just because the addition is not linear,
the result can just be almost anywhere on the graph.
And it's not intuitive where it's going to end up.
So I'd say my concluding thought is,
again, my explosive moment was the understanding
of why the flippening happens
to enforce the associative property of addition.
That was really exciting for me,
getting to go back to calculus
to remember how to define and compute tangents.
That was really fun.
And then also, I think for me,
the most fun that I've had is writing this code in Python.
Because I have not really a Python person.
I don't have anything against Python.
It's just not a language that I've really needed to use
in the past.
And it's kind of a pleasure to see
just how easy it is to code in Python
and how all of this crazy math
you can just write in a single line of code.
It's really fun.
So I'm excited.
I'd say those are my takeaways.
I'd just say, nonetheless,
literally Python combined with Jupyter notebooks
is so incredibly easy to work with.
It feels like you're writing in an actual notebook,
but you have the power of multiplying
just exponents and stuff instantly.
But yeah, I guess my takeaway,
again, the flippening would be the first kind of big point.
When you add things together,
you flip it on the y-axis before you're finished
or x-axis.
Sorry, I get that backwards sometimes.
But the second thing I would say
that if you take anything away from this,
it would be understanding that by adding things
on the elliptic curve,
the rules created for addition
aren't meant to look like what we have in normal
just numeric values.
It's meant to just give you another point on the curve.
And as such, when they say addition,
they're just creating rules to make sure
that everything fits to give you a result on the curve.
The reason why we have these special edge cases
is so that set of things is complete under all conditions.
As you add anything from just any x-value,
you can get a solution.
That's why this exists.
So it's just a way of defining something.
It's not necessarily meant to look like
the addition you're used to using.
So yeah, just let your mind just let it loose
and just try not to apply traditional mathematics
too much to this.
Otherwise, that will become very difficult.
It's just something that was invented
to define this operation on elliptic curves.
Some guy literally just made it up.
Just remember that.
It's made up math to give us something
that looks kind of like a duck.
It quacks kind of like a duck,
but also kind of weirdly has a weird duck feathers.
But it's duck-like enough such that we can call it addition.
But it's just literally made up by some guy.
So be prepared to suspend your disbelief.
And yeah, to your point,
Portland about Jupyter Notebooks with Python,
it is so fun.
And what's so crazy fun
is if you actually define bash commands
also in your Jupyter Notebook,
and then you can execute them within the notebook itself.
And I was doing that with Bitcoin D.
And oh my gosh, it is fun.
It's like crack.
It's so, so, so fun.
You can call on Bitcoin CLI from the Jupyter Notebook.
And you can check to see if your work is lining up
with what Bitcoin is happening.
Wait, so you could just...
Because we're not really...
So we're defining our own Bitcoin library.
We're writing our own Bitcoin library from scratch.
So we don't actually need Bitcoin D.
But what's cool is you can execute the Bitcoin CLI commands
within the Jupyter Notebook.
And as you're going through this book,
you can check to make sure that your work is correct.
You can check it against the actual Bitcoin core
reference implementation itself.
So if you like create a transaction
in Jupyter Notebooks using Python,
you can call the Bitcoin CLI
to literally validate that transaction.
Grab into it.
Yes, yes.
Okay, that's cool.
I haven't gotten that far with Jupyter Notebooks.
I pretty much coded Python
with just them and command line,
like not this Jupyter Notebook thing.
This book actually introduced me to Jupyter Notebooks.
And I'm a big fan so far.
But okay, yeah, I look forward to that.
That is excellent.
And I saw one of the comments from captain,
hashtag BTC says he's been writing code for decades.
C, C++, C sharp, JS, et cetera,
new to Python.
So I am learning two new things,
both building your own Bitcoin library
and Python at the same time.
So should we, let's open up the floor for questions.
Go ahead and raise your hand
if you have a question or comment
about anything we've gone over.
And again, that can also include
GitHub and Jupyter Notebooks and Python.
Now that said, I mentioned this last week,
I'm going to say it again.
If you come to all of these sessions
and you go through the exercises in Python,
in your Jupyter Notebook,
and you actually make sure
that you implement all of the code yourself,
if you take that repository
and submit it to Portland and I
at the end of this bootcamp,
you will receive a certificate
of completion that we will issue
on the Bitcoin blockchain itself.
And that's going to, I think,
mean something.
It's going to mean something to me.
If I see that you did this
and I'm looking to hire somebody for a job,
you're going to be that much more
of a viable candidate
than somebody who did not.
It's also good for yourself
to do this as well.
You will understand a lot more
about Bitcoin
and just in general programming.
And especially if you haven't
touched Python before,
integrating Python with Bitcoin
is really actually an amazing use of Python
just because of the number library includes.
Also, as a side note,
you are very responsibly embedding
this data into the time chain
using an op return and just a merkle hash, right?
That instead of just inscribing
a bunch of stuff,
it's a very small representation.
So it's a point of contention,
which is why I'm proud to say that,
yes, you're going to have
your certificate of completion
issued on the Bitcoin blockchain.
I know this is a huge point
of contention right now
because we are currently witnessing
a culture war between the inscribors
and the filter boys.
And so that said,
we are very respectful
of the Bitcoin blockchain.
Okay, Portland and I
were very, very, very respectful wishes to say
that every single certificate
is going to be rolled into a primitive
that's used in computer science
called a Merkle tree,
which is used not only in this application,
but all over Bitcoin.
We see Merkle trees all over the place.
And with a Merkle tree,
what you can do is you can take
a bunch of distinct pieces of data
and you can hash them all with one another
and only have to provide the root hash,
which is only going to be 32 bytes
as well as a Merkle proof of inclusion
or sometimes just a Merkle proof
to prove that your data
is made its way into that Merkle tree.
Now, the proof of inclusion
is a little bigger,
but it doesn't have to go on chain.
I'm going to provide that to y'all off chain.
So you're going to get your data,
your Merkle proof of inclusion.
You're going to get that off chain.
And all that's going on chain
is just the Merkle root.
It's only 32 bytes.
So if 10,000 people take this class
and we issue 10,000 certificates,
we're still only going to inscribe,
if you will, 32 bytes.
So don't cancel this, okay?
It's only 16 bytes for me,
16 bytes for Portland, total.
I would say that I would hope
that 10,000 people do do this,
but I just thought of another way
you could technically do it,
but it wouldn't be good.
It would be to put each,
basically hash of the proof of completion
as a pay to witness script
hash redeemed script in the out point.
So you just have every completed person
gets their own out point.
But no, we're not doing that.
Right, but we're doing just the one.
We're doing just the one.
Now, what would be cool
is if we give you the Merkle proof of inclusion
or the Merkle proof,
the data, which is to say,
Portland Hoddle completed this course.
Which I will.
Which he will.
So he's going to get his own.
D++ completed this course.
That's the data that's getting hashed.
The proof of inclusion proves
that we're in the Merkle tree
and then the Merkle root
goes on the Bitcoin blockchain.
So if I give you all three
of those pieces of data,
it's going to be up to you
to write the code that validates
the Merkle proof.
Yeah, that'll be a cool exercise.
I think for the participants.
OK, I see we have one person
is requesting.
I'm going to add them as a speaker.
Portland, I've added you as a co-host.
I don't know if you're able to.
I'm not going to.
I'm not going to chance it.
I've had a stable connection
for 30 minutes,
so I'm going to take it.
Also, and don't be shy.
Don't be shy.
I see Topher is in the audience.
So it's funny because
when he joined us last week,
he said, oh, chapter one
is my favorite chapter
of programming Bitcoin.
I thought he was joking.
It turns out he's not.
He loves that chapter is great.
Like it's not more than this one did.
Like this chapter is really cool.
But the first one that
that basically the P minus one factor
of how that translates
to the zero power
and you invert these things to divide.
That was boom.
That was pretty cool.
I mean, when we talked about
how with point addition,
you're just kind of defining an operator
that's kind of like addition.
We did that last week
with finite field math
whereby we defined these operators
that were not really the operators
that we know and love.
They're these weird
Wonderland versions and division
in particular gets really weird
because you can't really divide
in a finite field,
but you can multiply
by the multiplicative inverse.
So OK, we're going to just do that.
And again, some guy just decided
that that's how we define addition.
And so we're going with it.
So OK, captain, did you have
anything to add about today's session?
Any questions, comments?
Yes, yes.
Hi, Miss D plus plus.
Hi, Mr. Portland Hoddle.
I just wanted to first say thank you
because like this is the perfect timing
and I am like an audio
audio visual learner.
So like hearing your voices
is just really cool.
That's number one.
And then number two.
Oh, I'm interested in talking about
like how the process of how you're
going to like issue these certificates
but not today or maybe on not online.
And then three.
Oh, oh, oh, can I Mr.
Portland or is it Mr.
Portland or is it Mr. Hoddle?
It can be anything really,
but Portland Hoddle is typically
what I go by on Twitter.
There's a lag here,
so I'm just going to keep talking.
But you can clarify that later.
I would like to translate the script.
Like I want to invite some
of my friends locally
that can take this with me.
So like if I can have the
I don't want to have to like
copy and paste the whole thing.
If I can have like a copy of it,
I'll make the translation.
And oh, the slide deck.
If that's OK with you
and you can have it.
I mean, the slide deck.
Yeah, absolutely.
I can just share a Google link to that
because it's done on Google talks
or I'll just post it in my GitHub
repository along with the other ones
I've been doing so far.
So along with the chapter,
I just dump all the images of these.
So yeah, absolutely.
What language are you going
to be translating over to?
I guess my first one is going
to be Nepalese.
And then yeah,
then I can easily do whatever I want,
but I'm just I have local friends.
So I'm gonna do Nepalese first.
I mean, yeah, Nepalese.
So yeah, it's gonna be fun.
I love that.
I love that.
Yeah, you mentioned audio visual learning.
We all have our different learning styles.
And if you're just listening to the spaces
and you don't have anything to look at,
you might be a little confused.
I would definitely suggest
as you're listening,
having a book in front of you
and permanent slides in front of you,
having your Jupiter notebook open
so that you have something visually
to look at.
Last week, I was kind of toying
with the idea of streaming
the visual on Twitch.
But I don't know.
I think I'm just gonna hopefully
leave that up to y'all.
It's up to y'all to make sure
that you have the right visual
materials prepared for yourself.
And if we can figure out
how to make it work on Twitch,
if we're gonna do some live coding,
But in the meantime,
yeah, just have like your laptop
or your book open.
What's up, Brian Sandwich?
Ma'am, I am a Reuben, not a sandwich.
Oh, Reuben.
Hey, Brian.
Is this your first time
going through elliptic curves
or are you a veteran to the curve?
No, I am a curved newbie.
But I was gonna ask you guys,
where is this course that you guys
are talking about?
Yeah, so what we're doing
is we're going through
Jimmy Song's programming Bitcoin book
where you're learning
how to program Bitcoin from scratch.
So you're not gonna be using libraries
that implement the cryptography for you
or libraries that construct transactions for you.
You're writing all of that yourself in Python.
And so last week,
we went through finite fields.
This week, we're going through elliptic curves.
It might not make a lot of sense to folks
why we're talking about finite fields,
elliptic curves,
but you're gonna find out next week
when we combine those
in elliptic curve cryptography.
So Brian, what we're doing
is we're going through a chapter a week
on Sunday.
And for folks who are following along
with their Jupiter notebooks,
which Jimmy Song has
in his GitHub repository
and actually going through the exercises
and implementing this library themselves
from scratch,
if they get through the entire book,
they are going to receive a certificate
of completion from Portland and I
saying that you completed
the Bitcoin boot camp
to our satisfaction.
Hey, uh, real quick.
Sorry to interrupt,
but I just had a thought.
Should I make a copy?
Do you have like a schedule?
Hey, captain.
I think you might not be able
to hear Portland.
I think she can't hear you.
Go ahead.
So I was going to say,
do you think I should create
a copy of all of the examples
that or the exercises
that Jimmy Song has in his book
so that people can maybe even attempt
to solve them without having
to purchase the book
or find a copy somewhere?
Does that make sense?
Because like just like what
somebody needs to complete
very simply to buy
because right now
I don't think there's
a very well defined set of things
other than.
Super simple Portland.
What they need to complete
is the exercises in the Jupiter.
Okay, perfect.
And that's going to be available
all in his repository on GitHub.
So if you click on my page,
D plus plus on my Twitter
and you click on the Jimmy Song
programming Bitcoin link,
that's going to take you
to Jimmy Song's GitHub repository.
Then from there,
what you can do is you can either
clone it to your local host
or you can fork it
to your GitHub either way
and you are going to be able
to run a Jupiter notebook
once you've installed some dependencies.
From there, you're going to go
through each chapter,
one chapter per week
and you're going to flesh out
all the exercises
in that Jupiter notebook.
And all of those exercises,
Portland to your point,
are very well defined.
In many cases,
what Jimmy Song has done
is he's written the tests,
the functional tests in Python first
and you have to go through
and write the classes and methods
that fulfill and satisfy those tests.
So this is like test first development
for those of you
who follow a test first development.
And it's fun.
Test first development.
I'm just going to take a stab at this
and I think I've done this in the past.
It's defined as basically
you write the tests first,
like your expected outputs and solutions
and then you build the code
to achieve those results second.
Yeah, which is what we're doing
in this book.
It's like the tests are first
so then we got to make sure
that we satisfy them.
Side note, I actually haven't been,
I do have Jimmy Song's repository forked
but I've been attempting
to write the Jupiter notebook myself
from scratch with each one,
like literally not using templates.
Yeah, so you've been going through
like a little extra work on your part
which is great.
I have not been doing that
because there's a few things in here.
Like some of the class definitions
he already provides for us,
for example, the point class,
he's already fleshed out some of that.
So he's fleshed out the constructor,
he's fleshed out the equal operator
that overrides the existing equal operator
in Python and then I've just gone in
and I've fleshed out the ones
that he didn't complete,
like not equals, for example.
So yeah, I think if you're doing
what Portland's doing
where you're writing everything,
you're going to get probably even more
out of this class.
And the equals operator as well
is a little interesting too
because of the fact that
I really kind of come to the conclusion
that most of these things
that Jimmy Song does
for the equals operator,
he's just basically writing
to make sure all the members
of that class are equal to each other.
Like all the equals
and not equal statements
are exactly the same so far at least.
Oh, sorry to take the floor, Brian.
I apologize.
Anything else?
No, I was looking at the code too.
Brian, I was going to say
you should totally go through
the whole thing with us.
I'll try.
I'll help you along, Brian, if you want.
I've been having a lot of fun doing this.
A lot of fun actually.
Programming Bitcoin.
I think I literally had a start on GitHub
and I've been meaning to get through it.
Do all the things through it, Brian.
That's the thing is like,
this is your chance.
It's like how many people
had this book for
sitting on their shelf getting dusty
and someday they're going to finish it.
Well, this is the sign
you've all been waiting for.
And if you're just joining us
for the first time today,
don't worry.
You can totally catch up
because the first chapter,
it's about 20 pages.
It's not too long
because there's a lot of diagrams
and it's not too late to get caught up.
But what I would say is don't wait
until we're like halfway through the course
and try to catch up
because I'm not going to keep
all the material up on my Twitter forever.
So you're saying there's digital scarcity
to your material.
There's digital scarcity.
Yeah, it's ephemeral.
This is you got to kind of be here.
You had to be there, man.
You had to be there, bro.
You didn't scribe it
so it never goes away.
Don't tell people that.
Topor, do you want to say anything
about this chapter?
I see you're in the audience lurking.
Anyone else have any questions?
I can't I don't believe
that no one has no questions.
Like I'm getting a little suspicious
because if you guys
aren't asking questions,
I'm starting to wonder
if you're really.
I mean, to be fair,
Dean, like the curve
cryptography is literally
like fucking Chinese even to me.
And I'm literally sitting here
like I was listening to you guys.
I'm literally here like Googling
and fucking asking chat
JPT stuff to try to understand this
and it's still like black magic.
So Brian, what we said,
I don't know if you've been here
the whole time,
but you just imagine that
you're like halfway through.
Well, OK, what I said was
just imagine your Alice.
You've just hit Wonderland
and you're on acid
and everything is super weird.
Math just got really weird.
That's elliptic curve photography.
I guess then.
So since a lot of it
did sound like Chinese,
what we do got the coding part.
They will.
Hey, Captain, do you mind?
Do you mind just stepping down
and then coming back up?
Because I think you're not
hearing Portland.
And Portland.
Sorry, go ahead.
And I apologize, Captain.
I didn't mean to talk over,
but Brian,
do you have like a specific question
or something that was
exceptionally confusing
or something that you wish
was more clear about today's topic?
I wish I did,
but it's like it's like
I'm so trying to understand it
that it's like I don't even know
what's the right question to ask.
So I guess let's start with
how about how exactly is like.
Sec P 256 K one specifically
used to derive.
I believe it's used to
derive public keys, correct?
So here's the thing, Brian.
So we've been talking
about this for two weeks now
and we haven't defined
sex sex P 256 K one.
We haven't defined
public and private keys.
We haven't defined
public private key cryptography.
We haven't talked even about
what an elliptic curve
looks like over a finite field.
All we've done is just looked
into what is a finite field?
What is finite field math,
which is to say
how do we define math operators
over a finite field
and what is an elliptic curve?
That's all we've done.
We've talked about point addition,
which is where you take two points
on an elliptic curve
and you find a third point
that's also on the curve.
That's all we've done.
So if you're feeling overwhelmed,
that you're way far ahead
of what we've even covered.
No, no, so I guess it's just
I guess it's just kind of more
of the way like I learned.
So I guess you guys
are kind of going from it
from like a top down
or like a bottom off perspective.
You're building exactly.
I work more from like a top down.
Like here's the final thing
and then like I deconstruct it
and figure out like
how the fuck it works.
So yeah, that's probably why I'm lost.
I guess I would say
in a nutshell today,
I think all that we really described
was why the curve looks
like the shape it does, right?
So why does it have like
it just basically is like this bend
and it's got this little thing
that comes off
and it goes down the other side as well.
And then we defined basically
how you can take two dots
on that curve
and get a third dot.
At the end of the day,
that's really it.
But why I guess like what's the point?
Obviously I know it's using cryptography,
but I'm trying to understand like
how is it used?
Like how does this help me?
Have you ever heard of key tweaking?
I've heard the term, yes.
Okay, so when you tweak a key in Bitcoin,
what you're essentially doing
is point addition over elliptic curves.
So that's one example of like why.
I'm literally adding a random number.
Say that again.
I'm literally just adding
a random number that's on this curve.
You're adding two points
so that you have points on the curve
and you can add them together
to get a third point.
And we do this a lot in Bitcoin.
I'm just giving an example of key tweaking
because it's something you may have heard.
And it's an example of like
why the hell do we do this?
We do some key tweaking
and then we do it, yeah, we do it
with public and private keys.
So we'll talk about
how to derive public keys
and we derive public keys
by using point addition also.
I think, I guess,
please correct me if I'm wrong here,
but the other thing
you can really gain from this
is the fact that the addition
on these curves is nonlinear.
I think that is one of the bigger things
I got out of this.
And then I think next week
we'll go over how it applies
to an actual curve
once all of a sudden you apply
a finite field over this
just massive number, so, or equation.
So when you say a finite field,
do you just mean any two values
between an x and y coordinate?
Yeah, so in the first chapter,
we defined finite fields.
I didn't know you were doing this, sorry.
Yeah, it's just a set of number.
It's just a set of numbers.
So like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
That's a set of numbers
with an order of 11,
which is to say
there's 11 numbers in that field.
And then we define the math operators
across that field such that
the result of those operations
are also within the field.
And you can go back and listen
to our recording from last week
and then go through that chapter
and then go through the exercises
in the Jupiter notebook
to kind of help you understand.
And again, kind of like we talked
about being in Wonderland,
the operators that you define
over a finite field
are kind of weird plus and minus
and multiplication and division.
They have their similarities
to their regular operators
that we know and love,
but they're also a little strange
because they have to
result in numbers
that are within that field.
And for that reason,
there are some weird properties
that they hold.
What's up, Topher Scott?
I don't know if your Twitter
spaces is bugging out.
He said earlier
that his Twitter
was kind of bugging out today.
So if you're not able to talk,
Topher, I guess,
maybe drop down and come back.
Well, in the meantime,
Brian, in terms of the first chapter
about finite fields,
the math is very similar
to like clocks,
basically how things just wrap around.
So if you have a finite field
with an order of 12,
it means that you have
the numbers 0 through 11 in that
and you can just go around
and then once you add over that,
you just you just wrap it around
again and again and again.
And the math in that is extremely,
it's pretty simple overall.
It's like addition, subtraction,
multiplication, you can get that
in like five minutes.
It's not too bad,
but division is incredibly like
it's not incredibly difficult,
but if you walk down the right path,
you it'll hit right away.
But yeah, just finding that way
to get there to that conclusion.
Yeah, just follow the book
or just ask me.
I kind of walk you through it.
How basically something
to the zero powers one
and how you can essentially do division
through multiplication of things
with negative exponents.
So but yeah, division is the one part
about that chapter
that actually really matters.
Topher, can you talk?
Is your Twitter still bugging out?
Hello, hello.
Oh, you sound great.
Hey, I saw that you had a riddle for us.
Yes, there is a certain
theorem in chapter one
that shows itself here in chapter two.
And yeah, so that's my riddle.
Can you spot it?
Oh man, that's the thing is like
we haven't really combined
the two chapters together
because we're doing that next week,
but I'm trying to think what.
We haven't really done
modular arithmetic in chapter two.
So Portland, are you thinking?
Yeah, I'm processing.
Very slow processor here though.
I'm just kidding.
We're not really using
modular arithmetic.
We're not using finite fields.
We're just adding.
So is it something to do
with adding Topher?
Well, maybe I'm jumping ahead a little bit
because in the math,
you do use modular arithmetic,
but that's that's in the next chapter.
But chapter two.
But you're talking about
you're talking about chapters
one and two though Topher, right?
Well, I take that back
because in the finished code
when you're done writing the library,
it is involved in chapter two.
But I guess you don't have to involve it yet.
But it will be involved
when you write the code
for doing point addition.
Yeah, over finite fields.
But do you want to just
do you want to just tell us the answer
or do you want to keep us guessing?
Well, yeah, so the Portland
was talking about it
just before I came up.
But yeah, so there's this theorem
called Fermat's Little Theorem
that's explained.
And it's what you use to do division
with modular arithmetic.
And you will be using it again
in order to do point addition as well
because there's division
that's required in that operation.
My boy Fermat.
Oh, now I'm pretty stoked.
So when you wrote your library
for Taproot, did you use this book
as a reference and just go through
and rewrite everything in JavaScript?
I did. Yeah.
That's cool.
Yeah, and now that I'm looking at the code
because there's the book
and then there's the Jupyter Notebook
that follows the book.
And so in chapter two,
you will have built a library
for doing arithmetic
with number fields, finite fields.
And so when you do the point arithmetic,
do they make you also use finite fields?
They should.
Next week, yes.
Next week, we're going to combine
the two ideas
that we've learned thus far
because right now we're just
right now we're plotting
the elliptic curve over real numbers.
We're just getting numbers as the results.
There's no limitation
or modulus happening at all.
It's just here are your three points,
the two you put in
and then the third one
you got back out from this.
Is Topher speaking?
I'm scanning the code.
Oh, I see.
Topher has already cheated.
He's already moved ahead.
I guess Boatface, welcome to the stage.
I just have a quick question
to clarify what we talked about today
and this is probably going back
to high school math
for many of you,
which I was terrible at.
I can do tech,
but I can't really do graphs.
But here when we're adding these points,
like let's say p1 and p2,
which is x1 or the coordinates x1 and y1
and the coordinates x2 and y2.
To add those,
are we just simply taking the first x1
and adding it to x2,
taking the second y1
and adding it to y2
and then that makes up the addition c
in the case of the first a
plus b equals c example.
So Boatface,
when you're adding two points,
on the curve,
you're going to plot them
on the curve
and you can do this visually
and then you're going to draw
a straight line
between those two points a and b.
A straight line.
There's always going to be
a straight line
that you can draw
between any two points
and we learned this in pre-algebra
and we were kids
like before we did it algebra
and trigonometry
and calculus and all that stuff.
You can draw a straight line
between any two points
and what's cool
about elliptic curves
is when you draw that straight line
between the two points,
it's going to intersect the curve
in a third point.
We'll call that point c.
And looking at the book
on page 30
is really going to be helpful.
It's probably not going to make sense.
Yes, I think I maybe
didn't ask my question correctly.
I see the picture
and I see what I'm trying to
what is supposed to happen
but I want to be able to prove it
by plugging numbers in.
So if you try to plug those numbers in
and say x1 plus x2 equals x3,
that won't work.
So I can't add the coordinates?
Well, you can't add the coordinates directly
because you would just get
another point out in space.
It wouldn't be on the curve.
So instead, you have to do this process
where you find the slope
of those points.
So if you have one point another,
you find the slope of it.
And then essentially what you're doing
is you're then drawing a line
at the rate of that slope
through those two points
and then use this special equation
that is outlined in Jimmy Song's book
or you could actually read through
how it's derived.
Basically, it'll tell you
where it intersects
with the third point on the curve.
And as such...
Yeah, okay.
That makes more sense
because the coordinates
obviously don't match up right.
And so I guess the answer is
maybe just get a calculator
to do that for you.
It's more than a calculator.
Why don't we just prove
that Boatface's hypothesis
is not true.
And it's a great hypothesis
to try to prove or disprove
because the hypothesis is,
okay, we have x1, y1, x2, y2.
Let's check to see if x3
is going to be the sum of x1 and x2.
And so I'm going to look...
Or the zero point.
I'm going to look...
With the zero point, it will be,
but let's define two points.
This is from a Jupiter notebook,
exercise 14.
In Jupiter notebook,
exercise four,
the first point is going to be
two comma five.
So the x is two, the y is five.
The second point is going to be
x2 is negative one,
y2 is negative one.
So let's just forget the y's
for now and look at the x's.
We're going to prove or disprove
Boatface's hypothesis.
So x1 is two, x2 is negative one.
What is two plus negative one?
I know this one.
What is two plus negative one?
Let's go.
It's one.
Nailed it.
It's one.
So I'm going to add these two points
using point addition,
meaning I'm going to plot them
on the curve,
find where the third intersection
point is if I draw a straight line
between those two points
and then invert that
across the y-axis.
Now the result that I get
is three comma negative seven.
So is three equal to
what Boatface just said?
No, it's not.
You can kind of go through yourself
and you can see
where they might end up
if we have these linear properties
that we don't have
with elliptic curve point addition.
When you add two points together,
the result could be almost anywhere
on the graph.
It's non-linear.
That's why these curves
are so freaking cool
from a cryptographic standpoint.
And I think it's a great question
because you would think,
yeah, x1 plus x2 is x3,
but it's not.
You know, sometimes in math class,
like you don't get it
and you're listening for hours
and then some concept
kind of falls into place
and then retroactively
you understand it all.
That's like kind of two weeks
in a row that's happened.
Last question.
When you do that total turn
and flip to the other axis,
so far from what we've seen,
that's not really like a formula
so much as an interesting thing
that's going to become relevant later, right?
It is defined in the formula.
So right now,
when we've been defining point addition,
we have actually been
flipping over the results.
I guess my question is like
the flipping over of the result
ends up in these mathematical oddities
that we're studying.
But like there's no reason
to flip other than to prove
the mathematical oddity.
Yeah, there's a reason
and that's the flippening.
So when we're defining point addition,
we want it to satisfy properties
that we generally think of
when we think of addition
because it's not actual addition, right?
It's like it's this addition-like operation
that we're defining over elliptic curves.
So it's like, again,
we took acid, we're in Wonderland,
we're trying to figure out
how to add points.
You can't really add them,
but we can come up with a way
of doing an operation
that's kind of similar to addition.
And one of the things
that we want to be true of addition
is a property that's called associativity.
So if you recall,
when you were a little kid,
a plus b plus c is the same thing
as b plus c plus a.
Like the order in which you add stuff
should not change the result.
Like 1 plus 2 plus 3
is the same thing as 2 plus 3 plus 1.
Those should always be the same with addition.
And if they're not,
then something's not right
with that addition operator.
Real quick,
I think all the other three properties
hold true correct,
even if you don't flip the x-axis over that, right?
But it's associativity property
that it then fails.
But all the other properties
also still are satisfied by flipping it.
And then you also get
that last property as well.
So hence adding the flipping,
flippening is really just a construct
created to make sure
that all four of these boxes were ticked, right?
Yeah, I think so.
Because it's unintuitive though.
If you're just looking
at the commutative property of addition,
which is to say a plus b
equals b plus a,
that actually holds
even if you don't do the flippening.
So you don't need the flippening for that.
But for the associativity property,
you do need the flippening.
And so for you both face
on page 32 and 33,
what I did was I went through
these three points, a, b, and c.
And I said, okay,
what result do I get
when I change the order
of which points I'm adding first?
So I said, okay, first,
I'm going to add points a and b,
and then I'm going to add point c.
And in another case,
I'm going to add points b and c first,
and then I'm going to add point a later.
And when I change the order
in which I'm adding those points,
if I don't do the flippening,
I come up with two
completely different results.
They're both on the elliptic curve,
but they are in no way
flippening.
Then no matter what order
I add these numbers together,
I still get the same results.
And that's the reason
for the flippening.
does that suggest that you could
also do it in slightly
out of order like a plus c
in parentheses equals
or plus b equals
if we didn't flip,
that wouldn't work.
You wouldn't be able to do that.
Where do you flip
when you move the c
to the second position?
Like you just flip is sort of inherent
in the anytime you add,
you're going to flip
anytime you add, you flip,
you flip anytime you add two numbers
because so they're in parentheses,
You're supposed to add one set first,
then apply the next operator,
that next addition to that.
So it's going to flip twice,
if I'm correct in that set.
Two flippenings.
That's right.
Two additions, two flippenings,
three additions, three flippenings,
four additions, four flippenings.
Holy cow.
And then, and Bookface,
I know this is marinating for you,
but you mentioned you had an aha
moment tonight.
I'm wondering when that happened.
Just when I realized
that I'm wasting my time
like eyeballing these coordinates
and trying to add them up
and like they're not adding up.
I see now like
a calculator thing.
Yeah, yeah.
Okay, cool.
I'm not a smart man.
I'm a technical man.
I wouldn't say you're wasting your time.
I'd say that you're testing
a hypothesis and they're proving
or disproving it.
I would say even better
than using a calculator.
Use Python.
Literally just open up a Python shell
and just start like I think it's in.
It's a lot easier to read the code
and understand what's happening
the math formula into lines.
I think Jimmy Song's GitHub repository
has an example that you can basically
run from the Jupyter Notebook
that will add points.
I would have to double check though
because I wrote my own.
Yeah, there's a lot of examples
that add points because
for all the examples and exercises
in the Jupyter Notebook,
we're adding points
that have different properties
like points where the x and y's
are different,
points where the x and y's are the same,
points where the x's are the same
or the y's are different, et cetera.
And we're going through all those cases.
Speaking of Jupyter Notebooks,
I want to say one thing
I've discovered that is very fun.
I actually hosted my Jupyter Notebook
instance in a Docker container
on another computer.
And what that was interesting
is because now I have access
to that Jupyter Notebook
from every device in my house
or even I broke it out to the web too
so that I'm able to access it.
So it's not just limited
to every time I installed on a new computer,
I have this workspace
always available to me.
So you can do that.
You can run it as like a service
on a host, even a Raspberry Pi.
And then from there,
you can just access it
through that IP address
followed by the port number.
All right.
Post Capone.
Let's bring up Post Capone.
Off topic.
What is going on with the sandwiches?
I feel like I'm a bit out.
Oh, sorry.
The Rubens.
I feel like I'm a bit
out of the loop on that.
The Wizards are scammers
and they backstabbed us
and they're selling cats
to promote op cat.
So we're doing sandwiches
to promote op CTV.
Post Capone, are you following
through Jimmy Song's
programming Bitcoin with us?
I just turned down
but I absolutely
come to you.
I have used it
quite a million times in my life
but I'm really excited about
the walkthrough for it.
I'm really excited about buying
to pay for it.
I'm sure they're going to
actually sell it in science
and we're going to sell it in science.
You're a little muffled
I can kind of hear you
if I listen really fast.
Is this better?
If I speak loud.
Yeah, that's better.
I'm in a public space, yeah.
What I was saying is that
I've used Jimmy Song's book
quite a lot of times
and I just tuned in to this space
but I absolutely follow in it.
I'm very excited about
the walkthrough thing
but I am also excited
about Brian capitulating
in selling sciences.
Well, be sure to go through
the Jupiter notebook
because I would love for you
to actually get that certificate
of completion.
It's that carrot in front of the stick
that keeps us motivated
to actually finish this course
in its completion.
And I know post you obviously
know a whole lot about Bitcoin
and have been using this book
as a reference.
But you know it hits different
when you really like exhaust
every exercise.
It's so, so, so satisfying.
For me, for example,
with programming Bitcoin
and mastering Bitcoin
with Andreas Antonopoulos
and he has his own programming book
which doesn't go through
all of the math
as in-depth as this book does.
But I use these books
as reference, right?
It's very different
from going through
every single exercise
and actually implementing it yourself.
Okay, Brian Portland Topher post
Captain Boatface.
Any, any more thoughts?
I do got to jump.
I have some work to complete
before tomorrow morning
and I wanted to say
thank you so much for hosting
a great space.
I hope everybody learned
something by being here.
I know that as Brian said
it may sound like Greek
but if you can ask questions
DM me or I'll ask questions
or most importantly
get Jimmy Song's Jupyter Notebook
or get the book itself
and just start learning from that
because though you will learn a lot
through just osmosis
in these spaces
actively applying yourself
and really kind of doing things
with this above listening
will be the key to success
and understanding more about Bitcoin
and I think also the nice part too
is now that the kind of
two fundamental building blocks
have been built now
so you have elliptic curves
and you have finite fields
I think things accelerate
in terms of the fundness really quick
so getting out of just kind of boring math
into more of the actual programming
and how to apply this to Bitcoin
and like the question everybody
keeps jumping to
how does it make the private keys
or public keys
from the private keys
so I look forward to that.
Yeah I agree, I agree.
This the first two chapters
I think are probably the most dry
because we haven't really done
like Bitcoin stuff yet
and we're going to start doing Bitcoin stuff
and we're going to start learning
how to build our own Bitcoin transactions
from scratch
and how freaking cool is that.
I got to ask
is this an attack on Bitcoin?
I think everything is lately right?
Accelerating fundness
is an attack on Bitcoin.
Learning how to use Bitcoin
is an attack on Bitcoin.
Awesome guys
well thank you so much for joining
Quick question, I'm sorry
I just had a question probably to buy it.
The Jupyter Notebook, is it on the GitHub?
Absolutely.
So you're going to fork or clone the GitHub
and then you're going to run
the Jupyter Notebook on your local host
and what that's going to do
is it's going to run a server
that will allow you to run the Notebook
in a web browser.
Now Portland being the DevOps engineer
that he is, decided to containerize it
and make it available
to all of his devices everywhere.
I didn't do that.
Man loves Docker.
The Docker is the thing.
Seriously how do you do that, how?
Oh there's actually
I didn't Dockerize it.
Somebody else has already done the hard work
and I just literally took the repo
and followed the instructions
which were about five lines
but here's why it's just saying
having the Dockerized version
if you have a host that is constantly on
is so nice
because you don't ever have to start up
the instance of the app.
You don't ever have to type in Jupyter
or whatever to get it started.
I've never even typed in Jupyter Notebook
or whatever ever.
I just go to the website.
It's literally hosted 24 seven
anytime I need.
I just type in my password
I have access to all my Jupyter Notebooks.
Everything right there.
I can just start running things right away.
I don't have to basically
don't have to do extra steps.
So I just want to add things
that give men feeling the power
is not running Jupyter Notebook command.
Jupyter Notebooks are by far
and away the greatest feature
in the Python language.
But Docker is the answer
and I'll never forgive for it.
Okay okay why is Docker cancer?
Just three reasons.
Uh overhead.
Yeah okay fair enough.
Or miss overhead.
Extra execution environment baggage.
Owned by a fucking company.
The company thing doesn't bother me.
I think that Docker is a really,
really stellar example
of an open source corporation
that's done like tremendously good
and valuable work.
So like I would apply Docker as an entity
to like the end of the earth.
I think they've done an amazing job.
Dude just switch over to Nick already.
Come on Portland you know.
I just don't want to Dockerize everything.
I just want to build shit.
I just want to download it and build it.
I just don't want to do it.
You do a Docker,
do you just download it and just
spin it up.
That's I guess I would say that
everything has a time and place right.
Like the best tool for the job.
And no not everything needs to be
Dockerized etc.
But in cases where I literally
can clone somebody's repository
and do Docker compose up
and then get a Jupyter Notebook server
spooled up.
Yeah I'll do that.
That's fine.
I don't need massive performance.
I need to run Jimmy Song's notebooks
and I also want an environment
to do fun stuff in another example
where Docker works pretty good
is like isolating things
way from an actual host.
So if I just install everything locally
everything else is exposed.
If I Dockerize it well.
It's all in its own little container.
That's kind of nice.
And the last thing is
I actually run my own email server
and I literally just did it
with a Docker container.
There's Docker mail server
and I'm just saying like it's
really nice sometimes
for the right tasks
when something requires
a bunch of configuration
and somebody's already got
kind of that golden sample
built up for you
and you just want to plug in
your own like magic keywords
or magic variables to make it go.
And that's what I did with the email server.
I didn't use that.
Yes you're right.
Every Docker maxis and mix
OS maxis it just hasn't fact.
Yes no I agree.
I just haven't taken the time
No I just haven't taken the time
to learn it yet.
So with that said yeah.
Nix is coming soon
but just right now I have learned.
No I think for commercial
production environments
I think Docker is a really amazing tool.
The problem is that a lot of us
don't have commercial
commercial environment solutions
and we don't want to deal
with stupid Docker.
The biggest overhead for Docker
is development I think
in terms of just getting stuff done
because have you tried debugging
container to figure out
what's going wrong.
You're going to have a bad time.
So but yeah in terms of getting things
basically something you basically
debugged already it's good to go
and just basically containerizing it
so anybody that knows that type
and Docker compose up can do it.
That's a time and place for everything.
And yes Nix is probably better
in every case.
I just haven't learned it yet.
Hey I actually don't know
if I even agree with that one.
Okay there's also pot man
and some other things too right.
Like you could don't
shut up Nix.
Do Nix match any virtual environment
or is it just Docker specifically?
It's any virtual environment.
So does that include Python?
Yes I hate V and V.
Wait you don't like virtual environments?
Dude it's a it's a crutch.
It's a fucking crutch
because Python has dog shit
dependency management.
Okay I use virtual environments all the time
and I'm very very happy with them
No it works.
It's straight up
like it's Python dash M.
Oh yeah no they they definitely work
and I don't even like
I don't even really have a V.
For them it's just like
it's a funny Python.
Like everything's a fucking V and V.
To Rust and Lightning
in this course.
I'm just curious.
So no this course is just going
to be Python and Bitcoin.
Layer one we're not going to talk
about Rust and we're not going to
talk about Lightning.
We got to do what we got to do.
Wait so does it get into
does it get into like
actually like programming
and Bitcoin core like contributing
to those to the Bitcoin core
Git repo or like
just constructing transactions
and Bitcoin scripts and stuff like that.
At the end of the
at the end of the
Bitcoin scripts stuff.
I just want to figure I want to
figure out how to fucking
create an op cat script
that's going to be bigger
than Ryan dolls.
He's already working
on the next corner.
I know that he's already up
to 30 or something.
He figured out how to do
covenants.
He figured out how to do covenants
with like 30 op cats.
He's done a very limited
his goal is to do CTV,
which like if we're tracking
what he's doing right now,
it should be like something
along the lines of like three
or four times the current
sub size to do CTV.
I think I don't know.
We'll find out.
Yes, but the script,
the script is fucking hilarious.
It's literally just op
cat op cat op cat
like 40 times over and over.
Meds will literally implement
covenants using 40
op cats instead of going to therapy.
Is it that that's the underlying
problem with that therapy?
Just saying.
Is the amount of like
basically the amount of data
required to achieve
the same functionality
as something like CTV
and the processing burden
of op cat, right?
Like that's the point of
contention.
Why it would
sandwiches are for a break.
Oh, I think it's reasonable.
Oh, I don't know.
What were you saying?
So, like, why was
op cat removed?
I haven't still gotten a clear
answer why it was taken away
other than the implications
of having it.
The original inflation
ball trigger.
First off, we don't know.
Like objectively, we don't have
like actual information
about why it was made.
But I think the strongest
assumption and the most common
assumption is that
following the initial
inflation bogs,
Satoshi just deactivate
all the op codes
that weren't in use, right?
If you aren't using this,
we're turning it off, right?
And this was like
kind of a hair trigger response
to there being a bug
in a op code, right?
And what seemed to be
like the watershed
that followed that.
So, like, I think it's fair
to say, like, a lot of people
might want to say, like, oh, well,
op cat was part of
Satoshi's original design.
And Satoshi himself even
explicitly says
a couple of different times
that, like, we should support
all possible transaction
pipes and stuff like this.
Like, that's cool.
That's great.
But, like, the watershed
that followed was like,
you know, this conservative
design space.
Like, a sense of, like,
not having the expressive mess.
And so now, yeah.
Like, fast forward 14 years
or whatever, 13 and a half years.
And we're having this conversation
about, you know,
should we reactivate
some or any of these op codes?
Well, okay.
In terms of reactivation,
what method would be used?
Would you soft fork
another op code
into doing that functionality?
Or could you actually,
without hard forking,
re-expand the rule set
so that op cat
were reactivated per se?
Because I think that would be
hard fork according to any node
on the network right now.
Most of these...
Okay, so op cat in particular
is being proposed as...
I think it's op success 128
in tap script.
So this is a proposal
to activate op cat
from tap script.
Okay, that makes sense.
Yeah, if you wanted
to activate it as an op-not,
I think you heard.
So like, in theory,
you could activate it
in the same op-not slot
that it was previously in.
And the original Stoshe client
would accept it.
But there had been hard forks.
There's been two,
at least two,
that I'm aware of,
hard forks in the release
of the initial Stoshe client
So like that theory breaks down.
Interesting.
Okay, I gotta jump out.
Thank you so much for hosting.
Appreciate it, guys.
Thanks Portland.
Thanks as always.
Love the slides.
Okay, we'll see you next week
when we talk about
elliptic curve cryptography
where we combine elliptic curves
and finite fields.
So excited.
What's up, Shelly?
So I guess,
I don't know.
What do you guys want to do?
Does somebody want to open up
an after-party room
where we continue talking
about nerdy stuff?
I have to get to bed.
It's crazy.
Don't say it's my brain.
I'll open up one via you.
Yeah, go ahead and open up
an after-party room.
And let's just continue
nerding out about Bitcoin tech.
And for everybody
that came today
and learned about elliptic curves,
I'm so happy that you came.
And I can't really talk about-
Cheers to you guys
for doing these classes.
Elliptic curve cryptography.
Thanks post.
Bye, guys.