-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [Foundry] implement nft support in hts emulation (#172)
Signed-off-by: Mariusz Jasuwienas <[email protected]>
- Loading branch information
1 parent
f228465
commit baf5283
Showing
28 changed files
with
414 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pragma solidity >=0.6.0; | ||
|
||
bytes constant TABLE_DECODE = hex"0000000000000000000000000000000000000000000000000000000000000000" | ||
hex"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000" | ||
hex"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000" | ||
hex"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000"; | ||
|
||
function decode(string memory _data) pure returns (bytes memory) { | ||
bytes memory data = bytes(_data); | ||
|
||
if (data.length == 0) return new bytes(0); | ||
require(data.length % 4 == 0, "invalid base64 decoder input"); | ||
|
||
// load the table into memory | ||
bytes memory table = TABLE_DECODE; | ||
|
||
// every 4 characters represent 3 bytes | ||
uint256 decodedLen = (data.length / 4) * 3; | ||
|
||
// add some extra buffer at the end required for the writing | ||
bytes memory result = new bytes(decodedLen + 32); | ||
|
||
assembly { | ||
// padding with '=' | ||
let lastBytes := mload(add(data, mload(data))) | ||
if eq(and(lastBytes, 0xFF), 0x3d) { | ||
decodedLen := sub(decodedLen, 1) | ||
if eq(and(lastBytes, 0xFFFF), 0x3d3d) { | ||
decodedLen := sub(decodedLen, 1) | ||
} | ||
} | ||
|
||
// set the actual output length | ||
mstore(result, decodedLen) | ||
|
||
// prepare the lookup table | ||
let tablePtr := add(table, 1) | ||
|
||
// input ptr | ||
let dataPtr := data | ||
let endPtr := add(dataPtr, mload(data)) | ||
|
||
// result ptr, jump over length | ||
let resultPtr := add(result, 32) | ||
|
||
// run over the input, 4 characters at a time | ||
for {} lt(dataPtr, endPtr) {} | ||
{ | ||
// read 4 characters | ||
dataPtr := add(dataPtr, 4) | ||
let input := mload(dataPtr) | ||
|
||
// write 3 bytes | ||
let output := add( | ||
add( | ||
shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)), | ||
shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))), | ||
add( | ||
shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)), | ||
and(mload(add(tablePtr, and( input , 0xFF))), 0xFF) | ||
) | ||
) | ||
mstore(resultPtr, shl(232, output)) | ||
resultPtr := add(resultPtr, 3) | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.