Skip to content

Commit

Permalink
Replace signature raw in the snapshots event (#178)
Browse files Browse the repository at this point in the history
* coverage tool fix, all regular tests passes, coverage test conditions need fixing for running solidity coverage

* added legacy to gitignore

* working snapshot ring buffer

* working snapshot tests

* snapshot ringbuffer mock testing contract

* removed get snapshot for height

* fixed multicall upgradeProxy

* fixed linter issues

* removed hardhat console log imports

* added error codes back

* Clean up PR

* Fix snapshot events processing

* Fix log snapshots

* cleaned up snapshot a little

* updated ring buffer lib

* fix code after merging latest main

* Fix unit tests

* Format files

* Fix last unit tests

* updated epoch getter function

* added decoded header check for snapshot event

* removed .only

* ran linter and formatter

* Fix linter

* Put require back

* clean up readme

* Fix merge conflicts

* regenerate bindings

* Rearrange snapshots to make reverts more clear and cheaper

* Fix bindings

* Organize better the code

* update bindings

* Add more unit tests for signature checking

* Fix linter

* Remove bytes from snapshot event

* Update bindings

* Update linter

* Fix conflicts

Co-authored-by: ZJ <zijunlin32@gmail.com>
  • Loading branch information
vtleonardo and z-j-lin committed Aug 19, 2022
1 parent ba8906f commit e020d73
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 86 deletions.
17 changes: 9 additions & 8 deletions bridge/bindings/Snapshots.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions bridge/bindings/Snapshots.iface.f.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions bridge/bindings/bindings-artifacts/Snapshots.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions bridge/contracts/Snapshots.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
/// @notice Saves next snapshot
/// @param groupSignature_ The group signature used to sign the snapshots' block claims
/// @param bClaims_ The claims being made about given block
/// @return Flag whether we should kick off another round of key generation
/// @return returns true if the execution succeeded
function snapshot(bytes calldata groupSignature_, bytes calldata bClaims_)
public
returns (bool)
Expand All @@ -74,7 +74,10 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
keccak256(groupSignature_)
);

_checkBClaimsSignature(groupSignature_, bClaims_);
(uint256[4] memory masterPublicKey, uint256[2] memory signature) = _checkBClaimsSignature(
groupSignature_,
bClaims_
);

bool isSafeToProceedConsensus = true;
if (IValidatorPool(_validatorPoolAddress()).isMaintenanceScheduled()) {
Expand All @@ -91,16 +94,17 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
blockClaims.height,
msg.sender,
isSafeToProceedConsensus,
groupSignature_,
masterPublicKey,
signature,
blockClaims
);
return isSafeToProceedConsensus;
}

/// @notice Saves next snapshot
/// @param groupSignature_ The group signature used to sign the snapshots' block claims
/// @param bClaims_ The claims being made about given block
/// @return Flag whether we should kick off another round of key generation
/// @notice Migrates a set of snapshots to bootstrap the side chain.
/// @param groupSignature_ Array of group signature used to sign the snapshots' block claims
/// @param bClaims_ Array of BClaims being migrated as snapshots
/// @return returns true if the execution succeeded
function migrateSnapshots(bytes[] memory groupSignature_, bytes[] memory bClaims_)
public
onlyFactory
Expand All @@ -126,6 +130,10 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
if (blockClaims.height % _epochLength != 0) {
revert SnapshotsErrors.InvalidBlockHeight(blockClaims.height);
}
(
uint256[4] memory masterPublicKey,
uint256[2] memory signature
) = _checkBClaimsSignature(groupSignature_[i], bClaims_[i]);
epoch = getEpochFromHeight(blockClaims.height);
_setSnapshot(Snapshot(block.number, blockClaims));
emit SnapshotTaken(
Expand All @@ -134,7 +142,8 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
blockClaims.height,
msg.sender,
true,
groupSignature_[i],
masterPublicKey,
signature,
blockClaims
);
}
Expand Down Expand Up @@ -304,9 +313,10 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
}
}

function _checkBClaimsSignature(bytes calldata groupSignature_, bytes calldata bClaims_)
function _checkBClaimsSignature(bytes memory groupSignature_, bytes memory bClaims_)
internal
view
returns (uint256[4] memory, uint256[2] memory)
{
(uint256[4] memory masterPublicKey, uint256[2] memory signature) = RCertParserLibrary
.extractSigGroup(groupSignature_, 0);
Expand All @@ -330,6 +340,7 @@ contract Snapshots is Initializable, SnapshotsStorage, ISnapshots {
) {
revert SnapshotsErrors.SignatureVerificationFailed();
}
return (masterPublicKey, signature);
}

function _checkSnapshotMinimumInterval(uint256 lastSnapshotCommittedAt) internal view {
Expand Down
3 changes: 2 additions & 1 deletion bridge/contracts/interfaces/ISnapshots.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ interface ISnapshots {
uint256 height,
address indexed validator,
bool isSafeToProceedConsensus,
bytes signatureRaw,
uint256[4] masterPublicKey,
uint256[2] signature,
BClaimsParserLibrary.BClaims bClaims
);

Expand Down
36 changes: 32 additions & 4 deletions bridge/test/ethdkg/migration-validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ describe("Ethdkg: Migrate state", () => {
expectedHeight,
ethers.utils.getAddress(validatorsSnapshots2[1].address),
expectedSafeToProceedConsensus,
validSnapshot2048.GroupSignature,
validSnapshot2048.GroupSignatureDeserialized?.[0],
validSnapshot2048.GroupSignatureDeserialized?.[1],
validSnapshot2048.BClaimsDeserialized
);

Expand Down Expand Up @@ -346,7 +347,16 @@ describe("Ethdkg: Migrate state", () => {
expectedHeight,
ethers.utils.getAddress(validatorsSnapshots[1].address),
expectedSafeToProceedConsensus,
signedData[2].GroupSignature,
[
"0x0062cd4187d44be6f7977e5cbfc18066c3d5029bc6ab1e0ae5b1dd20a691fc6d",
"0x08648a63a6690c930265e93c86ec421d6a7ca06504c6b9509640cbd794a1459a",
"0x0a0837516f6bdc0ff9fd69776b2d7928432958b31551d10e921cc261f290b23c",
"0x06ce5812bf9f76f2dc04d272dd2e0ff8d2424d1e9f19c22da1ad5d2294463428",
],
[
"0x0413ba20de19c18c75e268419c3f6fd86cc4d9a75e3b1127ce180ed93b95bff6",
"0x09401a3cf161c59e5e34e0da23593f556c9f834e90264a474933fd8235202b0c",
],
[
expectedChainId,
expectedHeight,
Expand Down Expand Up @@ -419,7 +429,16 @@ describe("Ethdkg: Migrate state", () => {
expectedHeight,
ethers.utils.getAddress(validatorsSnapshots[1].address),
expectedSafeToProceedConsensus,
signedData[1].GroupSignature,
[
"0x0062cd4187d44be6f7977e5cbfc18066c3d5029bc6ab1e0ae5b1dd20a691fc6d",
"0x08648a63a6690c930265e93c86ec421d6a7ca06504c6b9509640cbd794a1459a",
"0x0a0837516f6bdc0ff9fd69776b2d7928432958b31551d10e921cc261f290b23c",
"0x06ce5812bf9f76f2dc04d272dd2e0ff8d2424d1e9f19c22da1ad5d2294463428",
],
[
"0x2a060cf960125afbb506d17644798a7e5c877e9e82b6bf426b7287d543ed59e0",
"0x09d52226e77e1bf3321bff5320989ee80f27a564d25bc4daaf4bb0640c73d7b0",
],
[
expectedChainId,
expectedHeight,
Expand Down Expand Up @@ -463,7 +482,16 @@ describe("Ethdkg: Migrate state", () => {
expectedHeight,
ethers.utils.getAddress(validatorsSnapshots[1].address),
expectedSafeToProceedConsensus,
signedData[2].GroupSignature,
[
"0x0062cd4187d44be6f7977e5cbfc18066c3d5029bc6ab1e0ae5b1dd20a691fc6d",
"0x08648a63a6690c930265e93c86ec421d6a7ca06504c6b9509640cbd794a1459a",
"0x0a0837516f6bdc0ff9fd69776b2d7928432958b31551d10e921cc261f290b23c",
"0x06ce5812bf9f76f2dc04d272dd2e0ff8d2424d1e9f19c22da1ad5d2294463428",
],
[
"0x0413ba20de19c18c75e268419c3f6fd86cc4d9a75e3b1127ce180ed93b95bff6",
"0x09401a3cf161c59e5e34e0da23593f556c9f834e90264a474933fd8235202b0c",
],
[
expectedChainId,
expectedHeight,
Expand Down
4 changes: 4 additions & 0 deletions bridge/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface Snapshot {
GroupSignature: string;
height: BigNumberish;
validatorIndex: number;
GroupSignatureDeserialized?: [
[string, string, string, string],
[string, string]
];
BClaimsDeserialized?: [
number,
number,
Expand Down
24 changes: 24 additions & 0 deletions bridge/test/snapshots/assets/4-validators-snapshots-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ export const validSnapshot1024: Snapshot = {
"0x000000000100040001000000000400000d00000002010000190000000201000025000000020100003100000002010000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
height: BigNumber.from(1024),
validatorIndex: 0,
GroupSignatureDeserialized: [
[
"0x0307958327890e6901c3060c2d80eea0d1b4d0b9d9aa5dc007b487fd8a38310d",
"0x2861312eb00e5ee36f68a8be4c420cc42a685f4a0b9b2afa00ff70f48a805d8e",
"0x1ad5efaf40b0d6e10cbb913487a789383afb88256d7263b97ffe8e25b6099877",
"0x1335c2f31eec681e70f4529e2982210837d98b8cf431462b4099d7188dd86aa6",
],
[
"0x02c65146913ce4418077631ca8d38c6517c025997a88629cd8b79b57b9d33e2b",
"0x2080cdf2a03b9b9a3ae4e015dbd48e4d4994ac945d1e5bcc9549ed0e011e2c15",
],
],
BClaimsDeserialized: [
1,
1024,
Expand All @@ -248,6 +260,18 @@ export const validSnapshot2048: Snapshot = {
"0x000000000100040001000000000800000d00000002010000190000000201000025000000020100003100000002010000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
height: BigNumber.from(2048),
validatorIndex: 0,
GroupSignatureDeserialized: [
[
"0x0307958327890e6901c3060c2d80eea0d1b4d0b9d9aa5dc007b487fd8a38310d",
"0x2861312eb00e5ee36f68a8be4c420cc42a685f4a0b9b2afa00ff70f48a805d8e",
"0x1ad5efaf40b0d6e10cbb913487a789383afb88256d7263b97ffe8e25b6099877",
"0x1335c2f31eec681e70f4529e2982210837d98b8cf431462b4099d7188dd86aa6",
],
[
"0x025e9c317f0fbc180d33b2aafe72a0e36080ce1a727c173a38de676f65b52cb1",
"0x1ec348b44892f76db05ac535c3921cccbe502cbec8acb0380a562c5f5d5bcc84",
],
],
BClaimsDeserialized: [
1,
2048,
Expand Down
24 changes: 24 additions & 0 deletions bridge/test/snapshots/assets/4-validators-snapshots-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ export const validSnapshot1024: Snapshot = {
"0x000000000100040001000000000400000d00000002010000190000000201000025000000020100003100000002010000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
height: BigNumber.from(1024),
validatorIndex: 0,
GroupSignatureDeserialized: [
[
"0x0fb2d09422ffde8f374aa38743f5387b027a0da60421113b6892ddb7e1b830b9",
"0x083b27be497305cbb104a8b4ce1d7ee01519f718a5e5bcb408e95b39bf4c8d9b",
"0x15e2cf0739f85da5a77042cdf62aacfad6f9384c869fe9157306ac5deec564fc",
"0x2094df42fa260f3cfd5e92ae28759440b1f752d611365a8467e85e0552acb8f4",
],
[
"0x0e5095cabbb882a266a902ba611732b55aef38e99e32b1429fbce4801c657863",
"0x1da9662c2091eb7ddf3e433c72c119ee63131676e3a46a3795a693f38142a137",
],
],
BClaimsDeserialized: [
1,
1024,
Expand All @@ -248,6 +260,18 @@ export const validSnapshot2048: Snapshot = {
"0x000000000100040001000000000800000d00000002010000190000000201000025000000020100003100000002010000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
height: BigNumber.from(2048),
validatorIndex: 0,
GroupSignatureDeserialized: [
[
"0x0fb2d09422ffde8f374aa38743f5387b027a0da60421113b6892ddb7e1b830b9",
"0x083b27be497305cbb104a8b4ce1d7ee01519f718a5e5bcb408e95b39bf4c8d9b",
"0x15e2cf0739f85da5a77042cdf62aacfad6f9384c869fe9157306ac5deec564fc",
"0x2094df42fa260f3cfd5e92ae28759440b1f752d611365a8467e85e0552acb8f4",
],
[
"0x098f32e5cb45a2f46057aef0dce32353783e7da2ea0b83092da3a6214d7f61bc",
"0x20d442405a9d95bbfb8d91bb4ea8380eb40f777a593b67df35cb5a78ab308603",
],
],
BClaimsDeserialized: [
1,
2048,
Expand Down
Loading

0 comments on commit e020d73

Please sign in to comment.