Skip to content

Commit

Permalink
Merge pull request #85 from noir-lang/jc/foundry-31
Browse files Browse the repository at this point in the history
simplify with_foundry test
  • Loading branch information
critesjosh authored Jul 31, 2024
2 parents cf14674 + 7c51a88 commit 408614b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions with-foundry/test/Starter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,13 @@ contract StarterTest is Test {
}

// Utility function, because the proof file includes the public inputs at the beginning
function sliceAfter64Bytes(bytes memory _bytes) internal pure returns (bytes memory) {
require(_bytes.length > 64, "Input must be longer than 64 bytes");

uint256 remainingLength = _bytes.length - 64;
bytes memory result = new bytes(remainingLength);

assembly {
// Copy remaining bytes
let resultPtr := add(result, 32) // skipping the length field
let sourcePtr := add(_bytes, 96) // 32 (length field) + 64 (bytes to skip)
for { let i := 0 } lt(i, remainingLength) { i := add(i, 32) } {
mstore(add(resultPtr, i), mload(add(sourcePtr, i)))
}

// Handle the last chunk if remaining length is not a multiple of 32
let lastChunk := and(remainingLength, 0x1f) // remainingLength % 32
if gt(lastChunk, 0) {
let mask := not(sub(exp(256, sub(32, lastChunk)), 1))
mstore(add(resultPtr, remainingLength), and(mload(add(sourcePtr, remainingLength)), mask))
}
function sliceAfter64Bytes(bytes memory data) internal pure returns (bytes memory) {
uint256 length = data.length - 64;
bytes memory result = new bytes(data.length - 64);
for (uint i = 0; i < length; i++) {
result[i] = data[i + 64];
}

return result;
}

}

0 comments on commit 408614b

Please sign in to comment.