Skip to content

Conversation

@zodiacbuilds
Copy link
Collaborator

Latest branch for fixing unit test errors working with yarn to be consistent with Temple monorepo

zodiacbuilds and others added 30 commits June 15, 2023 17:11
restyled layout according to layout guidelines
Added comments regarding the TODO for portions of code that need
to be adjusted based on review and feedback.
Created grant Minter Role after verifying signature of msg.sender as signer.
//TODO Add clean comments to every line.
//TODO Installed prettier but it seems to be clashing with Solidity extension.
Replaced AccessControl with Ownable.
InstalledOZ Contracts versions now match according to dependency in package.json.
//TODO Add in test case for msg.sender being able to obtain minter role
//TODO Add in test case for minter role being able to mint
//TODO Add in const for domain
//TODO: Fix weird error requesting for different compiler version despite 0.8.18 successfully compiling.
* @notice interfaced from Shards.sol to obtain address, token Id, amount owned and stored data
* for future use
*/
interface IShards {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: put interfaces in an external file

// Shards and domain separator constant is initialised
// using name, version and Arbitrum Goerli chainID.
constructor() {
if (msg.sender != owner()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think this check is necessary

//Mapping SHARD_ID to the individual enclaves
uint256[] public SHARD_ID = [2, 3, 4, 5, 6];
string[] public ENCLAVE = [
"",
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the empty string for?


//for loop checks if the Enclave name matches the Shard ID
function establishMapping() public {
// Establish the mapping between SHARD_ID and ENCLAVE
Copy link
Collaborator

Choose a reason for hiding this comment

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

gas: uint256 _length = SHARD_ID.length;. and then use _length in the for loop

//for loop checks if the Enclave name matches the Shard ID
function establishMapping() public {
// Establish the mapping between SHARD_ID and ENCLAVE
for (uint256 i = 2; i < SHARD_ID.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this for loop doesn't map all values. starting from 2, you miss chaosEnclave.

uint256 _length = SHARD_ID.length;
for(uint i=0; i<_length) {
  shardToEnclave[SHARD_ID[i]] = ENCLAVE[i+1];
  unchecked {
    ++i;
  }
} 

You could also do this in the constructor as it's a one-time thing

if (_shardIndex < SHARD_ID.length || _shardIndex > SHARD_ID.length) {
revert InvalidMint(msg.sender);
}
SHARDS.partnerMint(msg.sender, SHARD_ID[_shardIndex], 1, "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have not set SHARDS to an address

// original deployer is granted the default admin role
// Shards and domain separator constant is initialised
// using name, version and Arbitrum Goerli chainID.
constructor() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have not set SHARDS or RELIC

if (err != ECDSA.RecoverError.NoError) {
revert InvalidSignature(request.account);
}
// Check for error if deadline is expired
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would put checks at beginning of function

// Defining the CONSTANTS which are of bytes32 type
bytes32 constant MINTREQUEST_TYPEHASH =
keccak256("MintRequest(address signer,uint256 deadline,uint256 nonce)");
bytes32 constant EIP712DOMAIN_TYPEHASH =
Copy link
Collaborator

Choose a reason for hiding this comment

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

add address verifyingContract

bytes32 private constant EIP712DOMAIN_TYPEHASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

Copy link
Collaborator

Choose a reason for hiding this comment

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

as seen here

keccak256(bytes(_input.name)),
keccak256(bytes(_input.version)),
_input.chainId
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

add verifyingAddress address(this). see link from previous comment

@@ -0,0 +1,95 @@
const { expect } = require("chai");
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove old file?

it("Check if mapping of enclave to Shard Id is correct", async function () {
await pathOfTheTemplarShard.establishMapping();

for (let i = 2; i < SHARD_ID.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i mentioned this in contract review, so update test

expect(await pathOfTheTemplarShard.minters(account)).to.equal(value);

});

Copy link
Collaborator

Choose a reason for hiding this comment

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

add tests that fail for owner guarded functions when called by nonowner

const signature = await add2._signTypedData(data.domain, data.types, data.message);

await pathOfTheTemplarShard.setMinter(await add2.getAddress(), true);
await pathOfTheTemplarShard.connect(add3).mintShard(MintRequest, signature, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why connect add3 and not add2?

pathOfTheTemplarShard,
} = await loadFixture(setup));
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

some tests are missing. check test coverage and add tests for view functions too


});

it("Check if a signer that is not whitelisted minter produces an invalid signature", async function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

get signed typed data of address which can't mint and expect custom error from contract after calling with:

  • invalid signature
  • can't mint address

@zodiacbuilds zodiacbuilds marked this pull request as draft July 23, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants