-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AA benchmark tests #577
AA benchmark tests #577
Conversation
function toHexStringChecksummed(address value) internal pure returns (string memory str) { | ||
str = toHexString(value); | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...` | ||
let o := add(str, 0x22) | ||
let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... ` | ||
let t := shl(240, 136) // `0b10001000 << 240` | ||
for { | ||
let i := 0 | ||
} 1 { | ||
|
||
} { | ||
mstore(add(i, i), mul(t, byte(i, hashed))) | ||
i := add(i, 1) | ||
if eq(i, 20) { | ||
break | ||
} | ||
} | ||
mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask))))) | ||
o := add(o, 0x20) | ||
mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask))))) | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage Warning
function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
let length := mload(raw) | ||
str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix. | ||
mstore(str, add(length, length)) // Store the length of the output. | ||
|
||
// Store "0123456789abcdef" in scratch space. | ||
mstore(0x0f, 0x30313233343536373839616263646566) | ||
|
||
let o := add(str, 0x20) | ||
let end := add(raw, length) | ||
|
||
for { | ||
|
||
} iszero(eq(raw, end)) { | ||
|
||
} { | ||
raw := add(raw, 1) | ||
mstore8(add(o, 1), mload(and(mload(raw), 15))) | ||
mstore8(o, mload(and(shr(4, mload(raw)), 15))) | ||
o := add(o, 2) | ||
} | ||
mstore(o, 0) // Zeroize the slot after the string. | ||
mstore(0x40, add(o, 0x20)) // Allocate the memory. | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage Warning
function toHexString(address value) internal pure returns (string memory str) { | ||
str = toHexStringNoPrefix(value); | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
let strLength := add(mload(str), 2) // Compute the length. | ||
mstore(str, 0x3078) // Write the "0x" prefix. | ||
str := sub(str, 2) // Move the pointer. | ||
mstore(str, strLength) // Write the length. | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage Warning
function toHexString(bytes memory raw) internal pure returns (string memory str) { | ||
str = toHexStringNoPrefix(raw); | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
let strLength := add(mload(str), 2) // Compute the length. | ||
mstore(str, 0x3078) // Write the "0x" prefix. | ||
str := sub(str, 2) // Move the pointer. | ||
mstore(str, strLength) // Write the length. | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage Warning
function toHexStringNoPrefix(address value) internal pure returns (string memory str) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
str := mload(0x40) | ||
|
||
// Allocate the memory. | ||
// We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, | ||
// 0x02 bytes for the prefix, and 0x28 bytes for the digits. | ||
// The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80. | ||
mstore(0x40, add(str, 0x80)) | ||
|
||
// Store "0123456789abcdef" in scratch space. | ||
mstore(0x0f, 0x30313233343536373839616263646566) | ||
|
||
str := add(str, 2) | ||
mstore(str, 40) | ||
|
||
let o := add(str, 0x20) | ||
mstore(add(o, 40), 0) | ||
|
||
value := shl(96, value) | ||
|
||
// We write the string from rightmost digit to leftmost digit. | ||
// The following is essentially a do-while loop that also handles the zero case. | ||
for { | ||
let i := 0 | ||
} 1 { | ||
|
||
} { | ||
let p := add(o, add(i, i)) | ||
let temp := byte(i, value) | ||
mstore8(add(p, 1), mload(and(temp, 15))) | ||
mstore8(p, mload(shr(4, temp))) | ||
i := add(i, 1) | ||
if eq(i, 20) { | ||
break | ||
} | ||
} | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage Warning
See #563