Skip to content

Commit

Permalink
add 'confidential' modifier to Suapp
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroXbrock committed Jul 18, 2024
1 parent 17db5e0 commit f69da9a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Suapp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.8;

import "./Logs.sol";
import {Suave} from "./suavelib/Suave.sol";

/// @notice Suapp is a contract with general utilities for a Suapp.
contract Suapp {
Expand All @@ -10,4 +11,9 @@ contract Suapp {
Logs.decodeLogs(msg.data);
_;
}

modifier confidential() {
require(Suave.isConfidential(), "must be called confidentially");
_;
}
}
25 changes: 25 additions & 0 deletions test/Forge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ import "forge-std/Test.sol";
import "src/Test.sol";
import "src/suavelib/Suave.sol";
import "src/Context.sol";
import {Suapp} from "src/Suapp.sol";

contract NumberSuapp is Suapp {
uint256 public number;

function onSetNumber(uint256 num) public {
number = num;
}

function setNumber() public confidential returns (bytes memory) {
uint256 num = abi.decode(Context.confidentialInputs(), (uint256));
return abi.encodeWithSelector(this.onSetNumber.selector, num);
}
}

contract TestConfidential is Test, SuaveEnabled {
function testConfidentialResponse() public {
NumberSuapp suapp = new NumberSuapp();

ctx.setConfidentialInputs(abi.encode(123));

bytes memory suaveCalldata = suapp.setNumber();
assertEq(suaveCalldata.length, 4 + 32);
}
}

contract TestForge is Test, SuaveEnabled {
address[] public addressList = [0xC8df3686b4Afb2BB53e60EAe97EF043FE03Fb829];
Expand Down

0 comments on commit f69da9a

Please sign in to comment.