Skip to content
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

Add headless execution #39

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[profile.ci.fuzz]
runs = 10_000
solc_version = "0.8.23"
solc_version = "0.8.23"
[profile.suave]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This info is used by the precompile execution.

whitelist = ["*"]
14 changes: 4 additions & 10 deletions src/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ contract SuaveEnabled is Test {
ConfidentialInputsWrapperI constant confInputsWrapper = ConfidentialInputsWrapperI(Suave.CONFIDENTIAL_INPUTS);

function setUp() public {
string[] memory inputs = new string[](3);
string[] memory inputs = new string[](2);
inputs[0] = "suave-geth";
inputs[1] = "forge";
inputs[2] = "status";

try vm.ffi(inputs) returns (bytes memory response) {
// the status call of the `suave-geth forge` command fails with the 'not-ok' prefix
// which is '6e6f742d6f6b' in hex
if (isPrefix(hex"6e6f742d6f6b", response)) {
revert("Local Suave node not detected running");
}
} catch (bytes memory reason) {
try vm.ffi(inputs) returns (bytes memory response) {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suave-geth forge status had two goals:

  • Figure out if the suave-geth binary was available on PATH.
  • Check if there was a running instance of suave-geth to resolve the precompiles (status subcommand).

Now, with the headless execution, we can skip step 2.

catch (bytes memory reason) {
revert(detectErrorMessage(reason));
}

Expand All @@ -42,7 +36,7 @@ contract SuaveEnabled is Test {

function detectErrorMessage(bytes memory reason) internal pure returns (string memory) {
// Errors from cheatcodes are reported as 'CheatcodeError(string)' events
// 'eeaa9e6f' is the signature of the event
// 'eeaa9e6f' is the signature of the event. If the error is not a CheatcodeError, return the reason as is
if (!isPrefix(hex"eeaa9e6f", reason)) {
return string(reason);
}
Expand Down
12 changes: 9 additions & 3 deletions src/forge/Connector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import "forge-std/Test.sol";

contract Connector is Test {
function forgeIt(bytes memory addr, bytes memory data) internal returns (bytes memory) {
string memory root = vm.projectRoot();
string memory foundryToml = string.concat(root, "/", "foundry.toml");

string memory addrHex = iToHex(addr);
string memory dataHex = iToHex(data);

string[] memory inputs = new string[](4);
string[] memory inputs = new string[](7);
inputs[0] = "suave-geth";
inputs[1] = "forge";
inputs[2] = addrHex;
inputs[3] = dataHex;
inputs[2] = "--local";
inputs[3] = "--config";
inputs[4] = foundryToml;
inputs[5] = addrHex;
inputs[6] = dataHex;

bytes memory res = vm.ffi(inputs);
return res;
Expand Down
Loading