From bb2c583ce03a7e5ce3e1ab44c04fc7f8858e4341 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Fri, 24 May 2024 13:47:21 -0700 Subject: [PATCH 1/4] add draft of Dag confstore lib to ofa example --- examples/app-ofa-private/ofa-private.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/app-ofa-private/ofa-private.sol b/examples/app-ofa-private/ofa-private.sol index 20808b3..dd80577 100644 --- a/examples/app-ofa-private/ofa-private.sol +++ b/examples/app-ofa-private/ofa-private.sol @@ -4,6 +4,25 @@ pragma solidity ^0.8.8; import "suave-std/suavelib/Suave.sol"; import "suave-std/Context.sol"; +library DagStore { + address constant DAG_RETRIEVE = address(0); // TODO: fill in + address constant DAG_STORE = address(0); // TODO: fill in + + function get(bytes32 dagId) public view returns (bytes memory) { + (bool success, bytes memory data) = DAG_RETRIEVE.call(abi.encode(dagId)); + if (!success) { + revert PeekerReverted(DAG_RETRIEVE, data); + } + } + + function set(bytes32 dagId, bytes memory data) public { + (bool success, bytes memory data) = DAG_STORE.call(abi.encode(dagId, data)); + if (!success) { + revert PeekerReverted(DAG_STORE, data); + } + } +} + contract OFAPrivate { // Struct to hold hint-related information for an order. struct HintOrder { From 8766260beff8a7ee9264623ae192ff3472d9f6ff Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Fri, 24 May 2024 13:55:20 -0700 Subject: [PATCH 2/4] use new lib in ofa example --- examples/app-ofa-private/ofa-private.sol | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/app-ofa-private/ofa-private.sol b/examples/app-ofa-private/ofa-private.sol index dd80577..48600b4 100644 --- a/examples/app-ofa-private/ofa-private.sol +++ b/examples/app-ofa-private/ofa-private.sol @@ -13,20 +13,23 @@ library DagStore { if (!success) { revert PeekerReverted(DAG_RETRIEVE, data); } + return data; } - function set(bytes32 dagId, bytes memory data) public { + function set(bytes memory data) public returns (bytes32 dagId) { + bytes32 dagId = keccak256(data); (bool success, bytes memory data) = DAG_STORE.call(abi.encode(dagId, data)); if (!success) { revert PeekerReverted(DAG_STORE, data); } + return dagId; } } contract OFAPrivate { // Struct to hold hint-related information for an order. struct HintOrder { - Suave.DataId id; + bytes32 id; bytes hint; } @@ -51,12 +54,13 @@ contract OFAPrivate { allowedList[1] = 0x0000000000000000000000000000000043200001; // Store the bundle and the simulation results in the confidential datastore. - Suave.DataRecord memory dataRecord = Suave.newDataRecord(decryptionCondition, allowedList, allowedList, ""); - Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundles", bundleData); - Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundleSimResults", abi.encode(egp)); + // Suave.DataRecord memory dataRecord = Suave.newDataRecord(decryptionCondition, allowedList, allowedList, ""); + // Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundles", bundleData); + // Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundleSimResults", abi.encode(egp)); + dagId = DagStore.set(bundleData); HintOrder memory hintOrder; - hintOrder.id = dataRecord.id; + hintOrder.id = dagId; hintOrder.hint = hint; return hintOrder; @@ -73,7 +77,7 @@ contract OFAPrivate { } // Function to match and backrun another dataRecord. - function newMatch(Suave.DataId shareDataRecordId, uint64 decryptionCondition) external returns (bytes memory) { + function newMatch(bytes32 shareDataRecordId, uint64 decryptionCondition) external returns (bytes memory) { HintOrder memory hintOrder = saveOrder(decryptionCondition); // Merge the dataRecords and store them in the confidential datastore. @@ -81,9 +85,10 @@ contract OFAPrivate { Suave.DataId[] memory dataRecords = new Suave.DataId[](2); dataRecords[0] = shareDataRecordId; dataRecords[1] = hintOrder.id; - Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(dataRecords)); + // Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(dataRecords)); + bytes32 recordsId = DagStore.set(abi.encode(dataRecords)); - return abi.encodeWithSelector(this.emitHint.selector, hintOrder); + return abi.encodeWithSelector(this.emitHint.selector, recordsId); } function emitMatchDataRecordAndHintCallback(string memory bundleRawResponse) external { From b1a2f7597e2d12583a43d38987009b231b96add4 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Fri, 24 May 2024 14:05:44 -0700 Subject: [PATCH 3/4] set id in params --- examples/app-ofa-private/ofa-private.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/app-ofa-private/ofa-private.sol b/examples/app-ofa-private/ofa-private.sol index 48600b4..2b512aa 100644 --- a/examples/app-ofa-private/ofa-private.sol +++ b/examples/app-ofa-private/ofa-private.sol @@ -8,7 +8,7 @@ library DagStore { address constant DAG_RETRIEVE = address(0); // TODO: fill in address constant DAG_STORE = address(0); // TODO: fill in - function get(bytes32 dagId) public view returns (bytes memory) { + function get(bytes32 dagId) internal view returns (bytes memory) { (bool success, bytes memory data) = DAG_RETRIEVE.call(abi.encode(dagId)); if (!success) { revert PeekerReverted(DAG_RETRIEVE, data); @@ -16,13 +16,11 @@ library DagStore { return data; } - function set(bytes memory data) public returns (bytes32 dagId) { - bytes32 dagId = keccak256(data); + function set(bytes32 dagId, bytes memory data) internal { (bool success, bytes memory data) = DAG_STORE.call(abi.encode(dagId, data)); if (!success) { revert PeekerReverted(DAG_STORE, data); } - return dagId; } } From 13f47065636098947a6ecdf8f4a5dd739df16b84 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Fri, 24 May 2024 14:06:32 -0700 Subject: [PATCH 4/4] add precompile addrs for dagstore --- examples/app-ofa-private/ofa-private.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/app-ofa-private/ofa-private.sol b/examples/app-ofa-private/ofa-private.sol index 2b512aa..1ee6ef4 100644 --- a/examples/app-ofa-private/ofa-private.sol +++ b/examples/app-ofa-private/ofa-private.sol @@ -5,8 +5,8 @@ import "suave-std/suavelib/Suave.sol"; import "suave-std/Context.sol"; library DagStore { - address constant DAG_RETRIEVE = address(0); // TODO: fill in - address constant DAG_STORE = address(0); // TODO: fill in + address constant DAG_RETRIEVE = address(0x0000000000000000000000000000000052020001); + address constant DAG_STORE = address(0x0000000000000000000000000000000052020000); function get(bytes32 dagId) internal view returns (bytes memory) { (bool success, bytes memory data) = DAG_RETRIEVE.call(abi.encode(dagId));