Skip to content

Commit

Permalink
Fixes for ethereum bridge and json representation of batch header. (#…
Browse files Browse the repository at this point in the history
…1953)

* Dump.

* Added hash to json.

* Redisabled test.

* Regenerated contracts.

---------

Co-authored-by: StefanIliev545 <[email protected]>
  • Loading branch information
StefanIliev545 and StefanIliev545 authored Jun 6, 2024
1 parent e645308 commit a9485fe
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contracts/generated/EthereumBridge/EthereumBridge.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/bridge/L2/EthereumBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ contract EthereumBridge is

function sendNative(address receiver) external payable {
require(msg.value > 0, "Nothing sent.");
require(hasTokenMapping(address(0x0)), "No mapping for token.");

bytes memory data = abi.encodeWithSelector(
IBridge.receiveAssets.selector,
Expand All @@ -67,6 +66,7 @@ contract EthereumBridge is
receiver
);
queueMessage(remoteBridgeAddress, data, uint32(Topics.TRANSFER), 0, 0);
_messageBus().sendValueToL2{value: msg.value}(receiver, msg.value);
}

function sendERC20(
Expand Down
1 change: 0 additions & 1 deletion contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
isWithdrawalSpent[keccak256(abi.encode(_msg))] = true;

messageBus.receiveValueFromL2(_msg.receiver, _msg.amount);
//todo track state
}

// An attested enclave will pickup the Network Secret Request
Expand Down
6 changes: 3 additions & 3 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ type batchHeaderEncoding struct {
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`
LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages.
LatestInboundCrossChainHeight *hexutil.Big `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages.
TransfersTree common.Hash
CrossChainTree SerializedCrossChainTree `json:"crossChainTree"`
CrossChainRootHash common.Hash `json:"crossChainTreeHash"`
CrossChainTree SerializedCrossChainTree `json:"crossChainTree"`
}

// MarshalJSON custom marshals the BatchHeader into a json
Expand Down Expand Up @@ -122,7 +122,7 @@ func (b *BatchHeader) UnmarshalJSON(data []byte) error {
b.CrossChainMessages = dec.CrossChainMessages
b.LatestInboundCrossChainHash = dec.LatestInboundCrossChainHash
b.LatestInboundCrossChainHeight = (*big.Int)(dec.LatestInboundCrossChainHeight)
b.CrossChainRoot = dec.TransfersTree
b.CrossChainRoot = dec.CrossChainRootHash
b.CrossChainTree = dec.CrossChainTree
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/crosschain/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (vt ValueTransfers) ForMerkleTree() [][]interface{} {
for idx := range vt {
hashedVal := vt.HashPacked(idx)
val := []interface{}{
"v",
"v", // [v, "0xblabla"]
hashedVal,
}
values = append(values, val)
Expand Down
18 changes: 13 additions & 5 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,11 @@ func (g *Guardian) periodicBundleSubmission() {

bundleSubmissionTicker := time.NewTicker(interval)

fromSequenceNumber := uint64(0)
fromSequenceNumber, _, err := g.sl.L1Publisher().GetBundleRangeFromManagementContract()
if err != nil {
g.logger.Error(`Unable to get bundle range from management contract and initialize cross chain publishing`, log.ErrKey, err)
return
}

for {
select {
Expand All @@ -645,21 +649,25 @@ func (g *Guardian) periodicBundleSubmission() {
continue
}

if from.Uint64() > fromSequenceNumber {
fromSequenceNumber = from.Uint64()
if from.Uint64() > fromSequenceNumber.Uint64() {
fromSequenceNumber.Set(from)
}

bundle, err := g.enclaveClient.ExportCrossChainData(context.Background(), fromSequenceNumber, to.Uint64())
bundle, err := g.enclaveClient.ExportCrossChainData(context.Background(), fromSequenceNumber.Uint64(), to.Uint64())
if err != nil {
if !errors.Is(err, errutil.ErrCrossChainBundleNoBatches) {
g.logger.Error("Unable to export cross chain bundle from enclave", log.ErrKey, err)
}
if errors.Is(err, context.DeadlineExceeded) {
g.logger.Error(`Cross chain bundle export timed out.`, log.ErrKey, err)
return // stop the process - if we are timing out we are not going to catch up
}
continue
}

if len(bundle.CrossChainRootHashes) == 0 {
g.logger.Debug("No cross chain data to submit")
fromSequenceNumber = to.Uint64() + 1
fromSequenceNumber.SetUint64(to.Uint64() + 1)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/transaction_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (ti *TransactionInjector) awaitAndFinalizeWithdrawal(tx *types.Transaction,
return
}

xchainTree := make([][]interface{}, 0)
xchainTree := make([][]interface{}, 0) // ["v", "0xblablablabla"]
err = json.Unmarshal(header.CrossChainTree, &xchainTree)
if err != nil {
ti.logger.Error("Failed to unmarshal cross chain tree for withdrawal transaction", log.ErrKey, err)
Expand Down

0 comments on commit a9485fe

Please sign in to comment.