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

Commit

Permalink
Merge pull request #20 from pentagonxyz/feature/erc721
Browse files Browse the repository at this point in the history
feat: ERC721
  • Loading branch information
refcell authored Sep 14, 2022
2 parents 7e35b0d + 52f1854 commit 64733fc
Show file tree
Hide file tree
Showing 36 changed files with 1,031 additions and 152 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ math
├─ Trigonometry — "Basic trigonometry functions where inputs and outputs are integers"
tokens
├─ ERC20 — "Modern and gas efficient ERC20 + EIP-2612 implementation"
├─ ERC721 — TODO — "Modern, minimalist, and gas efficient ERC721 implementation"
├─ ERC721 — "Modern, minimalist, and gas efficient ERC721 implementation"
├─ ERC1155 — "Minimalist and gas efficient standard ERC1155 implementation"
├─ ERC4626 — TODO - "Minimal ERC4626 tokenized Vault implementation"
utils
Expand Down
18 changes: 11 additions & 7 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ libs = ['lib']
ffi = true
fuzz_runs = 1000
fs_permissions = [
{ access = "read", path = "./test/data-structures/mocks/InstantiatedArrays.huff" },
{ access = "read", path = "./test/data-structures/mocks/InstantiatedHashmap.huff" },
{ access = "read", path = "./test/data-structures/mocks/ArrayWrappers.huff" },
{ access = "read", path = "./test/data-structures/mocks/HashmapWrappers.huff" },

{ access = "read", path = "./test/math/mocks/FixedPointMathWrappers.huff" },
{ access = "read", path = "./test/math/mocks/SafeMathWrappers.huff" },
{ access = "read", path = "./test/math/mocks/MathWrappers.huff" },
{ access = "read", path = "./test/math/mocks/TrigonometryWrappers.huff" },

{ access = "read", path = "./test/tokens/mocks/ERC1155Wrappers.huff" },
{ access = "read", path = "./test/tokens/mocks/MockERC20.huff" },
{ access = "read", path = "./test/tokens/mocks/ERC20Mintable.huff" },
{ access = "read", path = "./test/tokens/mocks/ERC20Wrappers.huff" },
{ access = "read", path = "./test/tokens/mocks/ERC721Wrappers.huff" },
{ access = "read", path = "./test/tokens/mocks/ERC20MintableWrappers.huff" },

{ access = "read", path = "./test/utils/mocks/BitPackLibWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/ErrorsMock.huff" },
{ access = "read", path = "./test/utils/mocks/ErrorWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/JumpTableUtilWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/MerkleProofLibWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/MulticallableWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/ReentrancyGuardMock.huff" },
{ access = "read", path = "./test/utils/mocks/LibBitWrapper.huff" },
{ access = "read", path = "./test/utils/mocks/ReentrancyGuardWrappers.huff" },
{ access = "read", path = "./test/utils/mocks/LibBitWrappers.huff" },
]
remappings = [
"forge-std/=lib/forge-std/src/",
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 2 files
+1 −1 LICENSE-APACHE
+1 −1 LICENSE-MIT
2 changes: 1 addition & 1 deletion lib/foundry-huff
Submodule foundry-huff updated 1 files
+14 −14 src/HuffConfig.sol
5 changes: 5 additions & 0 deletions src/data-structures/Arrays.huff
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/// @title Arrays
/// @author exp-table <https://github.com/exp-table>
/// @notice Array utility library for Solidity contracts
/// @notice Adapted from <https://github.com/huff-language/huff-examples/blob/main/erc20/contracts/utils/HashMap.huff>

// Sets an array in storage from calldata.
// Note that since no assumptions is made regarding the context in which
// this function is called, the position of the encoded array in the calldata
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/Hashmap.huff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// @title HashMap
/// @author Andreas Bigger
/// @author asnared <https://github.com/abigger87>
/// @notice A Minimal HashMap based off <https://github.com/huff-language/huff-examples/blob/main/erc20/contracts/utils/HashMap.huff>

// Given a piece of data (ie an address), hash it, generating the storage slot for a hashmap.
Expand Down
5 changes: 3 additions & 2 deletions src/math/Math.huff
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// @title SafeMath
/// @author https://github.com/kadenzipfel
/// @notice Math module based off https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol
/// @author kadenzipfel <https://github.com/kadenzipfel>
/// @notice Math module over Solidity's arithmetic operations
/// @notice Adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol

#define function sqrt(uint256) pure returns(uint256)
#define function max(uint256, uint256) pure returns(uint256)
Expand Down
5 changes: 3 additions & 2 deletions src/math/SafeMath.huff
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// @title SafeMath
/// @author https://github.com/kadenzipfel
/// @notice SafeMath module based off https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol
/// @author kadenzipfel <https://github.com/kadenzipfel>
/// @notice Math module over Solidity's arithmetic operations with safety checks
/// @notice Adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol

// Interface
#define function safeAdd(uint256,uint256) pure returns (uint256)
Expand Down
17 changes: 8 additions & 9 deletions src/tokens/ERC1155.huff
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
#include "../utils/ERC1155Receiver.huff"
#include "../utils/CommonErrors.huff"

// Stateful Function Interface
// Function Interface
#define function mint(address,uint256,uint256,bytes) nonpayable returns ()
#define function batchMint(address,uint256[],uint256[],bytes) nonpayable returns ()

#define function burn(address,uint256,uint256) nonpayable returns ()

#define function batchMint(address,uint256[],uint256[],bytes) nonpayable returns ()
#define function batchBurn(address,uint256[],uint256[]) nonpayable returns ()

#define function isApprovedForAll(address,address) view returns (bool)
#define function setApprovalForAll(address,bool) nonpayable returns ()

#define function safeTransferFrom(address,address,uint256,uint256,bytes) nonpayable returns ()
#define function safeBatchTransferFrom(address,address,uint256[],uint256[],bytes) nonpayable returns()
#define function setApprovalForAll(address,bool) nonpayable returns ()

// Accessor Function Interface
#define function getApproved(uint256) view returns (address)
#define function isApprovedForAll(address,address) view returns (bool)
#define function balanceOf(address,uint256) view returns (uint256)
#define function balanceOfBatch(address[],uint256[]) view returns (uint256[])

Expand Down Expand Up @@ -542,8 +541,8 @@
0x80 // [&ret]

// Get lengths of dynamic arrays, duplicate in prepare to compare
0x24 calldataload 0x4 add dup1 // [&ids, &ids, &owners, &owners, &ret]
0x04 calldataload 0x4 add dup1 // [&ids, &ids, &ret]
0x24 calldataload 0x4 add dup1 // [&ids, &ids, &ret]
0x04 calldataload 0x4 add dup1 // [&ids, &ids, &owners, &owners, &ret]

// compare lengths
swap2 // [&owners, &ids, &ids, &owners, &ret]
Expand Down
35 changes: 7 additions & 28 deletions src/tokens/ERC20.huff
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @notice Modified from Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)

// Imports
#include "../utils/Errors.huff"
#include "../utils/NonPayable.huff"
#include "../data-structures/Hashmap.huff"

// TODO: Add revert strings (and related tests)

// Interface
#define function allowance(address,address) view returns (uint256)
#define function approve(address,uint256) nonpayable returns () // these returns sb updated
Expand Down Expand Up @@ -398,12 +399,14 @@
expired:
0x5045524D49545F444541444C494E455F45585049524544000000000000000000 // ["PERMIT_DEADLINE_EXPIRED"]
0x17 // [23 (length), "PERMIT_DEADLINE_EXPIRED"]
REVERT_WITH_REASON(0x00)
0x00 // [0, 23 (length), "PERMIT_DEADLINE_EXPIRED"]
REQUIRE()

invalidSigner:
0x494E56414C49445F5349474E4552000000000000000000000000000000000000 // ["INVALID_SIGNER"]
0x0e // [14 (length), "INVALID_SIGNER"]
REVERT_WITH_REASON(0x00)
0x00 // [0, 14 (length), "INVALID_SIGNER"]
REQUIRE()
}

/// @notice Takes an address off the stack, returns the current nonce for that address onto the stack.
Expand Down Expand Up @@ -530,30 +533,6 @@
log3 // []
}

/// @notice Reverts if the call has a non-zero value.
#define macro NON_PAYABLE() = takes (0) returns (0) {
callvalue iszero // [msg.value == 0]
novalue jumpi // []

// Revert with a "NON_PAYABLE" message
0xb4e4f4e5f50415941424c4500000000000000000000000000000000000000000 // ["NON_PAYABLE"]
0x1b // [11 (length), "NON_PAYABLE"]
REVERT_WITH_REASON(0x00) // []

novalue:
}

/// @notice Revert with a string reason
#define macro REVERT_WITH_REASON(mem_ptr) = takes (2) returns(0) {
// NOTE: String must be < 32 bytes
// [len, "str"]
[ERROR_SIG] <mem_ptr> mstore // [len, "str"] 0x00 error sig
0x20 <mem_ptr> 0x04 add mstore // [len, "str"] 0x00 error sig 0x04 offset
<mem_ptr> 0x24 add mstore // ["str"] 0x00 error sig 0x04 offset 0x24 len
<mem_ptr> 0x44 add mstore // [] 0x00 error sig 0x04 offset 0x24 len 0x44: "string"
0x64 0x00 revert
}


// Function Dispatching
#define macro MAIN_ERC20() = takes (1) returns (1) {
Expand Down
Loading

0 comments on commit 64733fc

Please sign in to comment.