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

Shutter: Validator registry v0 backwards compatibility #7724

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,33 @@ public void Can_check_if_registered()
}

// register all 10, then deregister last 5
updates.Add((0, CreateUpdate(100, 10, 0, true)));
updates.Add((1, CreateUpdate(105, 5, 1, false)));
updates.Add((0, CreateUpdate(100, 10, 0, 1, true)));
updates.Add((1, CreateUpdate(105, 5, 1, 1, false)));

// reregister 1 with V0 signature
updates.Add((2, CreateUpdate(107, 1, 2, 0, true)));

// invalid updates should be ignored
updates.Add((2, CreateUpdate(100, 10, 0, false))); // invalid nonce
updates.Add((3, CreateUpdate(50, 50, 0, true))); // not in validatorsInfo
updates.Add((3, CreateUpdate(100, 10, 0, 1, false))); // invalid nonce
updates.Add((4, CreateUpdate(50, 50, 0, 1, true))); // not in validatorsInfo

// bad signature
Update badUpdate = CreateUpdate(100, 10, 2, true);
Update badUpdate = CreateUpdate(100, 10, 2, 1, true);
badUpdate.Signature[34] += 1;
updates.Add((4, badUpdate));
updates.Add((5, badUpdate));

Assert.Multiple(() =>
{
Assert.That(!contract.IsRegistered(updates, validatorsInfo, out HashSet<ulong> unregistered));
Assert.That(unregistered, Has.Count.EqualTo(5));
Assert.That(unregistered, Has.Count.EqualTo(4));
});
}

private static Update CreateUpdate(ulong startIndex, uint count, uint nonce, bool isRegistration)
private static Update CreateUpdate(ulong startIndex, uint count, uint nonce, byte version, bool isRegistration)
{
ValidatorRegistryContract.Message msg = new()
{
Version = 1,
Version = version,
ChainId = ShutterTestsCommon.ChainId,
ContractAddress = Address.Zero.Bytes,
StartValidatorIndex = startIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private bool IsUpdateValid(in Update update, in ShutterValidatorsInfo validators
}

Message msg = new(update.Message.AsSpan());

ulong startValidatorIndex = msg.StartValidatorIndex;
ulong endValidatorIndex = msg.StartValidatorIndex + msg.Count;

Expand All @@ -121,7 +122,7 @@ private bool IsUpdateValid(in Update update, in ShutterValidatorsInfo validators
return false;
}

if (msg.Version != messageVersion)
if (msg.Version > messageVersion)
{
err = $"Registration message has wrong version ({msg.Version}) should be {messageVersion}.";
return false;
Expand Down Expand Up @@ -178,11 +179,12 @@ public Message(Span<byte> encodedMessage)
throw new ArgumentException("Validator registry contract message was wrong length.");
}

Version = encodedMessage[0];
byte version = encodedMessage[0];
Version = version;
ChainId = BinaryPrimitives.ReadUInt64BigEndian(encodedMessage[1..]);
ContractAddress = encodedMessage[9..29];
StartValidatorIndex = BinaryPrimitives.ReadUInt64BigEndian(encodedMessage[29..37]);
Count = BinaryPrimitives.ReadUInt32BigEndian(encodedMessage[37..41]);
Count = version == 0 ? 1 : BinaryPrimitives.ReadUInt32BigEndian(encodedMessage[37..41]);
Nonce = BinaryPrimitives.ReadUInt32BigEndian(encodedMessage[41..45]);
IsRegistration = encodedMessage[45] == 1;
}
Expand Down