Skip to content

Commit

Permalink
adding contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Nov 30, 2024
1 parent 358e88d commit 3204e37
Show file tree
Hide file tree
Showing 12 changed files with 2,106 additions and 24 deletions.
24 changes: 18 additions & 6 deletions contracts/scripts/native_solc_zksolc_compile_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ echo " ┌───────────────────────
echo " │ Compiling CCIP contracts... │"
echo " └──────────────────────────────────────────────┘"

SOLC_VERSION="0.8.24"
SOLC_VERSION="0.8.19"
OPTIMIZE_RUNS=26000
OPTIMIZE_RUNS_OFFRAMP=18000
OPTIMIZE_RUNS_ONRAMP=4100
Expand All @@ -15,7 +15,7 @@ OPTIMIZE_RUNS_MULTI_OFFRAMP=800

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
python3 -m pip install --require-hashes -r "$SCRIPTPATH"/requirements.txt
solc-select install $SOLC_VERSION
# solc-select install $SOLC_VERSION
solc-select use $SOLC_VERSION
export SOLC_VERSION=$SOLC_VERSION

Expand Down Expand Up @@ -87,9 +87,18 @@ compileContractZK () {
}


# compileContract ccip/Storage.sol
# compileContractZK ccip/Storage.sol

# compileContract ccip/EVMCustom.sol
# compileContractZK ccip/EVMCustom.sol

compileContract ccip/RBACTimelock.sol
compileContractZK ccip/RBACTimelock.sol

compileContract ccip/manyChainMultisig.sol
compileContractZK ccip/manyChainMultisig.sol

compileContract ccip/Storage.sol
compileContractZK ccip/Storage.sol
# Solc produces and overwrites intermediary contracts.
# Contracts should be ordered in reverse-import-complexity-order to minimize overwrite risks.
# compileContract ccip/offRamp/EVM2EVMOffRamp.sol
Expand Down Expand Up @@ -207,16 +216,17 @@ compileContractZK ccip/Storage.sol
# compileContractZK tests/MockV3Aggregator.sol


# SOLC_VERSION="0.8.19"
# SOLC_VERSION="0.5.16"
# solc-select install $SOLC_VERSION
# solc-select use $SOLC_VERSION
# export SOLC_VERSION=$SOLC_VERSION


# compileContractShared () {
# local contract
# contract=$(basename "$1" ".sol")

# solc --overwrite --optimize --optimize-runs $OPTIMIZE_RUNS --metadata-hash none \
# solc --overwrite --optimize --optimize-runs $OPTIMIZE_RUNS \
# -o "$ROOT"/contracts/solc/v$SOLC_VERSION/"$contract" \
# --abi --bin --allow-paths "$ROOT"/contracts/src/v0.8\
# "$ROOT"/contracts/src/v0.8/"$1"
Expand All @@ -232,5 +242,7 @@ compileContractZK ccip/Storage.sol
# "$ROOT"/contracts/src/v0.8/"$1"
# }

# compileContractShared ccip/opCodes.sol
# compileContractSharedZK ccip/opCodes.sol
# compileContractShared shared/token/ERC677/LinkToken.sol
# compileContractSharedZK shared/token/ERC677/LinkToken.sol
64 changes: 64 additions & 0 deletions contracts/src/v0.8/ccip/AccessControlEnumerable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;

mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}

/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
return _roleMembers[role].at(index);
}

/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
return _roleMembers[role].length();
}

/**
* @dev Overload {_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
_roleMembers[role].add(account);
}

/**
* @dev Overload {_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
_roleMembers[role].remove(account);
}
}
140 changes: 140 additions & 0 deletions contracts/src/v0.8/ccip/EVMCustom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

// https://docs.moonbeam.network/builders/pallets-precompiles/precompiles/eth-mainnet/#hashing-with-sha256
contract EVMCustomTest {

//----------------- SHA-256 TEST -----------------//

bytes32 public expected256Hash =
0x7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069;

function calculate256Hash() internal pure returns (bytes32) {
string memory word = "Hello World!";
bytes32 hash = sha256(bytes(word));

return hash;
}

function check256Hash() public view returns (bool) {
return (calculate256Hash() == expected256Hash);
}

//----------------- RIPEMD160 TEST -----------------//

bytes20 public expectedHash = hex"8476ee4631b9b30ac2754b0ee0c47e161d3f724c";

function calculate160Hash() internal pure returns (bytes20) {
string memory word = "Hello World!";
bytes20 hash = ripemd160(bytes(word));

return hash;
}

function checkRipeMd160Hash() public view returns (bool) {
return (calculate160Hash() == expectedHash);
}

//----------------- GLOBAL VARIABLE TEST -----------------//

function getBlockVariables() public view returns (uint, uint, bytes32)
{
return (block.number, block.timestamp, blockhash(block.number - 1));
}

//----------------- ECRECOVER TEST -----------------//

address addressTest = 0x12Cb274aAD8251C875c0bf6872b67d9983E53fDd;
bytes32 msgHash =
0xc51dac836bc7841a01c4b631fa620904fc8724d7f9f1d3c420f0e02adf229d50;
uint8 v = 0x1b;
bytes32 r =
0x44287513919034a471a7dc2b2ed121f95984ae23b20f9637ba8dff471b6719ef;
bytes32 s =
0x7d7dc30309a3baffbfd9342b97d0e804092c0aeb5821319aa732bc09146eafb4;

function verifyECrecover() public view returns (bool) {
// Use ECRECOVER to verify address
return (ecrecover(msgHash, v, r, s) == (addressTest));
}

//----------------- BIG MOD EXP TEST -----------------//

uint public checkResult;

function verify(uint _base, uint _exp, uint _modulus) public {
checkResult = modExp(_base, _exp, _modulus);
}

function modExp(
uint256 _b,
uint256 _e,
uint256 _m
) public returns (uint256 result) {
assembly {
// Free memory pointer
let pointer := mload(0x40)
// Define length of base, exponent and modulus. 0x20 == 32 bytes
mstore(pointer, 0x20)
mstore(add(pointer, 0x20), 0x20)
mstore(add(pointer, 0x40), 0x20)
// Define variables base, exponent and modulus
mstore(add(pointer, 0x60), _b)
mstore(add(pointer, 0x80), _e)
mstore(add(pointer, 0xa0), _m)
// Store the result
let value := mload(0xc0)
// Call the precompiled contract 0x05 = bigModExp
if iszero(call(not(0), 0x05, 0, pointer, 0xc0, value, 0x20)) {
revert(0, 0)
}
result := mload(value)
}
}

//----------------- GAS PRICE OPCODE TEST -----------------//

uint64 gasprice;
uint64 dummy; // dummy variable to trick G++ provider to estimate correct gasLimit

function setGasPrice(uint64 t) external {
dummy = t + 1;
uint64 gp;
assembly {
gp := gasprice()
}
gasprice = gp;
}

function getGasPrice() external view returns (uint64) {
return gasprice;
}

//----------------- DATA COPY TEST -----------------//

bytes public memoryStored;

function callDatacopy(bytes memory data) public returns (bytes memory) {
bytes memory result = new bytes(data.length);
assembly {
let len := mload(data)
if iszero(
call(
gas(),
0x04,
0,
add(data, 0x20),
len,
add(result, 0x20),
len
)
) {
invalid()
}
}

memoryStored = result;

return result;
}
}
58 changes: 58 additions & 0 deletions contracts/src/v0.8/ccip/IERC1155Receiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
* @dev _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);

/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
27 changes: 27 additions & 0 deletions contracts/src/v0.8/ccip/IERC721Receiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
Loading

0 comments on commit 3204e37

Please sign in to comment.