From 509e3badbb70ca84c84db56f6ceb804cb548ebea Mon Sep 17 00:00:00 2001 From: RuilaiZhang Date: Thu, 15 Dec 2022 17:10:01 +1100 Subject: [PATCH] update verify function --- clients/contracts/bridge.ts | 7 +++---- contracts/Bridge.sol | 12 +++++------- contracts/DelphinusBridge.sol | 1 - contracts/MKT.sol | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/clients/contracts/bridge.ts b/clients/contracts/bridge.ts index 813cee7..ebd0752 100644 --- a/clients/contracts/bridge.ts +++ b/clients/contracts/bridge.ts @@ -82,11 +82,10 @@ export class BridgeContract extends DelphinusContract { return this.getWeb3Contract().methods.addToken(tokenid).send(); } - private _verify(calldata: number[], verifydata: BN[], vid: number, rid: BN) { + private _verify(calldata: number[], verifydata: BN[], rid: BN) { const tx = this.getWeb3Contract().methods.verify( calldata, verifydata, - vid, rid ); return tx.send(); @@ -98,13 +97,13 @@ export class BridgeContract extends DelphinusContract { .send(); } - verify(calldata: number[], verifydata: BN[], vid: number, rid: BN) { + verify(calldata: number[], verifydata: BN[], rid: BN) { const pbinder = new PromiseBinder(); return pbinder.return(async () => { return await pbinder.bind( "Verify", - this._verify(calldata, verifydata, vid, rid) + this._verify(calldata, verifydata, rid) ); }); } diff --git a/contracts/Bridge.sol b/contracts/Bridge.sol index e118f2d..49995d5 100644 --- a/contracts/Bridge.sol +++ b/contracts/Bridge.sol @@ -23,7 +23,7 @@ contract Bridge is DelphinusBridge { mapping(uint256 => bool) private hasSideEffiect; uint256 merkle_root; uint256 rid; - uint256 verifierID; + uint16 verifierID; constructor(uint32 chain_id) { _bridge_info.chain_id = chain_id; @@ -105,9 +105,9 @@ contract Bridge is DelphinusBridge { function addVerifier(address vaddr) public returns (uint256) { ensure_admin(); uint256 cursor = verifiers.length; - verifierID = verifiers.length; - require(verifiers.length < 255, "Verifier index out of bound"); + require(verifiers.length < 65535, "Verifier index out of bound"); verifiers.push(DelphinusVerifier(vaddr)); + verifierID = uint16(verifiers.length - 1); return cursor; } @@ -116,7 +116,7 @@ contract Bridge is DelphinusBridge { return transactions[tid]; } - function _get_verifier(uint8 vid) private view returns (DelphinusVerifier) { + function _get_verifier(uint16 vid) private view returns (DelphinusVerifier) { require(verifiers.length > vid, "Verifier index out of bound"); return verifiers[vid]; } @@ -182,7 +182,6 @@ contract Bridge is DelphinusBridge { function verify( bytes calldata tx_data, uint256[] calldata verify_data, // [8]: old root, [9]: new root, [10]: sha_low, [11]: sha_high - uint8 _vid, uint256 _rid ) public { require(rid == _rid, "Verify: Unexpected Request Id"); @@ -202,8 +201,7 @@ contract Bridge is DelphinusBridge { merkle_root == verify_data[10], "Inconstant: Merkle root dismatch" ); - - DelphinusVerifier verifier = _get_verifier(_vid); + DelphinusVerifier verifier = _get_verifier(verifierID); bool v = verifier.verifyDelphinusTx(verify_data); require(v == true, "ZKVerify: zksnark check failed"); diff --git a/contracts/DelphinusBridge.sol b/contracts/DelphinusBridge.sol index 5e79cd7..35b9f25 100644 --- a/contracts/DelphinusBridge.sol +++ b/contracts/DelphinusBridge.sol @@ -22,7 +22,6 @@ interface DelphinusBridge { function verify( bytes calldata tx_data, uint256[] calldata verify_data, // [8]: old root, [9]: new root, [10]: sha_low, [11]: sha_high - uint8 _vid, uint256 _rid ) external; } diff --git a/contracts/MKT.sol b/contracts/MKT.sol index f0df916..20a2130 100644 --- a/contracts/MKT.sol +++ b/contracts/MKT.sol @@ -19,5 +19,5 @@ struct BridgeInfo { address owner; uint256 merkle_root; uint256 rid; - uint256 verifierID; + uint16 verifierID; }