Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oyster Secret Storage Implementation #14

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4ee59da
secret store changes added
rajatlko13 Sep 23, 2024
57eb506
comments updated
rajatlko13 Sep 23, 2024
a3e63d6
more functions added to SecretStorage contract
rajatlko13 Sep 24, 2024
738a5e0
secret store contract splitted
rajatlko13 Sep 24, 2024
c139ef0
selectedEnclaves added to SecretStoreCreated event
rajatlko13 Sep 25, 2024
53996b4
SecretStoreCreated event updated
rajatlko13 Sep 25, 2024
ad101d9
secret store contracts renamed and other post review updates
rajatlko13 Sep 26, 2024
047b741
contract updates pushed
rajatlko13 Sep 27, 2024
2678318
secret store deployment script pushed
rajatlko13 Sep 27, 2024
cd9eb9b
secret store deployment script updated
rajatlko13 Sep 27, 2024
7c5a194
secret store contract updates
rajatlko13 Sep 30, 2024
4acc2d6
test cases pushed for SecretStore
rajatlko13 Sep 30, 2024
84b0cce
Secret Manager test cases added
rajatlko13 Oct 1, 2024
e811930
usdc value checks added to SecretManager test cases
rajatlko13 Oct 1, 2024
af342f4
indentation fixed in secret store test cases
rajatlko13 Oct 2, 2024
6b6b13e
Merge branch 'master' into rajat/secret-store
rajatlko13 Oct 2, 2024
ce1166c
addChainGlobal() logic updated for duplicate chains
rajatlko13 Oct 2, 2024
665d901
indentation fix
rajatlko13 Oct 2, 2024
2fbc7f9
test cases updated
rajatlko13 Oct 3, 2024
047593d
added check for all selected enclaves acknowledgement before end time…
rajatlko13 Oct 8, 2024
6c01211
updated logic for mark store alive/dead
rajatlko13 Oct 10, 2024
2806a05
secret contracts updated
rajatlko13 Oct 14, 2024
936136e
underflow condition fixed in secret store payment logic
rajatlko13 Oct 14, 2024
698ca2d
added ack fail logic for replaced stores
rajatlko13 Oct 14, 2024
77836ab
terminate and remove secret functions updated
rajatlko13 Oct 14, 2024
8f331a2
updates in ack fail function
rajatlko13 Oct 15, 2024
a2dca16
fixed usdc payment issue for dead store marked in the last epoch
rajatlko13 Oct 16, 2024
87f5183
review fixes for usdc payment for secret
rajatlko13 Oct 17, 2024
e097254
contracts and test cases updated
rajatlko13 Oct 21, 2024
605979e
Alive check signature fix done
rajatlko13 Nov 4, 2024
5d9fb9c
bug fix in contract and UTs updated
rajatlko13 Nov 4, 2024
bcc1449
fixed function getCurrentConfirmedUsdcDeposit()
rajatlko13 Nov 4, 2024
2ef609c
quick fix in _markEnclaveDead()
rajatlko13 Nov 4, 2024
78a6a81
missing test cases added for SecretStore
rajatlko13 Nov 5, 2024
6ae9c3b
mark dead logic updated in SecretManager
rajatlko13 Nov 15, 2024
8fdc10b
nit fix - function name updated
rajatlko13 Nov 15, 2024
ed8e74e
storeSecretIds and deadTimestamp mapping moved to SecretStore contract
rajatlko13 Nov 15, 2024
4814c84
markAlive() updated
rajatlko13 Nov 19, 2024
0807a46
markAlive() logic fix
rajatlko13 Nov 19, 2024
b92efce
nit fix
rajatlko13 Nov 21, 2024
b741bad
secret store slashing logic updated
rajatlko13 Nov 22, 2024
492c7f7
secret store slashing logic bug resolved
rajatlko13 Nov 26, 2024
d700780
markAlive bug fix
rajatlko13 Nov 27, 2024
ffe578b
secret store test cases updated
rajatlko13 Nov 27, 2024
16b32e0
markDead gas estimate script pushed
rajatlko13 Nov 28, 2024
556cd82
secret store + job allocation changes pushed
rajatlko13 Dec 3, 2024
6a72098
executors code combined in secret store contract
rajatlko13 Dec 4, 2024
2d1373e
review bug fixes
rajatlko13 Dec 4, 2024
ecd6ca3
function logic updated
rajatlko13 Dec 5, 2024
3d986cb
SecretStore contract splitted
rajatlko13 Dec 6, 2024
ac6280a
review bug fixes
rajatlko13 Dec 9, 2024
aed7337
new structure for secret store and executors contract
rajatlko13 Dec 15, 2024
4d5c420
review issues fixed
rajatlko13 Dec 17, 2024
558fd1f
reputation logic moved to Executors
rajatlko13 Dec 17, 2024
26e5098
updated logic for adding back nodes to the tree post selection
rajatlko13 Dec 17, 2024
7a89e1c
slash store exponent issue resolved
rajatlko13 Dec 19, 2024
d2e8275
review bug fixes and updated test cases
rajatlko13 Dec 23, 2024
27bf83a
bug fixes and jobs UTs updated
rajatlko13 Dec 24, 2024
7f548e1
renounceSecrets function added
rajatlko13 Dec 25, 2024
139e91c
renounceSecret review fixes
rajatlko13 Dec 31, 2024
179a848
renounceSecrets() moved to SecretStore
rajatlko13 Dec 31, 2024
d3dcefe
quick fixes
rajatlko13 Dec 31, 2024
d8428dd
UT bug fixes
rajatlko13 Jan 6, 2025
f30c569
createJob function updated - only select from secret stores
rajatlko13 Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion contracts/mocks/JobsUser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,30 @@ contract JobsUser {

event FailedCallback(uint256 indexed jobId, uint256 slashedAmount);

// function createJob(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still being used in the serverless-v2 contracts, so let's keep it for now.

// uint8 _env,
// bytes32 _codehash,
// bytes memory _codeInputs,
// uint256 _userTimeout,
// uint256 _usdcDeposit
// ) external payable returns (bool success) {
// token.safeIncreaseAllowance(jobs, _usdcDeposit);

// (bool _success, ) = jobs.call(
// abi.encodeWithSignature(
// "createJob(uint8,bytes32,bytes,uint256)",
// _env,
// _codehash,
// _codeInputs,
// _userTimeout
// )
// );
// return _success;
// }

function createJob(
uint8 _env,
uint256 _secretId,
bytes32 _codehash,
bytes memory _codeInputs,
uint256 _userTimeout,
Expand All @@ -32,8 +54,9 @@ contract JobsUser {

(bool _success, ) = jobs.call(
abi.encodeWithSignature(
"createJob(uint8,bytes32,bytes,uint256)",
"createJob(uint8,uint256,bytes32,bytes,uint256)",
_env,
_secretId,
_codehash,
_codeInputs,
_userTimeout
Expand Down
167 changes: 167 additions & 0 deletions contracts/mocks/TeeManagerMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../secret-storage/SecretStore.sol";
import "../secret-storage/Executors.sol";
import "@openzeppelin/contracts/utils/Context.sol";

contract TeeManagerMock is Context {

Executors public EXECUTORS;
SecretStore public SECRET_STORE;
uint256 public immutable MIN_STAKE_AMOUNT;

struct TeeNode {
uint256 stakeAmount;
address owner;
uint8 env;
bool draining;
}

// enclaveAddress => TEE node details
mapping(address => TeeNode) public teeNodes;

constructor(
uint256 _minStakeAmount
) {
MIN_STAKE_AMOUNT = _minStakeAmount;
}

function setExecutors(Executors _executors) external {
EXECUTORS = _executors;
}

function setSecretStore(SecretStore _secretStore) external {
SECRET_STORE = _secretStore;
}

// --------------------------------- Executors functions start ---------------------------------

function registerExecutor(
address _enclaveAddress,
uint256 _jobCapacity,
uint8 _env,
uint256 _stakeAmount
) external {
teeNodes[_enclaveAddress].env = _env;
teeNodes[_enclaveAddress].owner = _msgSender();
teeNodes[_enclaveAddress].stakeAmount = _stakeAmount;

EXECUTORS.registerExecutor(_enclaveAddress, _jobCapacity, _env, _stakeAmount);
}

function deregisterExecutor(address _enclaveAddress) external {
EXECUTORS.deregisterExecutor(_enclaveAddress);
}

function drainExecutor(
address _enclaveAddress,
uint8 _env
) external {
EXECUTORS.drainExecutor(_enclaveAddress, _env);
}

function reviveExecutor(
address _enclaveAddress,
uint8 _env,
uint256 _stakeAmount
) external {
EXECUTORS.reviveExecutor(_enclaveAddress, _env, _stakeAmount);
}

function addExecutorStake(
address _enclaveAddress,
uint8 _env,
uint256 _stake
) external {
EXECUTORS.addExecutorStake(_enclaveAddress, _env, _stake);
}

function removeExecutorStake(
address _enclaveAddress
) external view {
EXECUTORS.removeExecutorStake(_enclaveAddress);
}

function slashExecutor(
address _enclaveAddress,
address _recipient
) external returns (uint256) {
return 0;
}

// ---------------------------------- Executors functions end -------------------------------------

// --------------------------------- Secret Store functions start ---------------------------------

function registerSecretStore(
address _enclaveAddress,
uint256 _storageCapacity,
uint8 _env,
uint256 _stakeAmount
) external {
teeNodes[_enclaveAddress].env = _env;
teeNodes[_enclaveAddress].owner = _msgSender();
teeNodes[_enclaveAddress].stakeAmount = _stakeAmount;

SECRET_STORE.registerSecretStore(
_enclaveAddress,
_storageCapacity,
_env,
_stakeAmount
);
}

function deregisterSecretStore(address _enclaveAddress) external {
SECRET_STORE.deregisterSecretStore(_enclaveAddress);
}

function drainSecretStore(
address _enclaveAddress,
uint8 _env,
address _owner
) external {
SECRET_STORE.drainSecretStore(_enclaveAddress, _env, _owner);
}

function reviveSecretStore(
address _enclaveAddress,
uint8 _env,
uint256 _stakeAmount
) external {
SECRET_STORE.reviveSecretStore(_enclaveAddress, _env, _stakeAmount);
}

function addSecretStoreStake(
address _enclaveAddress,
uint8 _env,
uint256 _stake
) external {
SECRET_STORE.addSecretStoreStake(_enclaveAddress, _env, _stake);
}

function removeSecretStoreStake(
address _enclaveAddress
) external view {
SECRET_STORE.removeSecretStoreStake(_enclaveAddress);
}

function slashStore(
address _enclaveAddress,
uint256 _missedEpochsCount,
address _recipient
) external {}

// --------------------------------- Secret Store functions end ---------------------------------

function getTeeNodesStake(
address[] memory _enclaveAddresses
) external view returns (uint256[] memory) {
uint256 len = _enclaveAddresses.length;
uint256[] memory stakeAmounts = new uint256[](len);
for (uint256 index = 0; index < len; index++)
stakeAmounts[index] = teeNodes[_enclaveAddresses[index]].stakeAmount;

return stakeAmounts;
}

}
Loading