Skip to content

Commit

Permalink
Use suave-std (#18)
Browse files Browse the repository at this point in the history
* forge install: suave-std

* Use suave-std

* Fix?

* forge install: suave-std

* M

* Add suave-std? without git

* Remove suave-geth

* Update

* forge install: suave-std

29416d462e7746df4441a911d08d52577ab2e75a

* Update

* Contract fmt check

* Add forge format check

* Fix linter
  • Loading branch information
ferranbt authored Jan 5, 2024
1 parent 9890634 commit 7911ed1
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 76 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ jobs:
- name: Lint
run: make lint

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Lint contracts
run: forge fmt --check

- name: Ensure go mod tidy runs without changes
run: |
go mod tidy
git update-index -q --really-refresh
git diff-index HEAD
integration-tests:
name: Integration tests
runs-on: ubuntu-latest
Expand All @@ -53,17 +60,25 @@ jobs:
- name: Check out code into the Go module directory and submodules
uses: actions/checkout@v2
with:
submodules: 'true'

submodules: "true"

- name: Checkout suave-geth repo
uses: actions/checkout@v4
with:
repository: flashbots/suave-geth
path: suave-geth
persist-credentials: false
fetch-depth: 0

- name: Build suave
run: |
cd suave-geth
make geth
- name: Run suave
run: |
./suave-geth/build/bin/geth --suave.dev &
./suave-geth/build/bin/geth --suave.dev --suave.eth.external-whitelist localhost:1234 &
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "suave-geth"]
path = suave-geth
url = https://github.com/flashbots/suave-geth.git
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.7.1
[submodule "lib/suave-std"]
path = lib/suave-std
url = https://github.com/flashbots/suave-std
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
"[solidity]": {
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"solidity.compileUsingRemoteVersion": "v0.8.16",
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib"
}
12 changes: 7 additions & 5 deletions examples/app-ofa-private/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"math/big"
"net/http"
"net/http/httptest"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -15,8 +15,10 @@ import (
)

func main() {
fakeRelayer := httptest.NewServer(&relayHandlerExample{})
defer fakeRelayer.Close()
relayerURL := "localhost:1234"
go func() {
log.Fatal(http.ListenAndServe(relayerURL, &relayHandlerExample{}))
}()

fr := framework.New()
contract := fr.DeployContract("ofa-private.sol/OFAPrivate.json")
Expand Down Expand Up @@ -90,9 +92,9 @@ func main() {
fmt.Println("Match event id", matchEvent.BidId)

// Step 4. Emit the batch to the relayer
fmt.Println("Step 4. Emit batch")
fmt.Println("4. Emit batch")

contract.SendTransaction("emitMatchBidAndHint", []interface{}{fakeRelayer.URL, matchEvent.BidId}, backRunBundleBytes)
contract.SendTransaction("emitMatchBidAndHint", []interface{}{"http://" + relayerURL, matchEvent.BidId}, backRunBundleBytes)
}

var hintEventABI abi.Event
Expand Down
36 changes: 19 additions & 17 deletions examples/app-ofa-private/ofa-private.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract OFAPrivate {
address[] public addressList = [0xC8df3686b4Afb2BB53e60EAe97EF043FE03Fb829];

// Struct to hold hint-related information for an order.
struct HintOrder {
Suave.BidId id;
Suave.DataId id;
bytes hint;
}

event HintEvent (
Suave.BidId id,
bytes hint
);
event HintEvent(Suave.DataId id, bytes hint);

// Internal function to save order details and generate a hint.
function saveOrder() internal view returns (HintOrder memory) {
Expand All @@ -29,8 +24,12 @@ contract OFAPrivate {
// to external applications.
bytes memory hint = Suave.extractHint(bundleData);

address[] memory allowedList = new address[](2);
allowedList[0] = address(this);
allowedList[1] = 0x0000000000000000000000000000000043200001;

// Store the bundle and the simulation results in the confidential datastore.
Suave.Bid memory bid = Suave.newBid(10, addressList, addressList, "");
Suave.DataRecord memory bid = Suave.newDataRecord(10, allowedList, allowedList, "");
Suave.confidentialStore(bid.id, "mevshare:v0:ethBundles", bundleData);
Suave.confidentialStore(bid.id, "mevshare:v0:ethBundleSimResults", abi.encode(egp));

Expand All @@ -52,26 +51,29 @@ contract OFAPrivate {
}

// Function to match and backrun another bid.
function newMatch(Suave.BidId shareBidId) external payable returns (bytes memory) {
function newMatch(Suave.DataId shareBidId) external payable returns (bytes memory) {
HintOrder memory hintOrder = saveOrder();

// Merge the bids and store them in the confidential datastore.
// The 'fillMevShareBundle' precompile will use this information to send the bundles.
Suave.BidId[] memory bids = new Suave.BidId[](2);
Suave.DataId[] memory bids = new Suave.DataId[](2);
bids[0] = shareBidId;
bids[1] = hintOrder.id;
Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedBids", abi.encode(bids));
Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(bids));

return abi.encodeWithSelector(this.emitHint.selector, hintOrder);
}

function emitMatchBidAndHintCallback() external payable {
}
function emitMatchBidAndHintCallback() external payable {}

function emitMatchBidAndHint(string memory builderUrl, Suave.BidId bidId) external payable returns (bytes memory) {
function emitMatchBidAndHint(string memory builderUrl, Suave.DataId bidId)
external
payable
returns (bytes memory)
{
bytes memory bundleData = Suave.fillMevShareBundle(bidId);
Suave.submitBundleJsonRPC(builderUrl, "mev_sendBundle", bundleData);

return abi.encodeWithSelector(this.emitMatchBidAndHintCallback.selector);
}
}
11 changes: 3 additions & 8 deletions examples/mevm-confidential-store/confidential-store.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract ConfidentialStore {
function callback() external payable {}
Expand All @@ -10,20 +10,15 @@ contract ConfidentialStore {
address[] memory allowedList = new address[](1);
allowedList[0] = address(this);

Suave.Bid memory bid = Suave.newBid(
10,
allowedList,
allowedList,
"namespace"
);
Suave.DataRecord memory bid = Suave.newDataRecord(10, allowedList, allowedList, "namespace");

Suave.confidentialStore(bid.id, "key1", abi.encode(1));
Suave.confidentialStore(bid.id, "key2", abi.encode(2));

bytes memory value = Suave.confidentialRetrieve(bid.id, "key1");
require(keccak256(value) == keccak256(abi.encode(1)));

Suave.Bid[] memory allShareMatchBids = Suave.fetchBids(10, "namespace");
Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, "namespace");
return abi.encodeWithSelector(this.callback.selector);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

library UniswapV3 {
address constant swapRouter = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
string constant exactOutputSingleSig = "exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))";
string constant exactOutputSingleSig =
"exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))";

struct ExactOutputSingleParams {
address tokenIn;
Expand All @@ -18,20 +19,15 @@ library UniswapV3 {
uint160 sqrtPriceLimitX96;
}

function exactOutputSingle(ExactOutputSingleParams memory params)
internal
view
returns (uint256 amountIn)
{
function exactOutputSingle(ExactOutputSingleParams memory params) internal view returns (uint256 amountIn) {
bytes memory output = Suave.ethcall(swapRouter, abi.encodeWithSignature(exactOutputSingleSig, params));
(uint256 num) = abi.decode(output, (uint64));
uint256 num = abi.decode(output, (uint64));
return num;
}
}

contract ExternalUniswapV3Quote {
function callback() external payable {
}
function callback() external payable {}

function example(UniswapV3.ExactOutputSingleParams memory params) external payable returns (bytes memory) {
UniswapV3.exactOutputSingle(params);
Expand Down
2 changes: 1 addition & 1 deletion examples/mevm-is-confidential/is-confidential.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract IsConfidential {
function callback() external payable {}
Expand Down
8 changes: 3 additions & 5 deletions examples/onchain-callback/onchain-callback.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract OnChainCallback {
event CallbackEvent (
uint256 num
);
event CallbackEvent(uint256 num);

event NilEvent ();
event NilEvent();

function emitCallback(uint256 num) public {
emit CallbackEvent(num);
Expand Down
2 changes: 1 addition & 1 deletion examples/onchain-state/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
fmt.Println("1. A confidential request fails if it tries to modify the state")

_, err := contract.Raw().SendTransaction("nilExample", nil, nil)
if err != nil {
if err == nil {
fmt.Println("expected an error")
os.Exit(1)
}
Expand Down
9 changes: 4 additions & 5 deletions examples/onchain-state/onchain-state.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract OnChainState {
uint64 state;

function nilExampleCallback() external payable {
}
function nilExampleCallback() external payable {}

function getState() external returns (uint64) {
return state;
}

// nilExample is a function executed in a confidential request
// that CANNOT modify the state of the smart contract.
function nilExample() external payable returns (bytes memory) {
require(Suave.isConfidential());
state++;
return abi.encodeWithSelector(this.nilExampleCallback.selector);
}

function exampleCallback() external payable {
state++;
}
Expand Down
8 changes: 3 additions & 5 deletions examples/private-library/private-library.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/Suave.sol";
import "suave-std/suavelib/Suave.sol";

contract PublicSuapp {
function callback() public payable {

}
function callback() public payable {}

function example() public payable returns (bytes memory) {
bytes memory bytecode = Suave.confidentialInputs();
Expand Down Expand Up @@ -37,6 +35,6 @@ interface PrivateLibraryI {

contract PrivateLibrary {
function add(uint256 a, uint256 b) public pure returns (uint256) {
return a+b;
return a + b;
}
}
9 changes: 2 additions & 7 deletions examples/with-forge/forge.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import "../../suave-geth/suave/sol/libraries/SuaveForge.sol";
import "suave-std/suavelib/SuaveForge.sol";
import "forge-std/Script.sol";

contract Forge is Script {
address[] public addressList = [0xC8df3686b4Afb2BB53e60EAe97EF043FE03Fb829];

function run() public {
Suave.Bid memory bid = SuaveForge.newBid(
0,
addressList,
addressList,
"namespace"
);
Suave.DataRecord memory bid = SuaveForge.newDataRecord(0, addressList, addressList, "namespace");
}
}
Loading

0 comments on commit 7911ed1

Please sign in to comment.