huffd1
is a non-fungible token implementation in Huff, where the ownership of a token is given by the evaluation of a polynomial
Notice the final hexadecimals, which is where the name of the project comes from.
We could also use
The degree of the polynomial is equal to total supply - 1, so for
The stack comments are written in reverse order:
opcode // [top-N, ..., top-1, top] pop // [top-N, ..., top-1] 0x01 // [top-N, ..., top-1, 0x01]Be careful not to be confused!
We have a Sage script that can export the basis polynomials as a codetable.
// basis polynomials coefficients
#define table Basis {
// 0x...
}
// number of tokens
#define constant TOTAL_SUPPLY = 0xa
// number of bytes per coefficient
#define constant COEFF_SIZE = 0x14
// order of the finite field
#define constant ORDER = 0xffffffffffffffffffffffffffffffffffffffd1
Using these, we can load polynomials from the code table, and work with them using Polynomial.huff
.
Let's describe each function of huffd1
:
To find the owner of a token
Initially, all tokens are owned by the contract deployer, which can be represented by the constant polynomial that is equal to the owner address.
To find the balance of an address, iterate over all tokens and call ownerOf
, counting the number of matching addresses along the way.
To transfer a token
This operation results in multiplying the coefficients of MULMOD
, and afterwards summation of the coefficients of ADDMOD
.
Also note that
Simply do:
forge test
It shall test both the polynomial utilities and the huffd1
contract.