Skip to content

Commit

Permalink
Not a good idea :(
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenioclrc committed Sep 1, 2023
1 parent d689853 commit d48d143
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ ButtplugTest:testSetOwner(address) (runs: 256, μ: 3351, ~: 3351)
ButtplugTest:testTokenUri() (gas: 3221)
ButtplugTest:testTotalMinted() (gas: 3156)
ButtplugTest:testTransfer() (gas: 3176)
GasbenchTest:testDeploy() (gas: 1109850)
GasbenchTest:testMint() (gas: 70402)
GasbenchTest:testMintMerkle() (gas: 102982)
GasbenchTest:testDeploy() (gas: 1005074)
GasbenchTest:testMint() (gas: 70654)
GasbenchTest:testMintMerkle() (gas: 103234)
46 changes: 23 additions & 23 deletions src/ERC721.huff
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
#define event ApprovalForAll(address,address,bool)

// Storage Slots
#define constant OWNER_LOCATION_MASK = 0xC0DE420C0DE420C0DE4200000000000000000000000000000000000000000000
#define constant BALANCE_LOCATION_MASK = 0xFFFFFFFFFFFF0000000000000000000000000000000000000000000000000000
#define constant OWNER_LOCATION = FREE_STORAGE_POINTER()
#define constant BALANCE_LOCATION = FREE_STORAGE_POINTER()
#define constant SINGLE_APPROVAL_LOCATION = FREE_STORAGE_POINTER()


Expand All @@ -59,7 +59,7 @@
/// @notice Returns the balance of the given address
#define macro BALANCE_OF() = takes (0) returns (0) {
0x04 calldataload // [account]
[BALANCE_LOCATION_MASK] or sload // [balance]
[BALANCE_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [balance]
0x00 mstore // []
0x20 0x00 return // []
}
Expand All @@ -68,7 +68,7 @@
/// @notice Returns the owner of the given token id
#define macro OWNER_OF() = takes (0) returns (0) {
0x04 calldataload // [tokenId]
[OWNER_LOCATION_MASK] or sload // [owner]
[OWNER_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner]
0x00 mstore // []
0x20 0x00 return // []
}
Expand Down Expand Up @@ -141,7 +141,7 @@
0x00 dup3 // [tokenId, from (0x00), to, tokenId]

// Check token ownership
[OWNER_LOCATION_MASK] or sload // [owner, from (0x00), to, tokenId]
[OWNER_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, from (0x00), to, tokenId]
unauthorized jumpi

// Give tokens to the recipient.
Expand Down Expand Up @@ -171,7 +171,7 @@
// Input stack: // [tokenId]

dup1 // [tokenId, tokenId]
[OWNER_LOCATION_MASK] or sload // [owner, tokenId]
[OWNER_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, tokenId]

// Check that the recipient is valid
dup1 iszero // [owner == 0, owner, tokenId]
Expand All @@ -182,14 +182,14 @@

// Reduce the balance of owner by 1
0x01 dup2 // [owner, 1, owner, to, tokenId]
[BALANCE_LOCATION_MASK] or sload // [balance, 1, owner, to, tokenId]
[BALANCE_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [balance, 1, owner, to, tokenId]
sub dup2 // [owner, balance-1, owner, to, tokenId]
[BALANCE_LOCATION_MASK] or
sstore // [owner, to, tokenId]
[BALANCE_LOCATION]
STORE_ELEMENT_FROM_KEYS(0x00) // [owner, to, tokenId]

// Set the owner of the token to 0x00
0x00 dup4 [OWNER_LOCATION_MASK] or // [slot, owner, 0x00, owner, to, tokenId]
sstore // [owner, to, tokenId]
0x00 dup4 [OWNER_LOCATION] // [slot, owner, 0x00, owner, to, tokenId]
STORE_ELEMENT_FROM_KEYS(0x00) // [owner, to, tokenId]

// Set the approval of the token to 0x00 for the owner
0x00 dup4 [SINGLE_APPROVAL_LOCATION] // [slot, owner, 0x00, owner, to, tokenId]
Expand Down Expand Up @@ -217,8 +217,8 @@
#define macro APPROVE() = takes (0) returns (0) {
// Load the token owner
0x24 calldataload dup1 // [tokenId, tokenId]
[OWNER_LOCATION_MASK] or
sload // [owner, tokenId]
[OWNER_LOCATION]
LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, tokenId]
dup1 caller eq // [is_sender_owner, owner, tokenId]

// Check if approved for all
Expand Down Expand Up @@ -436,7 +436,7 @@

// If from !== ownerOf[tokenId] revert with "WRONG_FROM"
dup1 dup4 // [tokenId, from, from, to, tokenId]
[OWNER_LOCATION_MASK] or sload // [owner, from, from, to, tokenId]
[OWNER_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, from, from, to, tokenId]
eq cont jumpi // [from, to, tokenId]
__ERROR(ErrWrongFrom)
ERR_CUSTOM()
Expand Down Expand Up @@ -471,30 +471,30 @@

// Update balance of from
0x01 dup2 // [from, 1, from, to, tokenId]
[BALANCE_LOCATION_MASK] or sload // [balance, 1, from, to, tokenId]
[BALANCE_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [balance, 1, from, to, tokenId]
sub dup2 // [from, balance-1, from, to, tokenId]
[BALANCE_LOCATION_MASK] or
sstore // [from, to, tokenId]
[BALANCE_LOCATION]
STORE_ELEMENT_FROM_KEYS(0x00) // [from, to, tokenId]
}

/// @notice Internal Macro to update Transfer to accounting
#define macro TRANSFER_GIVE_TO() = takes (3) returns (3) {
// retrieve balance
// input stack: // [from, to, tokenId]
dup2 // [to, from, to, tokenId]
[BALANCE_LOCATION_MASK] or // [balance_slot, to, from, to, tokenId]
sload // [balance, from, to, tokenId]
[BALANCE_LOCATION] // [balance_slot, to, from, to, tokenId]
LOAD_ELEMENT_FROM_KEYS(0x00) // [balance, from, to, tokenId]
0x01 add // [balance+1, from, to, tokenId]

// update balance
dup3 // [to, balance+1, from, to, tokenId]
[BALANCE_LOCATION_MASK] or // [balance_slot, to, balance+1, from, to, tokenId]
sstore // [from, to, tokenId]
[BALANCE_LOCATION] // [balance_slot, to, balance+1, from, to, tokenId]
STORE_ELEMENT_FROM_KEYS(0x00) // [from, to, tokenId]

// update ownerOf
dup2 dup4 // [tokenId, to, from, to, tokenId]
[OWNER_LOCATION_MASK] or // [owner_slot, tokenId, to, from, to, tokenId]
sstore // [from, to, tokenId]
[OWNER_LOCATION] // [owner_slot, tokenId, to, from, to, tokenId]
STORE_ELEMENT_FROM_KEYS(0x00) // [from, to, tokenId]

// update approval
0x00 dup4 // [tokenId, address(0), from, to, tokenId]
Expand Down

0 comments on commit d48d143

Please sign in to comment.