Skip to content

Commit

Permalink
Oh my... this really works
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Jan 4, 2024
1 parent 75de40d commit 971c2bd
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 182 deletions.
10 changes: 10 additions & 0 deletions src/forge/FSuave.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "./Wrapper2.sol";

contract SuaveEnabled {
function setUp() public {
Suave2.enable();
}
}
6 changes: 2 additions & 4 deletions src/forge/Wrapper.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "forge-std/console.sol";

interface Vm {
function ffi(string[] calldata commandInput) external view returns (bytes memory result);
}
Expand Down Expand Up @@ -37,9 +35,9 @@ contract Wrapper {
return string(abi.encodePacked("0x", converted));
}

/// Strips the first 4 bytes from the calldata and returns the rest.
fallback() external {
bytes memory msgdata = msg.data[4:];
bytes memory msgdata = forgeIt(abi.encodePacked(address(this)), msg.data);

assembly {
let location := msgdata
let length := mload(msgdata)
Expand Down
40 changes: 40 additions & 0 deletions src/forge/Wrapper2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../suavelib/Suave.sol";

interface Vm3 {
function etch(address, bytes calldata) external;
}

library Suave2 {
Vm3 constant vm = Vm3(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

function enableLib(address addr) public {
// code for Wrapper
bytes memory code =
hex"608060405234801561001057600080fd5b506004361061002b5760003560e01c8063671ff786146100a1575b6040516bffffffffffffffffffffffff193060601b1660208201526000906100959060340160408051808303601f19018152602036601f8101829004820285018201909352828452909291600091819084018382808284376000920191909152506100ca92505050565b90508081518060208301f35b6100b46100af36600461048c565b610259565b6040516100c1919061055c565b60405180910390f35b606060006100d784610259565b905060006100e484610259565b60408051600480825260a0820190925291925060009190816020015b606081526020019060019003908161010057905050905060405180604001604052806005815260200164737561766560d81b8152508160008151811061014857610148610576565b602002602001018190525060405180604001604052806005815260200164666f72676560d81b8152508160018151811061018457610184610576565b602002602001018190525082816002815181106101a3576101a3610576565b602002602001018190525081816003815181106101c2576101c2610576565b6020908102919091010152604051638916046760e01b8152600090737109709ecfa91a80626ff3989d68f67f5b1dd12d9063891604679061020790859060040161058c565b600060405180830381865afa158015610224573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261024c91908101906105ee565b9450505050505b92915050565b606060008251600261026b919061067b565b67ffffffffffffffff8111156102835761028361041d565b6040519080825280601f01601f1916602001820160405280156102ad576020820181803683370190505b5060408051808201909152601081526f181899199a1a9b1b9c1cb0b131b232b360811b602082015290915060005b84518110156103f3578182518683815181106102f9576102f9610576565b016020015161030b919060f81c6106a8565b8151811061031b5761031b610576565b01602001516001600160f81b0319168361033683600261067b565b8151811061034657610346610576565b60200101906001600160f81b031916908160001a90535081825186838151811061037257610372610576565b0160200151610384919060f81c6106bc565b8151811061039457610394610576565b01602001516001600160f81b031916836103af83600261067b565b6103ba9060016106d0565b815181106103ca576103ca610576565b60200101906001600160f81b031916908160001a905350806103eb816106e3565b9150506102db565b508160405160200161040591906106fc565b60405160208183030381529060405292505050919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561045c5761045c61041d565b604052919050565b600067ffffffffffffffff82111561047e5761047e61041d565b50601f01601f191660200190565b60006020828403121561049e57600080fd5b813567ffffffffffffffff8111156104b557600080fd5b8201601f810184136104c657600080fd5b80356104d96104d482610464565b610433565b8181528560208385010111156104ee57600080fd5b81602084016020830137600091810160200191909152949350505050565b60005b8381101561052757818101518382015260200161050f565b50506000910152565b6000815180845261054881602086016020860161050c565b601f01601f19169290920160200192915050565b60208152600061056f6020830184610530565b9392505050565b634e487b7160e01b600052603260045260246000fd5b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156105e157603f198886030184526105cf858351610530565b945092850192908501906001016105b3565b5092979650505050505050565b60006020828403121561060057600080fd5b815167ffffffffffffffff81111561061757600080fd5b8201601f8101841361062857600080fd5b80516106366104d482610464565b81815285602083850101111561064b57600080fd5b61065c82602083016020860161050c565b95945050505050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761025357610253610665565b634e487b7160e01b600052601260045260246000fd5b6000826106b7576106b7610692565b500490565b6000826106cb576106cb610692565b500690565b8082018082111561025357610253610665565b6000600182016106f5576106f5610665565b5060010190565b61060f60f31b81526000825161071981600285016020870161050c565b919091016002019291505056fea26469706673582212209bbb283ef2f98f0ca98f84404dd44e5f6535bd506f84ca977fbe4432d16d966d64736f6c63430008130033";
vm.etch(addr, code);
}

function enable() public {
enableLib(Suave.IS_CONFIDENTIAL_ADDR);
enableLib(Suave.BUILD_ETH_BLOCK);
enableLib(Suave.CONFIDENTIAL_INPUTS);
enableLib(Suave.CONFIDENTIAL_RETRIEVE);
enableLib(Suave.CONFIDENTIAL_STORE);
enableLib(Suave.DO_HTTPREQUEST);
enableLib(Suave.ETHCALL);
enableLib(Suave.EXTRACT_HINT);
enableLib(Suave.FETCH_DATA_RECORDS);
enableLib(Suave.FILL_MEV_SHARE_BUNDLE);
enableLib(Suave.NEW_BUILDER);
enableLib(Suave.NEW_DATA_RECORD);
enableLib(Suave.SIGN_ETH_TRANSACTION);
enableLib(Suave.SIGN_MESSAGE);
enableLib(Suave.SIMULATE_BUNDLE);
enableLib(Suave.SIMULATE_TRANSACTION);
enableLib(Suave.SUBMIT_BUNDLE_JSON_RPC);
enableLib(Suave.SUBMIT_ETH_BLOCK_TO_RELAY);
}
}
167 changes: 0 additions & 167 deletions src/suavelib/SuaveForge.sol

This file was deleted.

14 changes: 3 additions & 11 deletions test/Transactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import "forge-std/Vm.sol";
import "forge-std/console.sol";
import "src/Transactions.sol";
import "src/suavelib/Suave.sol";
import "src/forge/FSuave.sol";

contract TestTransactions is Test {
contract TestTransactions is Test, SuaveEnabled {
using Transactions for *;

function testLegacyTransactionRLPEncoding() public {
Expand Down Expand Up @@ -38,17 +39,8 @@ contract TestTransactions is Test {
assertEq0(rlp1, expected);
}

address public constant ANYALLOWED = 0x1111000000000000000000000000000042100001;

function testSomething() public {
bytes memory code =
hex"608060405234801561001057600080fd5b506004361061002b5760003560e01c8063671ff78614610074575b600060405160200161005690602080825260059082015264616161616160d81b604082015260600190565b60408051602080825263414141418183015260608401909252925081f35b610087610082366004610277565b61009d565b604051610094919061034c565b60405180910390f35b60606000825160026100af9190610395565b67ffffffffffffffff8111156100c7576100c7610261565b6040519080825280601f01601f1916602001820160405280156100f1576020820181803683370190505b5060408051808201909152601081526f181899199a1a9b1b9c1cb0b131b232b360811b602082015290915060005b84518110156102375781825186838151811061013d5761013d6103b2565b016020015161014f919060f81c6103de565b8151811061015f5761015f6103b2565b01602001516001600160f81b0319168361017a836002610395565b8151811061018a5761018a6103b2565b60200101906001600160f81b031916908160001a9053508182518683815181106101b6576101b66103b2565b01602001516101c8919060f81c6103f2565b815181106101d8576101d86103b2565b01602001516001600160f81b031916836101f3836002610395565b6101fe906001610406565b8151811061020e5761020e6103b2565b60200101906001600160f81b031916908160001a9053508061022f81610419565b91505061011f565b50816040516020016102499190610432565b60405160208183030381529060405292505050919050565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561028957600080fd5b813567ffffffffffffffff808211156102a157600080fd5b818401915084601f8301126102b557600080fd5b8135818111156102c7576102c7610261565b604051601f8201601f19908116603f011681019083821181831017156102ef576102ef610261565b8160405282815287602084870101111561030857600080fd5b826020860160208301376000928101602001929092525095945050505050565b60005b8381101561034357818101518382015260200161032b565b50506000910152565b602081526000825180602084015261036b816040850160208701610328565b601f01601f19169190910160400192915050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176103ac576103ac61037f565b92915050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6000826103ed576103ed6103c8565b500490565b600082610401576104016103c8565b500690565b808201808211156103ac576103ac61037f565b60006001820161042b5761042b61037f565b5060010190565b61060f60f31b81526000825161044f816002850160208701610328565b919091016002019291505056fea2646970667358221220308fa97990ba3aa76a873f441e6417af36f4e3900abae19398d9b6d7c5a70e5b64736f6c63430008130033";
vm.etch(Suave.CONFIDENTIAL_INPUTS, code);

(bool success, bytes memory data) = Suave.CONFIDENTIAL_INPUTS.staticcall(abi.encode());

//(bool success, bytes memory data) = ANYALLOWED.staticcall(abi.encode());
console.log(success);
bytes memory data = Suave.confidentialInputs();
console.logBytes(data);
}
}
3 changes: 3 additions & 0 deletions tools/forge-gen/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/flashbots/suave-std/tools/forge-gen

go 1.21.0
Loading

0 comments on commit 971c2bd

Please sign in to comment.