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 all 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 = ["*"]
13 changes: 4 additions & 9 deletions src/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ contract SuaveEnabled is Test {
ConfidentialStoreI constant confStoreWrapper = ConfidentialStoreI(Registry.confidentialStoreAddr);

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";
inputs[1] = "version";

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");
}
// TODO: validate versions
} catch (bytes memory reason) {
revert(detectErrorMessage(reason));
}
Expand All @@ -47,7 +42,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
4 changes: 2 additions & 2 deletions src/Transactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ library Transactions {
{
bytes memory rlp = Transactions.encodeRLP(request);
bytes memory hash = abi.encodePacked(keccak256(rlp));
bytes memory signature = Suave.signMessage(hash, signingKey);
bytes memory signature = Suave.signMessage(hash, Suave.CryptoSignature.SECP256, signingKey);
(uint8 v, bytes32 r, bytes32 s) = decodeSignature(signature);

response.to = request.to;
Expand All @@ -328,7 +328,7 @@ library Transactions {
{
bytes memory rlp = Transactions.encodeRLP(request);
bytes memory hash = abi.encodePacked(keccak256(rlp));
bytes memory signature = Suave.signMessage(hash, signingKey);
bytes memory signature = Suave.signMessage(hash, Suave.CryptoSignature.SECP256, signingKey);

// TODO: check overflow
uint64 chainIdMul = uint64(request.chainId) * 2;
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
16 changes: 12 additions & 4 deletions src/suavelib/Suave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ pragma solidity ^0.8.8;
library Suave {
error PeekerReverted(address, bytes);

enum CryptoSignature {
SECP256,
BLS
}

type DataId is bytes16;

struct BuildBlockArgs {
Expand Down Expand Up @@ -230,8 +235,8 @@ library Suave {
return abi.decode(data, (DataRecord));
}

function privateKeyGen() internal returns (string memory) {
(bool success, bytes memory data) = PRIVATE_KEY_GEN.call(abi.encode());
function privateKeyGen(CryptoSignature crypto) internal returns (string memory) {
(bool success, bytes memory data) = PRIVATE_KEY_GEN.call(abi.encode(crypto));
if (!success) {
revert PeekerReverted(PRIVATE_KEY_GEN, data);
}
Expand All @@ -251,9 +256,12 @@ library Suave {
return abi.decode(data, (bytes));
}

function signMessage(bytes memory digest, string memory signingKey) internal returns (bytes memory) {
function signMessage(bytes memory digest, CryptoSignature crypto, string memory signingKey)
internal
returns (bytes memory)
{
require(isConfidential());
(bool success, bytes memory data) = SIGN_MESSAGE.call(abi.encode(digest, signingKey));
(bool success, bytes memory data) = SIGN_MESSAGE.call(abi.encode(digest, crypto, signingKey));
if (!success) {
revert PeekerReverted(SIGN_MESSAGE, data);
}
Expand Down
Loading