Skip to content

Commit

Permalink
update contracts path
Browse files Browse the repository at this point in the history
  • Loading branch information
capossele committed Jan 24, 2024
1 parent 65bb59e commit 0d274a0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The picture below shows a simplified overview of how users can integrate Bonsai

![Bonsai Relay Diagram](images/BonsaiRelay.png)

1. Users can delegate their smart contract's logic to Bonsai. The [Bonsai Relay Contract](lib/risc0/bonsai/ethereum/contracts/BonsaiRelay.sol) provides a `Request Callback` interface. This interface, accessible both *off-chain* (through HTTP REST API) and *on-chain*, emits an event detected by the `Ethereum Bonsai Relayer`.
1. Users can delegate their smart contract's logic to Bonsai. The [Bonsai Relay Contract](lib/risc0/bonsai/ethereum/contracts/relay/BonsaiRelay.sol) provides a `Request Callback` interface. This interface, accessible both *off-chain* (through HTTP REST API) and *on-chain*, emits an event detected by the `Ethereum Bonsai Relayer`.
2. The `Ethereum Bonsai Relayer` sends the proof request to Bonsai.
3. Bonsai generates a Snark proof and its result, encapsulated in a journal.
4. The `Ethereum Bonsai Relayer` submits this proof and journal on-chain to the `Bonsai Relay Contract` for validation.
Expand Down
4 changes: 2 additions & 2 deletions contracts/BonsaiStarter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

pragma solidity ^0.8.17;

import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {BonsaiCallbackReceiver} from "bonsai/BonsaiCallbackReceiver.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiCallbackReceiver} from "bonsai/relay/BonsaiCallbackReceiver.sol";

/// @title A starter application using Bonsai through the on-chain relay.
/// @dev This contract demonstrates one pattern for offloading the computation of an expensive
Expand Down
4 changes: 2 additions & 2 deletions contracts/BonsaiStarterLowLevel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

pragma solidity ^0.8.17;

import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {BonsaiLowLevelCallbackReceiver} from "bonsai/BonsaiLowLevelCallbackReceiver.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiLowLevelCallbackReceiver} from "bonsai/relay/BonsaiLowLevelCallbackReceiver.sol";

/// @title A starter application using Bonsai through the on-chain relay.
/// @dev This contract demonstrates one pattern for offloading the computation of an expensive
Expand Down
2 changes: 1 addition & 1 deletion lib/risc0
Submodule risc0 updated 103 files
21 changes: 15 additions & 6 deletions script/BonsaiDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {BonsaiRelay} from "bonsai/BonsaiRelay.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiRelay} from "bonsai/relay/BonsaiRelay.sol";
import {BonsaiCheats} from "bonsai/BonsaiCheats.sol";
import {BonsaiTestRelay} from "bonsai/BonsaiTestRelay.sol";
import {ControlID, RiscZeroGroth16Verifier} from "bonsai/groth16/RiscZeroGroth16Verifier.sol";
import {BonsaiTestRelay} from "bonsai/relay/BonsaiTestRelay.sol";
import {ControlID} from "bonsai/groth16/ControlID.sol";
import {RiscZeroGroth16Verifier} from "bonsai/groth16/RiscZeroGroth16Verifier.sol";
import {IRiscZeroVerifier} from "bonsai/IRiscZeroVerifier.sol";

/// @notice Base deployment script for Bonsai projects with Foundry and it's dependencies.
Expand Down Expand Up @@ -80,7 +81,10 @@ contract BonsaiDeploy is Script, BonsaiCheats {
console2.log("Using IRiscZeroVerifier at ", address(verifierAddr));
verifier = IRiscZeroVerifier(verifierAddr);
} else {
verifier = new RiscZeroGroth16Verifier(ControlID.CONTROL_ID_0, ControlID.CONTROL_ID_1);
verifier = new RiscZeroGroth16Verifier(
ControlID.CONTROL_ID_0,
ControlID.CONTROL_ID_1
);
console2.log("Deployed RiscZeroGroth16Verifier to ", address(verifier));
}

Expand All @@ -103,7 +107,12 @@ contract BonsaiDeploy is Script, BonsaiCheats {
// Use a long and unweildy environment variable name for overriding
// the expected chain ID for the test relay so that it is hard to
// trigger without thinking about it.
bonsaiRelay = new BonsaiTestRelay(vm.envOr("DEPLOY_BONSAI_TEST_RELAY_EXPECTED_CHAIN_ID", uint256(31337)));
bonsaiRelay = new BonsaiTestRelay(
vm.envOr(
"DEPLOY_BONSAI_TEST_RELAY_EXPECTED_CHAIN_ID",
uint256(31337)
)
);
console2.log("Deployed BonsaiTestRelay to ", address(bonsaiRelay));
}
return bonsaiRelay;
Expand Down
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiCheats} from "bonsai/BonsaiCheats.sol";

import {BonsaiDeploy} from "./BonsaiDeploy.sol";
Expand Down
14 changes: 10 additions & 4 deletions tests/BonsaiStarter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pragma solidity ^0.8.17;

import {BonsaiTest} from "bonsai/BonsaiTest.sol";
import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiStarter} from "contracts/BonsaiStarter.sol";

contract BonsaiStarterTest is BonsaiTest {
Expand All @@ -27,12 +27,15 @@ contract BonsaiStarterTest is BonsaiTest {
function testOffChainMock() public {
bytes32 imageId = queryImageId("FIBONACCI");
// Deploy a new starter instance
BonsaiStarter starter = new BonsaiStarter(IBonsaiRelay(bonsaiRelay), imageId);
BonsaiStarter starter = new BonsaiStarter(
IBonsaiRelay(bonsaiRelay),
imageId
);

// Anticipate a callback invocation on the starter contract
vm.expectCall(address(starter), abi.encodeWithSelector(BonsaiStarter.storeResult.selector));
// Relay the solution as a callback
uint64 BONSAI_CALLBACK_GAS_LIMIT = 100000;
uint64 BONSAI_CALLBACK_GAS_LIMIT = 300000;
runCallbackRequest(
imageId, abi.encode(128), address(starter), starter.storeResult.selector, BONSAI_CALLBACK_GAS_LIMIT
);
Expand All @@ -45,7 +48,10 @@ contract BonsaiStarterTest is BonsaiTest {
// Test the BonsaiStarter contract by mocking an on-chain callback request
function testOnChainMock() public {
// Deploy a new starter instance
BonsaiStarter starter = new BonsaiStarter(IBonsaiRelay(bonsaiRelay), queryImageId("FIBONACCI"));
BonsaiStarter starter = new BonsaiStarter(
IBonsaiRelay(bonsaiRelay),
queryImageId("FIBONACCI")
);

// Anticipate an on-chain callback request to the relay
vm.expectCall(address(bonsaiRelay), abi.encodeWithSelector(IBonsaiRelay.requestCallback.selector));
Expand Down
2 changes: 1 addition & 1 deletion tests/BonsaiStarterLowLevel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pragma solidity ^0.8.17;

import {BonsaiTest} from "bonsai/BonsaiTest.sol";
import {IBonsaiRelay} from "bonsai/IBonsaiRelay.sol";
import {IBonsaiRelay} from "bonsai/relay/IBonsaiRelay.sol";
import {BonsaiStarterLowLevel} from "../contracts/BonsaiStarterLowLevel.sol";

contract BonsaiStarterLowLevelTest is BonsaiTest {
Expand Down

0 comments on commit 0d274a0

Please sign in to comment.