Chapter 1: Making the Kernel
In this chapter, you’ll learn to create and initialize the kernel, a hidden value inside the Walnut, and increment it by implementing a shake function. Estimated time: ~10 minutes.
Defining the kernel
The kernel is the hidden number inside the Walnut. Using Seismic’s suint256
type, the kernel is shielded on-chain. Open up packages/contracts/Walnut.sol
and define the kernel as a state variable and initialize it in the constructor:
Add a shake function
Next, let’s implement a function to increment the kernel. The shake function takes an suint256 parameter, _numShakes
which specifies the amount to increment the kernel by.
What's happening here?
Since shake
takes in an stype
as one of its parameters, it is key that no information about this parameter (in this case, the number of shakes) is leaked at any time during the function call. This means that the value of _numShakes
is known only to the function caller and is encrypted on-chain.
The function also updates a state variable (kernel
) and hence constitutes a state transition, which makes a call to this function a shielded write.
Last updated