Skip to content

Commit

Permalink
use Roles
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Feb 15, 2024
1 parent c5ef071 commit ba82272
Show file tree
Hide file tree
Showing 7 changed files with 6,585 additions and 6,161 deletions.
18 changes: 12 additions & 6 deletions contracts/RemixChallenges.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ contract RemixChallenges is Initializable, AccessControlUpgradeable, UUPSUpgrade
(bool verified) = abi.decode(data, (bool));
require(verified, "the provided proof isn't valid");

challenge.publishersCount++;

nullifiers[nullifier] = 1;
publishers[publisher] = 1;

// function safeMint(address to, string memory tokenType, string memory payload, bytes memory hash, uint mintGrant) public onlyRole(DEFAULT_ADMIN_ROLE)
(bool successMint,) = rewardContract.call{ value: 0 }(
(bool successMint, bytes memory dataMint) = rewardContract.call{ value: 0 }(
abi.encodeWithSignature("safeMint(address,string,string,bytes,uint256)",
msg.sender,
challenge.tokenType,
Expand All @@ -81,11 +86,12 @@ contract RemixChallenges is Initializable, AccessControlUpgradeable, UUPSUpgrade
)
);

challenge.publishersCount++;

nullifiers[nullifier] = 1;
publishers[publisher] = 1;
require(successMint, "the call to the minter failed");
if (!successMint) {
if (dataMint.length == 0) revert();
assembly {
revert(add(32, dataMint), mload(dataMint))
}
}
}

function _authorizeUpgrade(address newImplementation) internal override {
Expand Down
30 changes: 28 additions & 2 deletions contracts/RemixRewardUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,31 @@ contract Remix is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable,

modifier isTrainer() {
require(trainers[msg.sender] == 1, "Caller is not a trainer");
require(hasRole(TRAINER_ROLE, msg.sender), "Caller is not a trainer, no TRAINER_ROLE");
_;
}

modifier challengeProvider() {
require(hasRole(CHALLENGE_PROVIDER_ROLE, msg.sender), "Caller is not a trainer, no TRAINER_ROLE");
_;
}

modifier isAdmin() {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Caller is not a admin");
_;
}

modifier canSafeMint() {
require(
hasRole(CHALLENGE_PROVIDER_ROLE, msg.sender) ||
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
"Caller is neither admin nor a challenge provider");
_;
}

bytes32 public constant TRAINER_ROLE = 0x0000000000000000000000000000000000000000000000000000000000000001;
bytes32 public constant CHALLENGE_PROVIDER_ROLE = 0x0000000000000000000000000000000000000000000000000000000000000002;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {}

Expand Down Expand Up @@ -82,7 +104,7 @@ contract Remix is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable,
override
{}

function addType (string calldata tokenType) public onlyRole(DEFAULT_ADMIN_ROLE) {
function addType (string calldata tokenType) public canSafeMint {
types[tokenType] = true;
}

Expand All @@ -94,7 +116,9 @@ contract Remix is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable,
contributorHash = hash;
}

function safeMint(address to, string calldata tokenType, string memory payload, bytes memory hash, uint mintGrant) public onlyRole(DEFAULT_ADMIN_ROLE) {
function safeMint(address to, string calldata tokenType, string memory payload, bytes memory hash, uint mintGrant)
public
canSafeMint {
addType(tokenType);
mintBadge(to, tokenType, payload, hash, mintGrant);
}
Expand Down Expand Up @@ -139,10 +163,12 @@ contract Remix is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable,

function addTrainer (address trainer) public onlyRole(DEFAULT_ADMIN_ROLE) {
trainers[trainer] = 1;
grantRole(TRAINER_ROLE, trainer);
}

function removeTrainer (address trainer) public onlyRole(DEFAULT_ADMIN_ROLE) {
delete trainers[trainer];
revokeRole(TRAINER_ROLE, trainer);
}

function grantRemixersMinting (address[] calldata remixers, uint amount) public isTrainer() {
Expand Down
10,740 changes: 5,661 additions & 5,079 deletions contracts/artifacts/Remix.json

Large diffs are not rendered by default.

1,916 changes: 850 additions & 1,066 deletions contracts/artifacts/RemixChallenges.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/artifacts/RemixChallenges_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,11 @@
]
},
"contracts/RemixChallenges.sol": {
"keccak256": "0xb8d24aa9f7c0e1a8b0eb8b16c833d972a7d8dfdc73bdfc633c83c42f463bdd5c",
"keccak256": "0xd336fecdb3fa8a4a05f2f49dea26cad35ccf132ae2a32ce3df7f17020050c213",
"license": "MIT",
"urls": [
"bzz-raw://4d2792a977ea89b582206519f9541c443ae2c6dc7e8dd8c1614b6643cc78e319",
"dweb:/ipfs/QmZWx6vtQ3XksCwgS6CVtGKfoPhzzCWdttR8BwsXEmjLTA"
"bzz-raw://5c44dc95488a5e1e74dcfe13d99c46a958e7bd24016b20ddf14f1782e2c018c9",
"dweb:/ipfs/Qmeich2yFj3A9qVQAz1jJdb6CtrvJ4S957sGoWAYCqSr7G"
]
}
},
Expand Down
32 changes: 29 additions & 3 deletions contracts/artifacts/Remix_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@
"name": "Upgraded",
"type": "event"
},
{
"inputs": [],
"name": "CHALLENGE_PROVIDER_ROLE",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "DEFAULT_ADMIN_ROLE",
Expand All @@ -231,6 +244,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TRAINER_ROLE",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1431,11 +1457,11 @@
]
},
"contracts/RemixRewardUpgradable.sol": {
"keccak256": "0x88363e198a7375571dc5d171375f934e6ba7eef98b10f0aa4227ad3c17398d5f",
"keccak256": "0x57e3ba5f94598c6c1bdbcf5516882917781d82cc3936147c46fcc9e2312f4588",
"license": "MIT",
"urls": [
"bzz-raw://4fe2a70061b357b740127ebe43391bfcd30486342806f2d5fd3da998052c7ada",
"dweb:/ipfs/QmfBMQE2jGk2XhJ6QujK8BHGCnhQC1GqxGyyoqt3b5TKQc"
"bzz-raw://936abc2edcd9f19d681360c9e211d0c6c16048d0dfdca5d0aac596cc7f3a7edc",
"dweb:/ipfs/QmRVp6oaFZU2uDWSa7wqbdHyYoezRCJxYpsVYKMLLojeEk"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("Basic minting", function () {

it("Should not be allowed minting", async function () {
const ipfsHash = '0xabcd1234'
await expect(remix.connect(betatester).safeMint(betatester.address, 'Beta Tester', '0.22.0', ipfsHash, 2)).to.be.revertedWith('is missing role 0x0000000000000000000000000000000000000000000000000000000000000000')
await expect(remix.connect(betatester).safeMint(betatester.address, 'Beta Tester', '0.22.0', ipfsHash, 2)).to.be.revertedWith('Caller is neither admin nor a challenge provider')
});
});

Expand Down Expand Up @@ -149,7 +149,7 @@ describe("Challenge", function () {
})

it("Should call the remix reward contract to set the correct permission to the challenges contract", async function () {
const tx = await remix.connect(owner).grantRole('0x0000000000000000000000000000000000000000000000000000000000000000', remixChallenges.address);
const tx = await remix.connect(owner).grantRole('0x0000000000000000000000000000000000000000000000000000000000000002', remixChallenges.address);
await tx.wait()
})

Expand Down

0 comments on commit ba82272

Please sign in to comment.