forked from Consensys/gpact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the signature format for Crosschain Messaging Layer to match revised EEA specification. This PR has wide ranging breaking changes. Previous implementations will not work with this implementation as the signature format has changed. Unfortunately, the golang integration tests for GPACT no longer work. The issue is when the segment function call is executed. Despite extensive analysis, the defect has not been identified.
- Loading branch information
1 parent
1709683
commit 720911a
Showing
41 changed files
with
1,288 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
contracts/contracts/src/messaging/common/SignatureEncoding.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2022 ConsenSys Software Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
pragma solidity ^0.8; | ||
|
||
/** | ||
* Signature encoding is defined in the EEA Crosschain Messaging specification: | ||
* https://entethalliance.github.io/crosschain-interoperability/draft_crosschain_techspec_messaging.html | ||
*/ | ||
contract SignatureEncoding { | ||
uint16 constant ECDSA_SIGNATURE = 1; | ||
|
||
struct Signature { | ||
address by; | ||
bytes32 sigR; | ||
bytes32 sigS; | ||
uint8 sigV; | ||
bytes meta; | ||
} | ||
|
||
struct Signatures { | ||
uint256 typ; | ||
Signature[] signatures; | ||
} | ||
|
||
/** | ||
* Decode a signature blob. | ||
* | ||
* @param _signatures Encoded signatures. | ||
* @return Signture object. | ||
*/ | ||
function decodeSignature(bytes calldata _signatures) | ||
internal | ||
pure | ||
returns (Signatures memory) | ||
{ | ||
( | ||
, | ||
/* Skip offset of dynamic type */ | ||
uint16 sigType | ||
) = abi.decode(_signatures, (uint256, uint16)); | ||
require(sigType == ECDSA_SIGNATURE, "Signature unknown type"); | ||
|
||
Signatures memory sigs = abi.decode(_signatures, (Signatures)); | ||
return sigs; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
contracts/contracts/src/messaging/common/SignatureEncodingTest.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2022 ConsenSys Software Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
pragma solidity ^0.8; | ||
|
||
import "./SignatureEncoding.sol"; | ||
|
||
/** | ||
* Signature encoding is defined in the EEA Crosschain Messaging specification: | ||
* https://entethalliance.github.io/crosschain-interoperability/draft_crosschain_techspec_messaging.html | ||
*/ | ||
contract SignatureEncodingTest is SignatureEncoding { | ||
event ShowSig(bytes encoded); | ||
|
||
function testEmitSignatureBlob() external { | ||
Signature memory sig1 = Signature( | ||
address(0x21), | ||
bytes32(uint256(0x22)), | ||
bytes32(uint256(0x23)), | ||
uint8(0x24), | ||
bytes("abc") | ||
); | ||
Signature[] memory s = new Signature[](1); | ||
s[0] = sig1; | ||
Signatures memory sigs = Signatures(0x25, s); | ||
bytes memory encoded = abi.encode(sigs); | ||
emit ShowSig(encoded); | ||
} | ||
|
||
event SigType(uint256 typ); | ||
event SigInfo1(uint256 typ, uint256 len); | ||
event SigInfo2( | ||
address by, | ||
bytes32 sigR, | ||
bytes32 sigS, | ||
uint8 sigV, | ||
bytes meta | ||
); | ||
|
||
function testDecodeSignatureType(bytes calldata _signatures) external { | ||
(, uint256 sigType) = abi.decode(_signatures, (uint256, uint256)); | ||
emit SigType(sigType); | ||
} | ||
|
||
function testDecodeSignature(bytes calldata _signatures) external { | ||
Signatures memory sigs = decodeSignature(_signatures); | ||
|
||
emit SigInfo1(sigs.typ, sigs.signatures.length); | ||
|
||
for (uint256 i = 0; i < sigs.signatures.length; i++) { | ||
Signature memory sig = sigs.signatures[i]; | ||
emit SigInfo2(sig.by, sig.sigR, sig.sigS, sig.sigV, sig.meta); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.