Commit b799c26c authored by vicotor's avatar vicotor

fix bug for genesis block hash doesn't match.

parent 988bc0a4
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/exchain/go-exchain/exchain" "github.com/exchain/go-exchain/exchain"
"github.com/exchain/go-exchain/exchain/chaindb" "github.com/exchain/go-exchain/exchain/chaindb"
nebulav1 "github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1" nebulav1 "github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1"
"github.com/golang/protobuf/proto" "github.com/exchain/go-exchain/exchain/wrapper"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"math/big" "math/big"
"os" "os"
...@@ -107,7 +107,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block { ...@@ -107,7 +107,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block {
tx := &nebulav1.Transaction{ tx := &nebulav1.Transaction{
TxType: nebulav1.TxType_SignProxyTx, TxType: nebulav1.TxType_SignProxyTx,
User: account.String(), User: account.String(),
Nonce: exchain.GetNonce().Bytes(), Nonce: nil,
Proxy: false, Proxy: false,
Tx: &nebulav1.Transaction_SignProxyTx{ Tx: &nebulav1.Transaction_SignProxyTx{
SignProxyTx: &nebulav1.SignProxyTransaction{ SignProxyTx: &nebulav1.SignProxyTransaction{
...@@ -123,7 +123,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block { ...@@ -123,7 +123,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block {
tx := &nebulav1.Transaction{ tx := &nebulav1.Transaction{
TxType: nebulav1.TxType_DepositTx, TxType: nebulav1.TxType_DepositTx,
User: account.String(), User: account.String(),
Nonce: exchain.GetNonce().Bytes(), Nonce: nil,
Proxy: false, Proxy: false,
Tx: &nebulav1.Transaction_DepositTx{ Tx: &nebulav1.Transaction_DepositTx{
DepositTx: &nebulav1.DepositTransaction{ DepositTx: &nebulav1.DepositTransaction{
...@@ -139,10 +139,6 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block { ...@@ -139,10 +139,6 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block {
} }
} }
} }
hash := BlockHash(blk)
signature, _ := crypto.Sign(hash.Bytes(), genesisSignerKey)
blk.Header.Signature = signature
return blk return blk
} }
...@@ -164,18 +160,8 @@ func NewGenesisBlock(genfile string) (*GenesisBlock, error) { ...@@ -164,18 +160,8 @@ func NewGenesisBlock(genfile string) (*GenesisBlock, error) {
} }
func BlockHash(blk *nebulav1.Block) common.Hash { func BlockHash(blk *nebulav1.Block) common.Hash {
data := make([]byte, 0) wblk := wrapper.NewBlkWrapper(blk)
data = append(data, uint256.NewInt(blk.Header.Height).Bytes()...) return wblk.Hash()
data = append(data, uint256.NewInt(blk.Header.Timestamp).Bytes()...)
data = append(data, blk.Header.L1Hash...)
data = append(data, uint256.NewInt(blk.Header.L1Height).Bytes()...)
data = append(data, blk.Header.ParentHash...)
data = append(data, blk.Header.AppRoot...)
data = append(data, blk.Header.Proposer...)
txdata, _ := proto.Marshal(blk.Transactions)
data = append(data, txdata...)
return crypto.Keccak256Hash(data)
} }
func LoadGenesisAllocs(allocsPath string) (GenesisAlloc, error) { func LoadGenesisAllocs(allocsPath string) (GenesisAlloc, error) {
......
...@@ -256,6 +256,11 @@ func (payload *ExecutionPayload) Transactions() []*nebulav1.Transaction { ...@@ -256,6 +256,11 @@ func (payload *ExecutionPayload) Transactions() []*nebulav1.Transaction {
return []*nebulav1.Transaction{} return []*nebulav1.Transaction{}
} }
func (payload *ExecutionPayload) String() string {
d, _ := json.Marshal(payload.Payload)
return string(d)
}
func (payload *ExecutionPayload) MarshalData(o io.Writer) (int, error) { func (payload *ExecutionPayload) MarshalData(o io.Writer) (int, error) {
d, err := proto.Marshal(payload.Payload) d, err := proto.Marshal(payload.Payload)
if err != nil { if err != nil {
......
...@@ -1424,46 +1424,46 @@ contract Deploy is Deployer { ...@@ -1424,46 +1424,46 @@ contract Deploy is Deployer {
/// @notice Sets the implementation for the `CANNON` game type in the `DisputeGameFactory` /// @notice Sets the implementation for the `CANNON` game type in the `DisputeGameFactory`
function setCannonFaultGameImplementation(bool _allowUpgrade) public broadcast { function setCannonFaultGameImplementation(bool _allowUpgrade) public broadcast {
console.log("Setting Cannon FaultDisputeGame implementation"); // console.log("Setting Cannon FaultDisputeGame implementation");
DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy")); // DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
DelayedWETH weth = DelayedWETH(mustGetAddress("DelayedWETHProxy")); // DelayedWETH weth = DelayedWETH(mustGetAddress("DelayedWETHProxy"));
//
// Set the Cannon FaultDisputeGame implementation in the factory. // // Set the Cannon FaultDisputeGame implementation in the factory.
_setFaultGameImplementation({ // _setFaultGameImplementation({
_factory: factory, // _factory: factory,
_allowUpgrade: _allowUpgrade, // _allowUpgrade: _allowUpgrade,
_params: FaultDisputeGameParams({ // _params: FaultDisputeGameParams({
anchorStateRegistry: AnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy")), // anchorStateRegistry: AnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy")),
weth: weth, // weth: weth,
gameType: GameTypes.CANNON, // gameType: GameTypes.CANNON,
absolutePrestate: loadMipsAbsolutePrestate(), // absolutePrestate: loadMipsAbsolutePrestate(),
faultVm: IBigStepper(mustGetAddress("Mips")), // faultVm: IBigStepper(mustGetAddress("Mips")),
maxGameDepth: cfg.faultGameMaxDepth(), // maxGameDepth: cfg.faultGameMaxDepth(),
maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration())) // maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration()))
}) // })
}); // });
} }
/// @notice Sets the implementation for the `PERMISSIONED_CANNON` game type in the `DisputeGameFactory` /// @notice Sets the implementation for the `PERMISSIONED_CANNON` game type in the `DisputeGameFactory`
function setPermissionedCannonFaultGameImplementation(bool _allowUpgrade) public broadcast { function setPermissionedCannonFaultGameImplementation(bool _allowUpgrade) public broadcast {
console.log("Setting Cannon PermissionedDisputeGame implementation"); // console.log("Setting Cannon PermissionedDisputeGame implementation");
DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy")); // DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
DelayedWETH weth = DelayedWETH(mustGetAddress("PermissionedDelayedWETHProxy")); // DelayedWETH weth = DelayedWETH(mustGetAddress("PermissionedDelayedWETHProxy"));
//
// Set the Cannon FaultDisputeGame implementation in the factory. // // Set the Cannon FaultDisputeGame implementation in the factory.
_setFaultGameImplementation({ // _setFaultGameImplementation({
_factory: factory, // _factory: factory,
_allowUpgrade: _allowUpgrade, // _allowUpgrade: _allowUpgrade,
_params: FaultDisputeGameParams({ // _params: FaultDisputeGameParams({
anchorStateRegistry: AnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy")), // anchorStateRegistry: AnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy")),
weth: weth, // weth: weth,
gameType: GameTypes.PERMISSIONED_CANNON, // gameType: GameTypes.PERMISSIONED_CANNON,
absolutePrestate: loadMipsAbsolutePrestate(), // absolutePrestate: loadMipsAbsolutePrestate(),
faultVm: IBigStepper(mustGetAddress("Mips")), // faultVm: IBigStepper(mustGetAddress("Mips")),
maxGameDepth: cfg.faultGameMaxDepth(), // maxGameDepth: cfg.faultGameMaxDepth(),
maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration())) // maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration()))
}) // })
}); // });
} }
/// @notice Sets the implementation for the `ALPHABET` game type in the `DisputeGameFactory` /// @notice Sets the implementation for the `ALPHABET` game type in the `DisputeGameFactory`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment