Skip to content

Commit

Permalink
Merge pull request #34 from rarimo/fix/rootupdater-contract-address-i…
Browse files Browse the repository at this point in the history
…ssue

rootupdater: take contract address from tx logs instead of msg
  • Loading branch information
olegfomenko authored Sep 2, 2024
2 parents fc185b3 + 076a813 commit a0b91c0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions x/rootupdater/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,18 @@ func NewKeeper(
func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error {
params := k.GetParams(ctx)

k.Logger(ctx).Error("PostTxProcessing", "msg", msg, "receipt", receipt)
k.Logger(ctx).Info("PostTxProcessing", "msg", msg, "receipt", receipt)

stateV2, err := abi.JSON(strings.NewReader(state.PoseidonSMTABI))
if err != nil {
k.Logger(ctx).Error("failed to marshal poseidon smart abi", "error", err)
return err
return nil
}

contractAddress, err := hexutil.Decode(params.ContractAddress)
if err != nil {
// If return an error here, the whole EVM module won't work
k.Logger(ctx).Info("failed to decode contract address")
return nil
}

// Validating message receiver address (should be our state smart contract)
if msg.To() == nil || bytes.Compare(msg.To().Bytes(), contractAddress) != 0 {
k.Logger(ctx).Info("inappropriate contract address")
k.Logger(ctx).Error("failed to decode contract address")
return nil
}

Expand All @@ -84,16 +78,31 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth
k.Logger(ctx).Error("logs is empty")
}

// This approach is used because the contract address we use for validation and the event we
//want to catch are in different logs.
isAppropriateAddress := false
for _, log := range receipt.Logs {
// Validating message receiver address (should be our state smart contract)
if log != nil && log.Address.Bytes() != nil && bytes.Compare(log.Address.Bytes(), contractAddress) == 0 {
isAppropriateAddress = true
}
}
if !isAppropriateAddress {
return nil
}

for _, log := range receipt.Logs {

eventId := log.Topics[0]

event, err := stateV2.EventByID(eventId)
if err != nil {
k.Logger(ctx).Error("failed to get event by ID")
continue
}

if event.Name != params.EventName {
k.Logger(ctx).Info("unmatched event: got %s, expected %s", event.Name, params.EventName)
k.Logger(ctx).Info(fmt.Sprintf("unmatched event: got %s, expected %s", event.Name, params.EventName))
continue
}

Expand Down

0 comments on commit a0b91c0

Please sign in to comment.