-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add leaked logs example * Update suave-std
- Loading branch information
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Example Suapp with Offchain logs | ||
|
||
This example shows how Suapps can emit logs during the confidential execution that are leaked during the onchain callback. To do so, the Suapp has to import the `suave-std/Suapp.sol` contract and use the `emitOffchainLogs` modifier in the onchain callback function. Then, logs emitted during the confidential execution which triggers the onchain computation will be emitted on the Suave chain. | ||
|
||
The Suapp will look like this: | ||
|
||
``` | ||
import "suave-std/Suapp.sol"; | ||
contract ExampleSuapp is Suapp { | ||
function onchainCallback() public emitOffchainLogs { | ||
} | ||
event OffchainLog(); | ||
function offchain() public { | ||
emit OffchainLog(); | ||
return abi.encodeWithSelector(this.onchainCallback.selector); | ||
} | ||
} | ||
``` | ||
|
||
## How to use | ||
|
||
Run `Suave` in development mode: | ||
|
||
``` | ||
$ suave --suave.dev | ||
``` | ||
|
||
Execute the deployment script: | ||
|
||
``` | ||
$ go run main.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/flashbots/suapp-examples/framework" | ||
) | ||
|
||
func main() { | ||
fr := framework.New() | ||
contract := fr.Suave.DeployContract("offchain-logs.sol/OffchainLogs.json") | ||
|
||
receipt := contract.SendTransaction("example", nil, nil) | ||
if len(receipt.Logs) != 2 { | ||
log.Fatal("two logs expected") | ||
} | ||
|
||
// emit the CCR but DO NOT leak the logs | ||
receipt = contract.SendTransaction("exampleNoLogs", nil, nil) | ||
if len(receipt.Logs) != 1 { | ||
log.Fatal("only one log expected") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.8; | ||
|
||
import "suave-std/Suapp.sol"; | ||
|
||
contract OffchainLogs is Suapp { | ||
event OnchainEvent(uint256 num); | ||
event OffchainEvent(uint256 num); | ||
|
||
function emitCallbackWithLogs(uint256 num) public emitOffchainLogs { | ||
emit OnchainEvent(num); | ||
} | ||
|
||
function example() external returns (bytes memory) { | ||
emit OffchainEvent(101); | ||
|
||
return bytes.concat(this.emitCallbackWithLogs.selector, abi.encode(101)); | ||
} | ||
|
||
/* This function pair do not leak the events in the onchain transaction */ | ||
|
||
function emitCallbackWithoutLogs(uint256 num) public { | ||
// this callback **does not** emit logs | ||
emit OnchainEvent(num); | ||
} | ||
|
||
function exampleNoLogs() external returns (bytes memory) { | ||
emit OffchainEvent(101); | ||
|
||
return bytes.concat(this.emitCallbackWithoutLogs.selector, abi.encode(101)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule suave-std
updated
11 files
+1 −0 | .github/workflows/ci.yml | |
+0 −6 | .github/workflows/suave-lib-sync.yml | |
+1 −1 | lib/forge-std | |
+98 −0 | src/Logs.sol | |
+11 −0 | src/Suapp.sol | |
+8 −7 | src/forge/SuaveAddrs.sol | |
+44 −0 | src/protocols/Bundle.sol | |
+11 −0 | src/suavelib/Suave.sol | |
+29 −0 | src/utils/HexStrings.sol | |
+168 −0 | test/Logs.t.sol | |
+17 −0 | test/protocols/Bundle.t.sol |