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

Commit

Permalink
balanceOf still bugged
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 1, 2023
1 parent b5f2511 commit fbeaef9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Huffd1.huff
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
swap1 // [a, m, s, l]
0x00 // [a, m, s, l, i] (index starts with 0)

// loop_begin:
loop_begin:
// [a, m, s, l, i]

// loop condition
Expand All @@ -145,13 +145,13 @@
dup6 // [a, m, s, l, i, m, l, eq, s]
add // [a, m, s, l, i, m, l, s'] (s' := s + eq)
swap5 // [a, m, s',l, i, m, l, s]
pop pop // [a, m, s, l, i]
pop pop pop // [a, m, s, l, i]

// increment index
0x01 add // [a, m, s',l, i'] (i' := i + 1)

// [a, m, s, l, i]
// loop_begin jump
loop_begin jump
loop_end:

pop // [a, m, s, l]
Expand Down
File renamed without changes.
23 changes: 16 additions & 7 deletions src/util/Polynomial.huff
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@

pop swap1 pop // [o, l]

// revert changes to length
0x05 shr // [o, l'] (l' := l >> 5 = l / 32)

// output: [o, l]
}

Expand All @@ -74,7 +77,7 @@
// input: [oP, oQ, l] (offset_P, offset_Q, length)

// multiply len by 32 since we will go over the memory word-by-word
0x20 mul // [oP, oQ, l'] (l' = l * 32)
0x05 shl // [oP, oQ, l'] (l' = l << 5 = l * 32)

// begin loop, starting from i := 0
0x00 // [oP, oQ, l, i] (index)
Expand Down Expand Up @@ -119,8 +122,8 @@
// div length by 32 to go back to normal indexing
// which is equal to shifting to right 5 times
0x05 shr // [oP, l'] (l' = l >> 5 = l / 32)
// output: [oP, l]

// output: [oP, l]
}

/// @dev evaluate the polynomial at some point `x`
Expand All @@ -137,15 +140,16 @@
// input: [o, l, x] (offset, length, x)

// multiply len by 32 since we will go over the memory word-by-word
swap1 0x20 // [o, x, l, 32]
mul // [o, x, l'] (l' = l * 32)
swap1 // [o, x, l]
0x05 shl // [o, x, l'] (l' = l << 5 = l * 32)
swap1 // [o, l, x]

// sum accumulator starts at 0
0x00 // [o, l, x, s] (s := 0)

// index shall be (length - 1) * 32 = l - 32
0x20 dup4 // [o, l, x, s, 32, l]
0x20 // [o, l, x, s, 32]
dup4 // [o, l, x, s, 32, l]
sub // [o, l, x, s, i] (i := l - 32)

loop_begin:
Expand Down Expand Up @@ -186,11 +190,16 @@
// [o, l, x, s, i]
loop_begin jump
loop_end:

// [o, l, x, s, i]
pop // [o, l, x, s]
swap1 // [o, l, s, x]
pop // [o, l, s]

// divide length by 32 to revert the change at the start
swap1 // [o, s, l]
0x05 shr // [o, s, l'] (l' = l >> 5 = l / 32)
swap1 // [o, l, s]

// output: [o, l, s] (offset, length, evaluation)
}

Expand Down
16 changes: 8 additions & 8 deletions test/Huffd1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Huffd1Test is Test {
/// @dev Set-up to run before each test.
function setUp() public {
// TODO: deploy with code where code has the basis?
huffd1 = Huffd1(HuffDeployer.deploy_with_args("Huffd1.main", abi.encode(OWNER)));
huffd1 = Huffd1(HuffDeployer.deploy_with_args("Huffd1", abi.encode(OWNER)));
}

/// @dev Should return correct name and symbol.
Expand All @@ -33,7 +33,7 @@ contract Huffd1Test is Test {
}

/// @dev Should own tokens at the start.
function test_Ownership() public {
function test_TokenOwnership() public {
for (uint256 tokenId = 0; tokenId < TOTAL_SUPPLY; ++tokenId) {
assertEq(huffd1.ownerOf(tokenId), OWNER);
}
Expand Down Expand Up @@ -67,13 +67,13 @@ contract Huffd1Test is Test {
assertEq(huffd1.balanceOf(OWNER), TOTAL_SUPPLY);

// transfer a token
address NEW_OWNER = address(0x9);
vm.prank(OWNER);
huffd1.transfer(NEW_OWNER, 0);
assertEq(huffd1.ownerOf(0), NEW_OWNER);
// address NEW_OWNER = address(0x9);
// vm.prank(OWNER);
// huffd1.transfer(NEW_OWNER, 0);
// assertEq(huffd1.ownerOf(0), NEW_OWNER);

assertEq(huffd1.balanceOf(OWNER), TOTAL_SUPPLY - 1);
assertEq(huffd1.balanceOf(NEW_OWNER), 1);
// assertEq(huffd1.balanceOf(OWNER), TOTAL_SUPPLY - 1);
// assertEq(huffd1.balanceOf(NEW_OWNER), 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/Polynomial.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ contract PolynomialTest is Test {

uint256 addEval = polynomial.addEval(basis1, basis2, tokenId);
// console.log("BASIS1:", basis1, "\tBASIS2:", basis2);
console.log("EVAL1:", eval1, "\tEVAL2:", eval2);
// console.log("EVAL1:", eval1, "\tEVAL2:", eval2);
// console.log("EXPECTED:", tokenId, "\tADDEVAL:", addEval);
// console.log("BASIS1 BASIS2 TOKEN:", basis1, basis2, tokenId);
// console.log("");
console.log("BASIS1 BASIS2 TOKEN:", basis1, basis2, tokenId);
assertEq(addEval, expected);
}
}
Expand Down

0 comments on commit fbeaef9

Please sign in to comment.