Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace signature raw in the snapshots event #178

Merged
merged 49 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2677617
coverage tool fix, all regular tests passes, coverage test conditions…
z-j-lin Jun 23, 2022
91d5b98
added legacy to gitignore
z-j-lin Jun 23, 2022
d20cf21
working snapshot ring buffer
z-j-lin Jun 30, 2022
d3620ee
working snapshot tests
z-j-lin Jul 1, 2022
25ce7aa
snapshot ringbuffer mock testing contract
z-j-lin Jul 5, 2022
b5ee5e5
removed get snapshot for height
z-j-lin Jul 7, 2022
5ea4ed9
Merge remote-tracking branch 'upstream/main'
z-j-lin Jul 8, 2022
2d09fcc
fixed multicall upgradeProxy
z-j-lin Jul 19, 2022
4498571
Merge remote-tracking branch 'upstream/main'
z-j-lin Jul 19, 2022
dd2cf04
fixed linter issues
z-j-lin Jul 19, 2022
26dcd6c
removed hardhat console log imports
z-j-lin Jul 19, 2022
cecc15c
added error codes back
z-j-lin Jul 19, 2022
e1efc14
Merge remote-tracking branch 'upstream/main' into zj-main
vtleonardo Jul 21, 2022
911c9c2
Clean up PR
vtleonardo Jul 21, 2022
b114dda
Fix snapshot events processing
vtleonardo Jul 21, 2022
7d79af1
Fix log snapshots
vtleonardo Jul 22, 2022
b709ea7
cleaned up snapshot a little
z-j-lin Jul 25, 2022
fca9ebe
Merge branch 'main' of github.com:z-j-lin/alicenet
z-j-lin Jul 25, 2022
3393d88
updated ring buffer lib
z-j-lin Aug 1, 2022
955270b
Merge branch 'main' of github.com:z-j-lin/alicenet into zj-main
vtleonardo Aug 2, 2022
65ce0e4
Merge remote-tracking branch 'upstream/main' into zj-main
vtleonardo Aug 2, 2022
db8fc15
fix code after merging latest main
vtleonardo Aug 2, 2022
ac61339
Fix unit tests
vtleonardo Aug 2, 2022
1c521f3
Format files
vtleonardo Aug 2, 2022
bac0148
Fix last unit tests
vtleonardo Aug 2, 2022
bb0d29b
updated epoch getter function
z-j-lin Aug 3, 2022
8d8d9fc
Merge branch 'main' of github.com:z-j-lin/alicenet
z-j-lin Aug 3, 2022
d6fb50a
added decoded header check for snapshot event
z-j-lin Aug 4, 2022
bc19320
removed .only
z-j-lin Aug 4, 2022
be0ed04
ran linter and formatter
z-j-lin Aug 4, 2022
bc3cf8f
Fix linter
vtleonardo Aug 4, 2022
1c668bb
Put require back
vtleonardo Aug 4, 2022
90d5644
clean up readme
vtleonardo Aug 4, 2022
14a7e57
Merge remote-tracking branch 'upstream/main' into zj-main
vtleonardo Aug 10, 2022
a98add3
Fix merge conflicts
vtleonardo Aug 10, 2022
461e67c
regenerate bindings
vtleonardo Aug 10, 2022
d9c9d80
Rearrange snapshots to make reverts more clear and cheaper
vtleonardo Aug 11, 2022
e6fe0ec
Merge remote-tracking branch 'upstream/main' into make-reverts-cheape…
vtleonardo Aug 12, 2022
cae9b95
Fix bindings
vtleonardo Aug 12, 2022
6513bc0
Organize better the code
vtleonardo Aug 12, 2022
ffdfddb
Merge remote-tracking branch 'upstream/main' into make-reverts-cheape…
vtleonardo Aug 12, 2022
9bba930
update bindings
vtleonardo Aug 12, 2022
31dd92e
Add more unit tests for signature checking
vtleonardo Aug 12, 2022
579b7af
Fix linter
vtleonardo Aug 12, 2022
45dfcd3
Remove bytes from snapshot event
vtleonardo Aug 17, 2022
e2879f0
Update bindings
vtleonardo Aug 17, 2022
eec5013
Update linter
vtleonardo Aug 17, 2022
79bfc6c
Merge remote-tracking branch 'upstream/main' into replace-signature-raw
vtleonardo Aug 19, 2022
9dd21d0
Fix conflicts
vtleonardo Aug 19, 2022
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
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