Interview With A Hex Dev: Part 2— The Engineering Behind Hex Shares & Staking

Vince C.
14 min readFeb 16, 2021

This is a continuation of the interview between Dev Kyle Bahr and Kryptosparbuch. In Part 2, they discuss the mechanics behind passive compounding in the Hex share price system.

Kryptosparbuch: So we talked about the security today a lot. Now it’s time to move away from that, even though it is a really important topic and all our German followers really love those questions. That’s why we took so much time for that, but now let’s go on deeper into Hex.

The most prominent thing you are known for is the share rate. You came up with the share rate, right? And how did you come up with it in the first place?

Kyle: I’m not going to take full credit for that, though I think I understand it the best. A little bit of history: the problem that this started with is the claim that longer Hex stakes always pay better than shorter stakes.

There’s the fundamental claim and even with all the changes that was the core proposition of the project: you lock up your coins and if you lock longer you are rewarded more than someone who locks shorter.

It has to work that way.

People must be completely confident that this works, otherwise the core principle of locking up your coins for a long time, reducing market supply, price go up, all those “Richard-isms” will be undermined. If somebody finds a way to stake shorter so that they have liquid Hex to sell anytime they want and they have an advantage over people who’ve locked up and given up that timing advantage, then all the faith in the project is gone.

That core claim that longer pays better has to work, and we looked at a zillion ways to make that happen. There were all kinds of mechanisms to defer when shares pay. We’re going to talk about the simulation later, but frankly the simulator, once it revealed some particular problem, I almost entirely repurposed it to experiment on how to make this LongerPaysBetter thing work.

Early on, someone in the community (I think his handle was Greg,and he’s a very sharp dude) suggested doing some simulations. He did a lot of the same simulations I did, though not as random but just simpler ones, and he said:

“Well, you should just do compounding. Just do compounding like how a normal compounding interest investment works.”

We looked at that and it was super-complicated about how to have people interact with the contract all the time, like manually compounding because nothing is automatic on Ethereum. You can’t automatically compound everybody, so then it just becomes very high-touch, which just runs counter to the idea that you just stake and then forget about it. If you have to be engaged and constantly hitting a button, that doesn’t work.

He proposed that you could do the reverse by just basically slashing the benefit that latecomers get, and that was the first way that the idea was phrased. He gave some examples, like if you slash the reward that latecomers get, you can achieve this compounding effect without touching. So that was point one: how you can reduce the benefit to later people and get the same compounding effect as if everybody is touching the contract all the time.

But then that fizzled out because it didn’t handle bonuses, it didn’t do anything, and it didn’t quite work. Also, it showed really extreme returns differences, given the rules at the time. When I mentioned before that the BigPayDay used to be split over every day, this created a situation.

Those two things combined together — where early people are rewarded daily and if you come later, you’ve missed out on some number of days of reward and you’re slashed so that early people are compounded — showed this ridiculous difference:

A Day-1 person could make a 1000x over the first year and a Day-2 person would make 500x.

So one day, if you just hear about the project a day late, you lose about half versus the guy yesterday. There were a bunch of things about that original idea that didn’t work. Moving along, we were trying all kinds of different ideas. Richard kind of floated this idea of “highest ROI”. He said:

“Well, all we have to do to make sure that the new guys don’t get paid more than old guys is that the new guy has to basically buy the ROI of the old guy, and so if he has to buy in at some higher rate then that will naturally slash his benefit.”

Then we thought: “Okay, maybe we can put a price on shares”, because at first shares were just always 1:1. There was no conversion factor. It was always just:

  1. Take your Hex
  2. Directly convert to shares
  3. Then convert it back to Hex later

So we combined these two ideas and said:

“Okay, so we have some sort of price mechanism, there’s something about ROI. Maybe we can put those together and that will give us the effect we want.”

And yet, it still didn’t quite work. There were edge-cases where big, short stakes could beat long stakes when they shouldn’t have been able to. The dev who did all of the contract code that’s in production added the final element to correct for that one issue, which was changing the way that the ROI is calculated.

It’s not strictly ROI. It’s not comparing it to what you made before. It just looks forward and asks:

“If you re-stake under the same parameters, how do we keep your shares constant?”

That was the final correction that was needed to make this thing work in a very smooth way. There were a couple other tweaks in there. I think I tried it both when you start a stake versus when you end a steak. It’s actually not quite compounding as you would expect. It only happens on end stake rather than daily, so there’s no guarantee that you’re turning over the whole coin base everyday; it’s only when stakes end.

There’s a couple tweaks here and there, but with the original inspiration of “you can do this compounding by slashing newcomers”, we asked if we could key it off of ROI somehow. Then came the one refinement on that idea of changing ROI to only be forward-looking, meaning if you stake under the same parameters, it would just hold shares constant.

Then I wrote some proof-code in this tool called WolframAlpha to make sure that there’s no circumstance where that will be violated. The invariant is: you never get more shares than you started with under the same staking parameters.

We submitted that to the auditors, who had a math Ph.D. guy look it over, write it up in formal math and prove that it was so. It took about 6–8 months to come up with the right mechanism for share rate, and this is all because of that fundamental guarantee that longer stakes must always pay better than shorter stakes.

Kryptosparbuch: Awesome. You answered the question really thoroughly. You already answered all the questions I had about the share rate. Actually we have one more because it was very technical and some people in the chat now are new to Hex and not that far down the rabbit-hole. Could you please give us an example, because there is still the notion that the highest 5555-day stake will set the new Hex share price in 2036.

Kyle: I did gloss over the key difference from that, so let’s back up. The thing that has to be true is that short stakes will never beat long stakes, in terms of how much Hex they get back. So one way that you can hopefully and intuitively guarantee that, is if for example, I have 100 shares and you have 50 shares, it’s because I staked way longer than you did.

The way that we know for sure that you’ll never do better than me — meaning if you stake and then you re-stake again and again, and then it all adds up to the same time that I did — the way that we can know for sure that you’ll never gain ground on me is that if you restake for the same amount of time, your shares won’t go up.

Let’s imagine the opposite: if you have 50 shares and you know a trick to stake for a short period of time to get 51 shares, well then, you could just do that trick again and get 52, and do that trick again and get 53. So you’re gaining ground on me by doing something that we’re trying to discourage. I should always win if I stake for longer than you, for the same amount of Hex (principal).

I should be ahead of you forever, as long as I keep staking longer, meaning: My time comes up, I restake for that same long period, and no matter how many little stakes you get in-between, as long as you never get more shares each cycle or each iteration, then you can never catch up to me and the guarantee will hold, whether it’s for 100 days, 1000 days, or 5000 days.

We have a way to guarantee that you never gain ground. So, how do we do that? Well, the computation to figure out what you need to pay to get your shares, should always just be what you need to pay to get your shares back. If I cash in 50 shares, all I have to do is figure out what to charge you to get 50 shares back, and that’s easy because I know how much Hex you just got.

If you put in some amount of Hex and you get back 10% more, 10x more, 100x more or 80% more, or even 80% less because you have a penalty, I can figure out what price to charge you to get your shares back. So if you made 2x, well I just have to charge you double what I charged you last time, and then you’ll get exactly the same number of shares back. if you got 50%, I just need to raise the price 50%, etc.

No matter what you exit with I can just figure out what to charge you to get back in at exactly the same position. That way you’re not gaining ground, and you’re not necessarily losing ground, you’re just sort of repeating.

Now the trick with share rate is that in the case that I gave where, say you only get back 80% because you have a penalty I’m not going to lower the price for you. I’m just going to keep the price where it is. Or, if you make 50% and someone else has already doubled the price, I’m not going to lower the price for you. So you’re not able to buy back in at the same amount of Hex in the same time frame.

It’s really just about managing that price so that no one can ever get more shares for the same commitment. Just think of it that way The thing that is held constant is that a commitment yields this many shares, and then once you end your stake, that commitment of time has to yield the same number of shares, and we just compute the price to to make that true.

So even after 5555 days with a max size stake, somebody makes 100x and then they just take all those gains and they restake them for one day. Well, the next day they have made some amount of money.

Maybe it’s a 10th of a percent, but if you raise the price a 10th of a percent to match those gains it’s not the highest anyone’s made, even that they made yesterday. But, it means that they can’t gain ground on somebody who staked 5555 days halfway through their stake.

So, you have to think across long periods of time. If they staked on Day 1 and then someone else comes along in 5 years and stakes for 5555 days, then the original person shouldn’t be able to catch up to them either.

It needs to be constant for everyone, across all of time.

It’s not ROI. Just think of it as: the price changes to match and to keep the commitment constant.

Kryptosparbuch: Yes, it’s beautiful. I never thought that is was computed this way, that it’s forward-looking. I was thinking, the contract looked back on the data and then raised the share price, but it’s not like that. It checks for every single person, and no one can ever get more shares when they stake again. Then you have to look forward for the next possibility on what they could have done, just like in your example of re-staking for a single day, even.

Before we move on to the next section, you’re familiar with the future staking chart, right? Near the end of every year, in November or December, there is a large stake and we know from the beginning that those stakes were made in the first two weeks of the existence of Hex. Are those those stakes going to set a new share rate every year and will that lead to a spike in the share rate or not?

Kyle: Probably. It’s hard to say for certain but I think that’s right. The earlier you start and when you get out to fairly long time frames, the size sort of diminishes in value. It maxes it at 10% but you can match that with just an extra 6 months, the way that the math works out.

Kryptosparbuch: Yes, but you still get the 1.1x bonus multiplier for BiggerPaysBetter. That’s my background of thinking, it might spike for something below 10%, because if it’s always the biggest, longest, earliest stake and the max-out is 10%, the stake may earn 8–9% more than the stakes it’s competing with.

Kyle: Yes, your thinking on that is right. All I was trying to mention is not to scare people, because you can defeat that relatively small advantage by just pushing out 6 months on your commitment. That’s all I mean, is that you can overcome it relatively easily and that’s by design.

Kryptosparbuch: Yeah, the background is that if somebody asks me how to build up a ladder, and I want to build 15 individual annual stakes, one for each possible year on the timeline, then I am recommending ending your stakes before that large stake.

The first reason for that is it could be sold afterwards, and the second reason is because if you want to restake, and if you end stake before that large one you can restake for a better share price.

Kyle: Yeah, that’s good. It feels a bit like a micro-optimization because it will be a few percent, but that adds up. That’s reasonable advice to give people.

Kryptosparbuch: I think it adds up to a lot. I’m just comparing the Day-1 staker who paid 10,000 Hex for 1 T-Share, and today you have to pay 16,000 Hex for one T-Share, so it’s 60% higher already, right? This is paid out daily and I think it just makes it out to be a lot for the next 15 years.

Kyle: Yeah, it definitely adds up, especially if you’re going long, because then you’ve subtracted 8% of your total.

Kryptosparbuch: Yes, the idea of that is if I have an annual ladder with 15 stakes, after each year I can end stake it and push the principle as a restake to the end of my ladder.

Kyle: Yeah, I’ve seen that system. I think that that works well. There’s a little bit of ramp up time to get yourself on this cadence, but then you’re always having max bonus. Basically, you build up to the max bonus forever.

Kryptosparbuch: Exactly. That’s the idea behind it, yeah. So when we started talking about the share rate, you mentioned somebody in the community said that you could just do compounding interest and then the user would have to interact with the smart contract every day, but this was not feasible. Yet still, we have compounding interest in Hex right? Can you explain how the compounding works?

Kyle: Sure! There’s two ways to generate the same curve. A compounding curve starts by looking very flat, and then it starts to go in a “J”- shape up.

The reason it does that is the math for compounding is all about doubling time. That means the time it takes to double your value and that just starts to look more extreme.

If you go from 1/2 to 1, to 2, to 4,to 8, to 16, the jumps start to get bigger because doubling looks more dramatic, but the other way that you can simulate that is: you start at 1, and then you do the compounding logic as a fraction of 1 instead.

So instead of making the number bigger in that pattern, you make the number smaller in the opposite pattern. Does that make sense?

Kryptosparbuch: Yeah, before the update on the Hex frontend, the share rate was displayed where we started at 1 Hex equals 100 million shares, and now after the change, it’s displaying it as Hex price per T-Share.

Kyle: Right, because you’re less than 1, and in fact every stake that ended, reduced it a little bit. It became much more noticeable after BigPayDay, but it was happening all the timeand it looks nearly linear, but if you zoom out, you see that you’re actually going on a schedule of halvening time, rather than doubling time.

It’s a fairly long cycle, which I’m sure we’ll talk about — average stake length — a little bit later , but the effect of compounding works if you do it that way, where you reduce newcomers on the same schedule that somebody would be compounding if you did it the other way, with a very high-touch way.

So that’s what share rate is meant to mimic; instead of having somebody hit the button to compound themselves when somebody exits it tells the contract to reduce the shares per Hex by a little bit, and that’s going to mimic the curve, basically the inverse of the compounding curve. That’s how you get compounding: by reducing new people essentially on the same schedule that you would compound old people.

Kryptosparbuch: I think the compounding effect is one of the best things in Hex, with the share rate of course. Have you ever seen something like the share rate and share price working together in any other crypto? You can stake other crypto as well, but is there anything else like Hex?

Kyle: Nothing that I’ve seen, and granted I haven’t been super steeped in the thousands of projects out there. But I did look into an awful lot of them that were trying. The short answer is no. I’ve not seen anything done like this.

The schemes out there that are common: there’s two of them. One is that the network or the coin, is attempting to be proof-of-stake. The way that they do that is not through compounding and interest but essentially through validator rewards. You’re staking your coins and it gives you a small percentage chance to do some work for the network, and then when you do that work you’re rewarded.

The monetary policy is where they just set how much they reward people, but then it’s random, so over time you’ll experience maybe 5% gains or whatever, because you’ll get a chance to get the reward a small percentage of the time. Then they just tune that reward, and it mimics 5% interest.

So that’s one scheme. That’s not code-mediated, that’s not a smart contract, that’s network rules. It’s sort of like Bitcoin mining, which has network rules for what to reward miners.

The other scheme are these financial projects or products, something like Compound, or there’s a zillion of them. Compound is a fairly well-known one where again, a company is setting a rate based on supply-and-demand curves.

It’s not a smooth compounding interest function like what we have, where nobody has to touch it. Nobody has to do anything to it. It will just work forever. This is people trying to write an algorithm to fine tune a supply-demand curve. Actually, dYdX, which is a derivatives platform, do something like this. They have like an interest function that computes the instantaneous interest rate.

Again, it’s not a smooth curve. They have admin keys so they’ve swapped out this interest function as they’ve noticed people hacking the system. It’s still high-touch, by people making decisions on what the rate ought to be.

So in both cases, it may be programmatic, meaning that a computer program is deciding what to pay you, but it’s not something you could have a mathematician write a formula for, publish it and then it’s just true forever.

That’s what Hex has exactly.

In Part 3, coming soon, Dev Kyle discusses the Hex-per-T-Share payouts and more!

Original YouTube video link:
https://www.youtube.com/watch?v=RrFJzjoIwC0

--

--

Vince C.

Crypto lover, headphone audiophile, freelance musician.