From 7cd156a7c8ca772b79fd28f4b21b2921860e7b37 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Fri, 2 Feb 2024 13:50:33 +0000 Subject: [PATCH 1/3] Add headless execution --- foundry.toml | 4 +++- src/Test.sol | 2 ++ src/forge/Connector.sol | 12 +++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/foundry.toml b/foundry.toml index 26443c0..775d61c 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,3 +1,5 @@ [profile.ci.fuzz] runs = 10_000 -solc_version = "0.8.23" \ No newline at end of file +solc_version = "0.8.23" +[profile.suave] +whitelist = ["*"] diff --git a/src/Test.sol b/src/Test.sol index 7b20508..6250de8 100644 --- a/src/Test.sol +++ b/src/Test.sol @@ -20,11 +20,13 @@ contract SuaveEnabled is Test { 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) { revert(detectErrorMessage(reason)); } diff --git a/src/forge/Connector.sol b/src/forge/Connector.sol index 45f0c99..6496dcd 100644 --- a/src/forge/Connector.sol +++ b/src/forge/Connector.sol @@ -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; From c69f396fd83cc158384d5738a8c32f96c230b858 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Mon, 5 Feb 2024 10:03:28 +0000 Subject: [PATCH 2/3] Clear PR --- src/Test.sol | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Test.sol b/src/Test.sol index 6250de8..a22ab66 100644 --- a/src/Test.sol +++ b/src/Test.sol @@ -14,20 +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) {} + catch (bytes memory reason) { revert(detectErrorMessage(reason)); } @@ -44,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); } From 26a93e9b02a86340a46d1de4cb5426ade8f66f02 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 20 Feb 2024 14:44:10 +0000 Subject: [PATCH 3/3] Update Suavelib --- src/Test.sol | 7 ++++--- src/Transactions.sol | 4 ++-- src/suavelib/Suave.sol | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Test.sol b/src/Test.sol index bd7f242..81a5419 100644 --- a/src/Test.sol +++ b/src/Test.sol @@ -21,10 +21,11 @@ contract SuaveEnabled is Test { function setUp() public { string[] memory inputs = new string[](2); inputs[0] = "suave-geth"; - inputs[1] = "forge"; + inputs[1] = "version"; - try vm.ffi(inputs) returns (bytes memory response) {} - catch (bytes memory reason) { + try vm.ffi(inputs) returns (bytes memory response) { + // TODO: validate versions + } catch (bytes memory reason) { revert(detectErrorMessage(reason)); } diff --git a/src/Transactions.sol b/src/Transactions.sol index 626a0d3..04122df 100644 --- a/src/Transactions.sol +++ b/src/Transactions.sol @@ -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; @@ -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; diff --git a/src/suavelib/Suave.sol b/src/suavelib/Suave.sol index 08c7ee5..0bc074e 100644 --- a/src/suavelib/Suave.sol +++ b/src/suavelib/Suave.sol @@ -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 { @@ -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); } @@ -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); }