Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
addScaleStore works
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 1, 2023
1 parent c04a0ff commit 3fa8996
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Initially, all tokens are owned by the contract deployer, which can be represent

### `balanceOf`

To find the balance of an address, iterate over all tokens and call `ownerOf`, counting the number of matches along the way.
To find the balance of an address, iterate over all tokens and call `ownerOf`, counting the number of matching addresses along the way.

### `transfer`

Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ remappings = [
]

fs_permissions = [
{ access = "read", path = "./test/mocks/PolynomialWrappers.huff" }
{ access = "read", path = "./src/test/Polynomial.t.huff" }
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#define constant COEFF_SIZE = 0x1
#define constant ORDER = 0xd

#define constant P_SLOT = 0xbabedeadcafe

// evaluate a point at basis
#define function eval(uint256 basis, uint256 point) view returns (uint256 evaluation)
// add two basis polynomials and evaluate the point
Expand All @@ -21,6 +19,9 @@
// scale the stored polynomial
#define function scaleStore(uint256 scale) view returns ()

// polynomial offset for P
#define constant P_SLOT = 0xbabedeadcafe

#define macro MAIN() = takes (0) returns (0) {
0x00 calldataload 0xE0 shr
dup1 __FUNC_SIG(eval) eq eval jumpi
Expand Down
36 changes: 14 additions & 22 deletions test/Polynomial.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract PolynomialTest is Test {
bool constant VERBOSE = false;

function setUp() public {
string memory code = vm.readFile("test/mocks/PolynomialWrappers.huff");
string memory code = vm.readFile("src/test/Polynomial.t.huff");
polynomial = IPolynomial(HuffDeployer.deploy_with_code("util/Polynomial", code));
}

Expand Down Expand Up @@ -56,7 +56,18 @@ contract PolynomialTest is Test {
}
}

// function test_Foo() public {
// uint256 expected = 0xE;
// uint256 actual = 0xA;
// assertEq(actual, expected);
// }

function test_AddScaleStore() public {
// stored poly is initially constant zero
for (uint256 tokenId = 0; tokenId < TOTAL_SUPPLY; ++tokenId) {
assertEq(polynomial.evalStore(tokenId), 0);
}

uint256 basisToAdd = 0;
polynomial.addStore(basisToAdd);

Expand All @@ -66,30 +77,11 @@ contract PolynomialTest is Test {
for (uint256 basis = 0; basis < TOTAL_SUPPLY; ++basis) {
VERBOSE ? console.log("") : ();
for (uint256 tokenId = 0; tokenId < TOTAL_SUPPLY; ++tokenId) {
uint256 expected = 0;
if (basisToAdd == tokenId) {
expected++;
}
if (basis == tokenId) {
expected++;
}
expected = scale * expected;
expected = expected % ORDER;
uint256 expected = basisToAdd == tokenId ? scale % ORDER : 0;
assertEq(polynomial.evalStore(tokenId), expected);
// VERBOSE ? console.log("BASIS(0) *", scale, "=", scaledEval) : ();
VERBOSE ? console.log(basis, tokenId, expected) : ();
}
}
console.log("P(0)", polynomial.evalStore(0));
console.log("P(1)", polynomial.evalStore(1));
console.log("P(2)", polynomial.evalStore(2));

console.log("P(0) + L1(0)", polynomial.evalStore(0));
console.log("P(1) + L1(1)", polynomial.evalStore(1));
console.log("P(2) + L1(2)", polynomial.evalStore(2));

console.log("5(P(0) + L1(0))", polynomial.evalStore(0));
console.log("5(P(1) + L1(1))", polynomial.evalStore(1));
console.log("5(P(2) + L1(2))", polynomial.evalStore(2));
}
}

Expand Down

0 comments on commit 3fa8996

Please sign in to comment.