Learn how to implement the precompile in `contract.go`
In this section, we will go define the logic for our CalculatorPlus precompile; in particular, we want to add the logic for the following three functions: powOfThree, moduloPlus, and simplFrac.
For those worried about this section - don't be! Our solution only added 12 lines of code to contract.go.
Before we define the logic of CalculatorPlus, we first will examine the implementation of the Calculator precompile:
Although the code snippet above may be long, you might notice that we added only four lines of code to the autogenerated code provided to us by Precompile-EVM! In particular, we only added lines 19, 48, 79, and 80. In general, note the following:
Structs vs Singular Values: make sure to keep track which inputs/outputs are structs and which one are values like big.Int. As an example, in nextTwo, we are dealing with a big.Int type input. However, in repeat, we are passed in a input of type struct RepeatInput.
Documentation: for both Calculator and CalculatorPlus, the big package documentation is of great reference: https://pkg.go.dev/math/big
Now that we have looked at the implementation for the Calculator precompile, its time you define the CalculatorPlus precompile!
Likewise, for powOfThree, we want to define the logic of the function in the custom code section. However, note that while we are working with an output struct, our input is a singular value. With this in mind, take a crack at implementing powOfThree: