Skip to content

Commit

Permalink
chore(contracts/core): generate sigs instead of precomputing them (#2466
Browse files Browse the repository at this point in the history
)

Generate signatures instead of using precomputed values, as chainIds
vary depending on destination. Precomputed values were causing tests to
fail.

issue: #2431
  • Loading branch information
Zodomo authored Nov 12, 2024
1 parent f9e348a commit 39262ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion contracts/bindings/admin.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions contracts/core/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Admin_Test:test_pause_unpause() (gas: 30662045)
Admin_Test:test_pause_unpause_bridge() (gas: 25691732)
Admin_Test:test_pause_unpause_xcall() (gas: 30615975)
Admin_Test:test_pause_unpause_xsubmit() (gas: 30615726)
Admin_Test:test_upgrade() (gas: 34697220)
Admin_Test:test_pause_unpause() (gas: 30680773)
Admin_Test:test_pause_unpause_bridge() (gas: 25710460)
Admin_Test:test_pause_unpause_xcall() (gas: 30634703)
Admin_Test:test_pause_unpause_xsubmit() (gas: 30634454)
Admin_Test:test_upgrade() (gas: 34715948)
AllocPredeploys_Test:test_num_allocs() (gas: 1181319043)
AllocPredeploys_Test:test_predeploys() (gas: 1181300853)
AllocPredeploys_Test:test_preinstalls() (gas: 1182017269)
Expand Down Expand Up @@ -143,8 +143,8 @@ Quorum_Test:test_verify_sigsNotSorted_reverts() (gas: 282992)
Quorum_Test:test_verify_succeeds() (gas: 294059)
Slashing_Test:test_stub() (gas: 143)
Slashing_Test:test_unjail() (gas: 54734)
Staking_Test:test_createValidator() (gas: 143163)
Staking_Test:test_delegate() (gas: 109986)
Staking_Test:test_createValidator() (gas: 145288)
Staking_Test:test_delegate() (gas: 110001)
Staking_Test:test_stub() (gas: 143)
Upgrade_Test:test_stub() (gas: 143)
XAppUpgradeable_Test:test_isXCall() (gas: 148924)
Expand Down
10 changes: 4 additions & 6 deletions contracts/core/script/admin/StakingPostUpgradeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,16 @@ contract StakingPostUpgradeTest is Test {
}

function _testCreateValidator() internal {
bytes32 privkey = 0xf0e1605dd50ce33553290b778b0f53b2cde5e47a8794c0e7d2815e456e6da3b9;
bytes32 x = 0x3b12d750493ed6b12b390447f6dd38f587af12ed04ab8d6858e818cf0c63607c;
bytes32 y = 0x044e0321a3e57de51e95f2b230b9e4ffed2318578baab1a80652234fe0115d13;
bytes memory pubkey = Secp256k1.compressPublicKey(x, y);
bytes32 digest = 0x6b428e37b951e4f3858fde3c4f025278b0f2e1b8abf34fa295d26be1aeebf6e3;
bytes memory signature =
hex"ab1fc81491c244466777cc3edfbb5925cb2586c2f8d061edc09022cfc3f9ff6d06e8105a7228b964dd3a22349c9f853994db5ce47f76867ba43a641b7530559c1b";
bytes32 digest = staking.getValidatorPubkeyDigest(x, y);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(privkey), digest);
bytes memory signature = abi.encodePacked(r, s, v);
uint256 deposit = staking.MinDeposit();
vm.deal(validator, deposit);

bytes32 validatorPubkeyDigest = staking.getValidatorPubkeyDigest(x, y);
assertEq(validatorPubkeyDigest, digest, "validator pubkey digest");

vm.expectEmit();
emit Staking.CreateValidator(validator, pubkey, deposit);
vm.prank(validator);
Expand Down
9 changes: 6 additions & 3 deletions contracts/core/test/octane/Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ contract Staking_Test is Test {
event Delegate(address indexed delegator, address indexed validator, uint256 amount);

address owner;
address validator;
StakingHarness staking;

function setUp() public {
owner = makeAddr("owner");
validator = makeAddr("validator");
staking = new StakingHarness(owner);
}

function test_createValidator() public {
address validator = makeAddr("validator");
address[] memory validators = new address[](1);
validators[0] = validator;
bytes32 privkey = 0x5aae8cd28d4456aba1d24542558bc2fac787e2fdc2210c20f2f3375e82174205;
bytes32 x = 0x534d719d4f56544f42e22cab20886dd64fb713a5c72b31f929d856654a11dc0c;
bytes32 y = 0x5609e3c7f55c46a197ead4a96caa63eeade00b4a775e7709f6e673157a724d6c;
bytes memory pubkey = Secp256k1.compressPublicKey(x, y);
bytes memory signature =
hex"e847a133d1925786238a920c00e38ceb5fd5c2ffaba0bcfb63858d3724f40b370767f30ad1cc1a1130d9a199b5c0322b860fce2144147f993db48af4fd4ec2af1b";
bytes32 validatorPubkeyDigest = staking.getValidatorPubkeyDigest(x, y);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(privkey), validatorPubkeyDigest);
bytes memory signature = abi.encodePacked(r, s, v);
vm.deal(validator, staking.MinDeposit());

// allowlist is disabled
Expand Down

0 comments on commit 39262ac

Please sign in to comment.