Skip to content

Commit

Permalink
up to uint96
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowBirdy committed Oct 17, 2023
1 parent 81107b3 commit 8db1013
Show file tree
Hide file tree
Showing 3 changed files with 333 additions and 18 deletions.
119 changes: 118 additions & 1 deletion src/HuffCastLib.huff
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
//#define constant __UINT248_MAX_PLUS_ONE =
//#define constant __UINT240_MAX_PLUS_ONE =
//#define constant __UINT232_MAX_PLUS_ONE =
//#define constant __UINT224_MAX_PLUS_ONE =
//#define constant __UINT216_MAX_PLUS_ONE =
//#define constant __UINT208_MAX_PLUS_ONE =
//#define constant __UINT200_MAX_PLUS_ONE =
//#define constant __UINT192_MAX_PLUS_ONE =
//#define constant __UINT184_MAX_PLUS_ONE =
//#define constant __UINT176_MAX_PLUS_ONE =
//#define constant __UINT168_MAX_PLUS_ONE =
//#define constant __UINT160_MAX_PLUS_ONE =
//#define constant __UINT152_MAX_PLUS_ONE =
//#define constant __UINT144_MAX_PLUS_ONE =
//#define constant __UINT136_MAX_PLUS_ONE =
//#define constant __UINT128_MAX_PLUS_ONE =
//#define constant __UINT120_MAX_PLUS_ONE =
//#define constant __UINT112_MAX_PLUS_ONE =
//#define constant __UINT104_MAX_PLUS_ONE =
//#define constant __UINT96_MAX_PLUS_ONE =
//#define constant __UINT88_MAX_PLUS_ONE =
//#define constant __UINT80_MAX_PLUS_ONE =
//#define constant __UINT72_MAX_PLUS_ONE =
//#define constant __UINT64_MAX_PLUS_ONE =
//#define constant __UINT56_MAX_PLUS_ONE =
//#define constant __UINT48_MAX_PLUS_ONE =
//#define constant __UINT40_MAX_PLUS_ONE =
//#define constant __UINT32_MAX_PLUS_ONE =


#define error Overflow()


//#define constant __UINT24_MAX_PLUS_ONE = 0x1000000
//#define constant __UINT16_MAX_PLUS_ONE = 0x10000
//#define constant __UINT8_MAX_PLUS_ONE = 0x100

/* Methods */

#define macro REVERT_OVERFLOW() = {
Expand All @@ -16,11 +51,93 @@
success:
}
#define macro TO_UINT16() = takes (1) returns (1) {
0x10000
0x10000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT24() = takes (1) returns (1) {
0x1000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT32() = takes (1) returns (1) {
0x100000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT40() = takes (1) returns (1) {
0x10000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT48() = takes (1) returns (1) {
0x1000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT56() = takes (1) returns (1) {
0x100000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT64() = takes (1) returns (1) {
0x10000000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT72() = takes (1) returns (1) {
0x1000000000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT80() = takes (1) returns (1) {
0x100000000000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT88() = takes (1) returns (1) {
0x10000000000000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}
#define macro TO_UINT96() = takes (1) returns (1) {
0x1000000000000000000000000
dup2
lt
success jumpi
REVERT_OVERFLOW()
success:
}



72 changes: 57 additions & 15 deletions src/HuffCastLibImportoor.huff
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,66 @@
/* Interface */
#define function toUint8(uint256) view returns (uint8)
#define function toUint16(uint256) view returns (uint16)
#define function toUint24(uint256) view returns (uint24)
#define function toUint32(uint256) view returns (uint32)
#define function toUint40(uint256) view returns (uint40)
#define function toUint48(uint256) view returns (uint48)
#define function toUint56(uint256) view returns (uint56)
#define function toUint64(uint256) view returns (uint64)
#define function toUint72(uint256) view returns (uint72)
#define function toUint80(uint256) view returns (uint80)
#define function toUint88(uint256) view returns (uint88)
#define function toUint96(uint256) view returns (uint96)


#define macro MAIN() = takes (0) returns (0) {
// Identify which function is being called.
0x00 calldataload 0xE0 shr // [sel]
0x04 calldataload // [input,sel]
dup2 __FUNC_SIG(toUint8) eq u8 jumpi //
dup2 __FUNC_SIG(toUint16) eq u16 jumpi
0x00 0x00 revert

u8:
TO_UINT8()
u16:
TO_UINT16()

ret:
0x00 mstore
0x20 0x00 return
// Identify which function is being called.
0x00 calldataload 0xE0 shr // [sel]
0x04 calldataload // [input,sel]
dup2 __FUNC_SIG(toUint8) eq u8 jumpi
dup2 __FUNC_SIG(toUint16) eq u16 jumpi
dup2 __FUNC_SIG(toUint24) eq u24 jumpi
dup2 __FUNC_SIG(toUint32) eq u32 jumpi
dup2 __FUNC_SIG(toUint40) eq u40 jumpi
dup2 __FUNC_SIG(toUint48) eq u48 jumpi
dup2 __FUNC_SIG(toUint56) eq u56 jumpi
dup2 __FUNC_SIG(toUint64) eq u64 jumpi
dup2 __FUNC_SIG(toUint72) eq u72 jumpi
dup2 __FUNC_SIG(toUint80) eq u80 jumpi
dup2 __FUNC_SIG(toUint88) eq u88 jumpi
dup2 __FUNC_SIG(toUint96) eq u96 jumpi

0x00 0x00 revert

u8:
TO_UINT8()
u16:
TO_UINT16()
u24:
TO_UINT24()
u32:
TO_UINT32()
u40:
TO_UINT40()
u48:
TO_UINT48()
u56:
TO_UINT56()
u64:
TO_UINT64()
u72:
TO_UINT72()
u80:
TO_UINT80()
u88:
TO_UINT88()
u96:
TO_UINT96()


ret:
0x00 mstore
0x20 0x00 return
}


Expand Down
Loading

0 comments on commit 8db1013

Please sign in to comment.