Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit c64ddd3

Browse files
minh-bqNganSM
andauthored
genesis, params: add Miko hardfork on mainnet (#402)
* precompiled: add procompiled contract to verify proof of possession BLS * cmd, entrypoint: add an account cmd to generate BLS proof of possession * consortium/v2: upgrade ronin trusted org contract * genesis/testnet: add Miko hardfork on testnet * params/version: bump Ronin to version 2.7.0 * state_processor: fix out-of-order system txs The current way that transactions are processed by Consortium V2 engine allows a system transaction to be placed before a common transaction in a block. However, the generated logs and receipts are ordered so that those of system transactions are stored at the end (see `core/state_processor.go/Process`). This leads to mismatching betwwen logs/receipts and their corresponding transactions because the handler of `eth_getLogs` assume that receipts are stored in the same order with that of `block.Transactions()` (see `core/rawdb/accessors_chain.go/deriveLogFields`). * state_processor, consortium-v2: test out of order system transactions * state_processor: adjust out-of-order tx check The check for out-of-order transactions is applied to Miko blocks only. * genesis, params: add Miko hardfork on mainnet * params/version: bump Ronin to version 2.7.1 --------- Co-authored-by: NganSM <[email protected]>
1 parent 9767790 commit c64ddd3

20 files changed

+594
-54
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ENV BLS_PRIVATE_KEY ''
2929
ENV BLS_PASSWORD ''
3030
ENV BLS_AUTO_GENERATE 'false'
3131
ENV BLS_SHOW_PRIVATE_KEY 'false'
32+
ENV GENERATE_BLS_PROOF 'false'
3233

3334
COPY --from=builder /opt/build/bin/ronin /usr/local/bin/ronin
3435
COPY --from=builder /opt/genesis/ ./

cmd/ronin/accountcmd.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ The keyfile is assumed to contain an unencrypted private key in hexadecimal form
260260
},
261261
Description: `ronin account generatebls [--secret]`,
262262
},
263+
{
264+
Name: "generate-bls-proof",
265+
Usage: "Generate BLS proof of possession",
266+
Action: utils.MigrateFlags(blsProofGenerate),
267+
Flags: []cli.Flag{
268+
utils.BlsWalletPath,
269+
utils.BlsPasswordPath,
270+
},
271+
ArgsUsage: "[keyFile]",
272+
Description: `
273+
ronin account generate-bls-proof [keyFile] [--finality.blswalletpath walletpath] [--finality.blspasswordpath passwordpath]
274+
275+
Generate proof from keyfile or stored encrypted wallet
276+
277+
The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
278+
You must input either keyfile or a pair of walletpath and passwordpath.
279+
`,
280+
},
263281
},
264282
}
265283
)
@@ -490,7 +508,7 @@ func loadKeyManager(ctx *cli.Context) (*bls.KeyManager, []blsCommon.PublicKey, e
490508
func loadBlsSecretKey(ctx *cli.Context) (blsCommon.SecretKey, error) {
491509
keyfile := ctx.Args().First()
492510
if len(keyfile) == 0 {
493-
utils.Fatalf("keyfile must be given as argument")
511+
return nil, fmt.Errorf("keyfile must be given as argument")
494512
}
495513

496514
secretKeyHex, err := ioutil.ReadFile(keyfile)
@@ -627,3 +645,40 @@ func blsAccountGenerate(ctx *cli.Context) error {
627645

628646
return nil
629647
}
648+
649+
func blsProofGenerate(ctx *cli.Context) error {
650+
var (
651+
keyManager *bls.KeyManager
652+
secretKeys []blsCommon.SecretKey
653+
)
654+
655+
secretKey, err := loadBlsSecretKey(ctx)
656+
if err != nil {
657+
keyManager, _, err = loadKeyManager(ctx)
658+
if err != nil {
659+
utils.Fatalf("Either keyfile or path to wallet must be provided, err: %s", err)
660+
}
661+
rawSecretKeys, err := keyManager.FetchValidatingSecretKeys(context.Background())
662+
if err != nil {
663+
utils.Fatalf("Failed to fetch BLS secret key, err %s", err)
664+
}
665+
for _, rawSecretKey := range rawSecretKeys {
666+
secretKey, err := blst.SecretKeyFromBytes(rawSecretKey[:])
667+
if err != nil {
668+
utils.Fatalf("Failed to decode BLS secret key, err %s", err)
669+
}
670+
secretKeys = append(secretKeys, secretKey)
671+
}
672+
} else {
673+
secretKeys = append(secretKeys, secretKey)
674+
}
675+
676+
for i, secretKey := range secretKeys {
677+
rawPublicKey := secretKey.PublicKey().Marshal()
678+
proof := secretKey.SignProof(rawPublicKey)
679+
fmt.Printf("BLS public key #%d: {%x}\n", i, rawPublicKey)
680+
fmt.Printf("BLS proof #%d: {%x}\n", i, proof.Marshal())
681+
}
682+
683+
return nil
684+
}

consensus/consortium/v2/consortium.go

+17
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ var (
5858

5959
diffInTurn = big.NewInt(7) // Block difficulty for in-turn signatures
6060
diffNoTurn = big.NewInt(3) // Block difficulty for out-of-turn signatures
61+
62+
// The proxy contract's implementation slot
63+
// https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.7.3/contracts/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#L34
64+
implementationSlot = common.HexToHash("360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")
6165
)
6266

6367
var (
@@ -840,6 +844,17 @@ func (c *Consortium) processSystemTransactions(chain consensus.ChainHeaderReader
840844
return nil
841845
}
842846

847+
func (c *Consortium) upgradeRoninTrustedOrg(blockNumber *big.Int, state *state.StateDB) {
848+
// The upgrade only happens in 1 block: Miko hardfork block
849+
if c.chainConfig.MikoBlock != nil && c.chainConfig.MikoBlock.Cmp(blockNumber) == 0 {
850+
state.SetState(
851+
c.chainConfig.RoninTrustedOrgUpgrade.ProxyAddress,
852+
implementationSlot,
853+
c.chainConfig.RoninTrustedOrgUpgrade.ImplementationAddress.Hash(),
854+
)
855+
}
856+
}
857+
843858
// Finalize implements consensus.Engine that calls three methods from smart contracts:
844859
// - WrapUpEpoch at epoch to distribute rewards and sort the validators set
845860
// - Slash the validator who does not sign if it is in-turn
@@ -901,6 +916,7 @@ func (c *Consortium) Finalize(chain consensus.ChainHeaderReader, header *types.H
901916
if err := c.processSystemTransactions(chain, header, transactOpts, false); err != nil {
902917
return err
903918
}
919+
c.upgradeRoninTrustedOrg(header.Number, state)
904920
if len(*transactOpts.EVMContext.InternalTransactions) > 0 {
905921
*internalTxs = append(*internalTxs, *transactOpts.EVMContext.InternalTransactions...)
906922
}
@@ -946,6 +962,7 @@ func (c *Consortium) FinalizeAndAssemble(chain consensus.ChainHeaderReader, head
946962
if err := c.processSystemTransactions(chain, header, transactOpts, true); err != nil {
947963
return nil, nil, err
948964
}
965+
c.upgradeRoninTrustedOrg(header.Number, state)
949966

950967
// should not happen. Once happen, stop the node is better than broadcast the block
951968
if header.GasLimit < header.GasUsed {

0 commit comments

Comments
 (0)