Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
10 changes: 9 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ deploy.sh
setAp.sh
upgrade.sh
remix-compiler.config.js
hardhat.config.js
hardhat.config.js

#Foundry files
foundry.toml
remappings.txt
lib
out
forge-cache
.gitmodules
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Empty file modified README.md
100644 → 100755
Empty file.
6 changes: 0 additions & 6 deletions args/goerli.js

This file was deleted.

9 changes: 0 additions & 9 deletions args/mumbai.js

This file was deleted.

Binary file added audit/SlowMist Audit Report - DID SYNC .pdf
Binary file not shown.
Binary file removed audit/SlowMist Audit Report - did-sync.pdf
Binary file not shown.
43 changes: 28 additions & 15 deletions constants/chainIds.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
{
"ethereum": 1,
"bsc": 2,
"avalanche": 6,
"polygon": 9,
"arbitrumOne": 10,
"optimism": 11,
"platon": 100,
"ethereum": 101,
"polygon": 109,
"moonbeam": 126,
"bsc": 102,
"avalanche": 106,
"arbitrumOne": 110,
"optimism": 111,
"iris": 99,
"aptos": 98,

"platon_dev": 10120,
"goerli_dev": 10121,
"bsc-testnet": 10002,
"fuji": 10006,
"mumbai_dev": 10109,
"arbitrum-rinkeby": 10010,
"optimism-kovan": 10011,
"moombase_dev": 10126
}
"aptos_qa": 10118,
"iris_qa": 10119,
"platon_stg": 10120,
"platon_qa": 10120,
"platon_dev": 10120,
"goerli_stg": 10121,
"goerli_qa": 10121,
"goerli_dev": 10121,
"mumbai_stg": 10109,
"mumbai_qa": 10109,
"mumbai_dev": 10109,
"moombase_stg": 10126,
"moombase_qa": 10126,
"moombase_dev": 10126,
"bsctestnet_qa": 10102,
"bsctestnet_stg": 10102,
"bsctestnet_dev": 10102
}
17 changes: 11 additions & 6 deletions constants/layerzeroEndpoints.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{
"ethereum": "0x66A71Dcef29A0fFBDBE3c6a460a3B5BC225Cd675",
"bsc": "0x3c2269811836af69497E5F486A85D7316753cf62",
"avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62",
"moonbeam": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4",
"polygon": "0x3c2269811836af69497E5F486A85D7316753cf62",
"platon": "hashkeydid contract address",
"avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62",
"arbitrumOne": "0x3c2269811836af69497E5F486A85D7316753cf62",
"optimism": "0x3c2269811836af69497E5F486A85D7316753cf62",

"platon_dev": "0x3cB89e8540CD78c62Bcf4f91A90156BFEF309CE0",
"goerli_dev": "0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23",
"iris_qa": "0x6b4Ed0Fb2E070fe4ed73d61d10Ab9f2e8B5cd9e0",
"platon_stg": "0x3cB89e8540CD78c62Bcf4f91A90156BFEF309CE0",
"goerli_stg": "0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23",
"bsc-testnet": "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1",
"fuji": "0x93f54D755A063cE7bB9e6Ac47Eccc8e33411d706",
"mumbai_dev": "0xf69186dfBa60DdB133E91E9A4B5673624293d8F8",
"mumbai_stg": "0xf69186dfBa60DdB133E91E9A4B5673624293d8F8",
"arbitrum-rinkeby": "0x4D747149A57923Beb89f22E6B7B97f7D8c087A00",
"optimism-kovan": "0x72aB53a133b27Fa428ca7Dc263080807AfEc91b5",
"moombase_dev": "0xb23b28012ee92E8dE39DEb57Af31722223034747"
"moombase_stg": "0xb23b28012ee92E8dE39DEb57Af31722223034747",
"bsctestnet_qa": "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1",
"bsctestnet_stg": "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1",
"bsctestnet_dev": "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1"
}
117 changes: 98 additions & 19 deletions contracts/DidSync.sol
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ struct Payload {
IDid.KYCInfo[] KYCInfo;
bytes[] evidence;
bytes evidenceLZ;
bytes nonEVMAddress;
}

contract DidSync is NonblockingLzAppUpgradeable, SyncStorage {

///@dev Emmited when user sync KYC information
event SendToChain(address user, uint16 indexed dstChainId, uint256 tokenId);
event ReceiveFromChain(uint16 _srcChainId, bytes srcAddress, uint256 tokenId, uint64 nonce);
event SendToChain(address user, uint16 indexed dstChainId, uint256 tokenId, bytes nonEVMAddress);
event ReceiveFromChain(
uint16 _srcChainId,
bytes srcAddress,
uint256 tokenId,
uint64 nonce
);

/// @dev Initialize only once
/// @param _endpoint LzApp endpoint
Expand All @@ -33,11 +38,18 @@ contract DidSync is NonblockingLzAppUpgradeable, SyncStorage {
__NonblockingLzAppUpgradeable_init(_endpoint);
}

function setAdapterParams(uint16 version, uint gasForDestinationLzReceive) public onlyOwner {
function setAdapterParams(
uint16 version,
uint gasForDestinationLzReceive
) public onlyOwner {
adapterParams = abi.encodePacked(version, gasForDestinationLzReceive);
}

function setMaxKYCNumberWithGas(uint256 _maxKYCNumber, uint16 version, uint gasForDestinationLzReceive) public onlyOwner {
function setMaxKYCNumberWithGas(
uint256 _maxKYCNumber,
uint16 version,
uint gasForDestinationLzReceive
) public onlyOwner {
maxKYCNumber = _maxKYCNumber;
adapterParams = abi.encodePacked(version, gasForDestinationLzReceive);
}
Expand All @@ -46,12 +58,35 @@ contract DidSync is NonblockingLzAppUpgradeable, SyncStorage {
/// @param _dstChainId Destination chain id
/// @param _payload transfer payload
function sync(Payload memory _payload, uint16 _dstChainId) public payable {
require(IDid(did).ownerOf(_payload.tokenId) == msg.sender && _payload.user == msg.sender && keccak256(abi.encodePacked(_payload.did)) == keccak256(abi.encodePacked(IDid(did).tokenId2Did(_payload.tokenId))), "DidSync: not owner or invalid args");
require(_validate(keccak256(abi.encodePacked(_payload.user, _payload.tokenId, _payload.did)), _payload.evidenceLZ, IDid(did).signer()), "DidSync: invalid signature");
require(
IDid(did).ownerOf(_payload.tokenId) == msg.sender &&
_payload.user == msg.sender &&
keccak256(abi.encodePacked(_payload.did)) ==
keccak256(
abi.encodePacked(IDid(did).tokenId2Did(_payload.tokenId))
),
"DidSync: not owner or invalid args"
);
require(
_validate(
keccak256(
abi.encodePacked(
_payload.user,
_payload.tokenId,
_payload.did
)
),
_payload.evidenceLZ,
IDid(did).signer()
),
"DidSync: invalid signature"
);
bytes memory payload = abi.encode(_payload);
// _dstChainId: layer zero trusted remote chain id, initialized PlatON as 100.
// block.chainid: PlatON chain id.
if(_dstChainId != 100 && block.chainid != 210425){
// testnet
// if (_dstChainId != 10120 && block.chainid != 2206132 && _dstChainId != 10119 && block.chainid != 16688 && _dstChainId != 10118)
if (_dstChainId != 100 && block.chainid != 210425 && _dstChainId != 99 && block.chainid != 6688 && _dstChainId != 98) {
_lzSend(
_dstChainId,
payload,
Expand All @@ -60,25 +95,69 @@ contract DidSync is NonblockingLzAppUpgradeable, SyncStorage {
adapterParams
);
} else {
require(payable(did).send(msg.value), "Failed to send Ether");
(bool sent, ) = payable(did).call{value: msg.value}("");
require(sent, "Failed to send Ether");
}
emit SendToChain(msg.sender, _dstChainId, _payload.tokenId);
emit SendToChain(msg.sender, _dstChainId, _payload.tokenId, _payload.nonEVMAddress);
}

/// @dev Receive KYC information from other chains
/// @param _payload Payload
function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal override {
(Payload memory payload) = abi.decode(_payload, (Payload));
require(_validate(keccak256(abi.encodePacked(payload.user, payload.tokenId, payload.did)), payload.evidenceLZ, IDid(did).signer()), "DidSync: invalid signature");
require(payload.KYCProvider.length <= maxKYCNumber, "DidSync: invalid KYCProvider length");
IDid(did).mintDidLZ(payload.tokenId, payload.user, payload.did, payload.avatar, payload.KYCProvider, payload.KYCId, payload.KYCInfo, payload.evidence);
emit ReceiveFromChain(_srcChainId, _srcAddress, payload.tokenId, _nonce);
function _nonblockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal override {
Payload memory payload = abi.decode(_payload, (Payload));
require(
_validate(
keccak256(
abi.encodePacked(payload.user, payload.tokenId, payload.did)
),
payload.evidenceLZ,
IDid(did).signer()
),
"DidSync: invalid signature"
);
require(
payload.KYCProvider.length <= maxKYCNumber,
"DidSync: invalid KYCProvider length"
);
IDid(did).mintDidLZ(
payload.tokenId,
payload.user,
payload.did,
payload.avatar,
payload.KYCProvider,
payload.KYCId,
payload.KYCInfo,
payload.evidence
);
emit ReceiveFromChain(
_srcChainId,
_srcAddress,
payload.tokenId,
_nonce
);
}

function estimateSendFee(Payload memory _payload, uint16 _dstChainId, bool _useZro, bytes memory _adapterParams) public view virtual returns (uint nativeFee, uint zroFee) {
function estimateSendFee(
Payload memory _payload,
uint16 _dstChainId,
bool _useZro,
bytes memory _adapterParams
) public view virtual returns (uint nativeFee, uint zroFee) {
// mock the payload for send()
bytes memory payload = abi.encode(_payload);
return lzEndpoint.estimateFees(_dstChainId, address(this), payload, _useZro, _adapterParams);
return
lzEndpoint.estimateFees(
_dstChainId,
address(this),
payload,
_useZro,
_adapterParams
);
}

/// @dev validate signature msg
Expand All @@ -98,4 +177,4 @@ contract DidSync is NonblockingLzAppUpgradeable, SyncStorage {
}
return ecrecover(message, v, r, s) == signer;
}
}
}
Empty file modified contracts/EternalStorageProxy.sol
100644 → 100755
Empty file.
Empty file modified contracts/SyncStorage.sol
100644 → 100755
Empty file.
Empty file modified contracts/interfaces/IDid.sol
100644 → 100755
Empty file.
Empty file modified contracts/interfaces/ILayerZeroEndpointUpgradeable.sol
100644 → 100755
Empty file.
Empty file modified contracts/interfaces/ILayerZeroReceiverUpgradeable.sol
100644 → 100755
Empty file.
Empty file.
Empty file modified contracts/lzApp/LzAppUpgradeable.sol
100644 → 100755
Empty file.
Empty file modified contracts/lzApp/NonblockingLzAppUpgradeable.sol
100644 → 100755
Empty file.
Empty file modified deploy/DidSync.js
100644 → 100755
Empty file.
Empty file modified deploy/ExternalStorageProxy.js
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 2b58ec
Loading