Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sender to revert context #2919

Merged
merged 46 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8a93aa3
e2e tests and modifications for authenticated call
skosito Sep 20, 2024
af8d86c
extend test with sender check and revert case
skosito Sep 20, 2024
0cd7cb2
separate tests into separate files
skosito Sep 20, 2024
914d151
cleanup
skosito Sep 20, 2024
9d1471f
withdraw and call support and tests
skosito Sep 20, 2024
10ea638
bump protocol contracts
skosito Sep 20, 2024
d6786dc
split tests into separate files
skosito Sep 20, 2024
6b711dc
small cleanup
skosito Sep 20, 2024
614df83
fmt
skosito Sep 20, 2024
fbb0c21
Merge branch 'develop' into authenticated-call-sc-support
skosito Sep 20, 2024
9557a57
generate
skosito Sep 20, 2024
07a83a1
lint
skosito Sep 20, 2024
3610f17
changelog
skosito Sep 20, 2024
7bd42dc
Merge branch 'develop' into authenticated-call-sc-support
skosito Sep 23, 2024
bd80fb2
PR comments
skosito Sep 23, 2024
86367b0
fix case in proto
skosito Sep 24, 2024
e850ae6
bump vote inbound gas limit in zetaclient
skosito Sep 24, 2024
4d6f363
fix test
skosito Sep 24, 2024
d5b5c11
generate
skosito Sep 24, 2024
c93142b
fixing tests
skosito Sep 24, 2024
80ca59e
call options non empty
skosito Sep 24, 2024
1692d98
generate
skosito Sep 24, 2024
5daa3ee
test fix
skosito Sep 24, 2024
e89c759
rename gateway caller
skosito Sep 24, 2024
04f432a
pr comments rename tests
skosito Sep 24, 2024
470a90e
PR comment
skosito Sep 24, 2024
5ad665d
generate
skosito Sep 24, 2024
8c96cea
tests
skosito Sep 24, 2024
3c02247
Merge branch 'develop' into authenticated-call-sc-support
skosito Sep 24, 2024
5e634a6
add sender in test contract
skosito Sep 24, 2024
f320012
extend e2e tests
skosito Sep 25, 2024
7ffda91
generate
skosito Sep 25, 2024
e4f0394
changelog
skosito Sep 25, 2024
24b1499
PR comment
skosito Sep 25, 2024
0a6b1f6
generate
skosito Sep 25, 2024
e8b32f2
Merge branch 'develop' into authenticated-call-sc-support
skosito Sep 26, 2024
b889c2f
update tests fixes
skosito Sep 26, 2024
f0f1c9a
tests fixes
skosito Sep 26, 2024
e7a6630
fix
skosito Sep 26, 2024
a4b9384
test fix
skosito Sep 26, 2024
3425be0
Merge branch 'authenticated-call-sc-support' into add-sender-to-rever…
skosito Sep 27, 2024
17d84da
gas limit fixes
skosito Sep 27, 2024
d6f4bf5
PR comment fix
skosito Sep 27, 2024
7a5dbdb
Merge branch 'develop' into add-sender-to-revert-context
skosito Sep 27, 2024
8c50bc8
fix bad merge
skosito Sep 27, 2024
e8fd5e6
Merge branch 'develop' into add-sender-to-revert-context
skosito Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [2907](https://github.com/zeta-chain/node/pull/2907) - derive Bitcoin tss address by chain id and added more Signet static info
* [2911](https://github.com/zeta-chain/node/pull/2911) - add chain static information for btc testnet4
* [2904](https://github.com/zeta-chain/node/pull/2904) - integrate authenticated calls smart contract functionality into protocol
* [2919](https://github.com/zeta-chain/node/pull/2919) - add inbound sender to revert context

### Refactor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etests
import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"

Expand Down Expand Up @@ -38,4 +39,12 @@ func TestV2ERC20DepositAndCallRevertWithCall(r *runner.E2ERunner, args []string)

// check the payload was received on the contract
r.AssertTestDAppEVMCalled(true, payloadMessageDepositOnRevertERC20, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageDepositOnRevertERC20),
)
require.NoError(r, err)
require.Equal(r, r.EVMAuth.From, senderForMsg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etests
import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

Expand Down Expand Up @@ -43,4 +44,12 @@ func TestV2ERC20WithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

r.AssertTestDAppZEVMCalled(true, payloadMessageWithdrawOnRevertERC20, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2ZEVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageWithdrawOnRevertERC20),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etests
import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"

Expand Down Expand Up @@ -38,4 +39,12 @@ func TestV2ETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {

// check the payload was received on the contract
r.AssertTestDAppEVMCalled(true, payloadMessageDepositOnRevertETH, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageDepositOnRevertETH),
)
require.NoError(r, err)
require.Equal(r, r.EVMAuth.From, senderForMsg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etests
import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

Expand Down Expand Up @@ -42,4 +43,12 @@ func TestV2ETHWithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string)
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

r.AssertTestDAppZEVMCalled(true, payloadMessageWithdrawOnRevertETH, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2ZEVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageWithdrawOnRevertETH),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/zeta-chain/ethermint v0.0.0-20240909234716-2fad916e7179
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240920151810-cabe34920d52
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240924201108-3a274ce7bad0
gitlab.com/thorchain/tss/go-tss v1.6.5
go.nhat.io/grpcmock v0.25.0
golang.org/x/crypto v0.23.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4182,8 +4182,8 @@ github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f h1:XqUvw9a3EnDa2
github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f/go.mod h1:B1FDE6kHs8hozKSX1/iXgCdvlFbS6+FeAupoBHDK0Cc=
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138 h1:vck/FcIIpFOvpBUm0NO17jbEtmSz/W/a5Y4jRuSJl6I=
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138/go.mod h1:U494OsZTWsU75hqoriZgMdSsgSGP1mUL1jX+wN/Aez8=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240920151810-cabe34920d52 h1:DlSY9awQteXVmvY0lPD4Or83iuL4P5KwSGky+n4mYio=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240920151810-cabe34920d52/go.mod h1:SjT7QirtJE8stnAe1SlNOanxtfSfijJm3MGJ+Ax7w7w=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240924201108-3a274ce7bad0 h1:GbfO2dyjSAWqBH0xDIttwPB2fE5A+zw0UUbEoW3S3wU=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240924201108-3a274ce7bad0/go.mod h1:SjT7QirtJE8stnAe1SlNOanxtfSfijJm3MGJ+Ax7w7w=
github.com/zeta-chain/tss-lib v0.0.0-20240916163010-2e6b438bd901 h1:9whtN5fjYHfk4yXIuAsYP2EHxImwDWDVUOnZJ2pfL3w=
github.com/zeta-chain/tss-lib v0.0.0-20240916163010-2e6b438bd901/go.mod h1:d2iTC62s9JwKiCMPhcDDXbIZmuzAyJ4lwso0H5QyRbk=
github.com/zondax/hid v0.9.1/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
Expand Down
5 changes: 5 additions & 0 deletions pkg/contracts/testdappv2/TestDAppV2.abi
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "asset",
Expand Down
2 changes: 1 addition & 1 deletion pkg/contracts/testdappv2/TestDAppV2.bin

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions pkg/contracts/testdappv2/TestDAppV2.go

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion pkg/contracts/testdappv2/TestDAppV2.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pkg/contracts/testdappv2/TestDAppV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ contract TestDAppV2 {
}

/// @notice Struct containing revert context passed to onRevert.
/// @param sender Address of account that initiated smart contract call.
/// @param asset Address of asset, empty if it's gas token.
/// @param amount Amount specified with the transaction.
/// @param revertMessage Arbitrary data sent back in onRevert.
struct RevertContext {
address sender;
address asset;
uint64 amount;
bytes revertMessage;
Expand Down Expand Up @@ -100,6 +102,7 @@ contract TestDAppV2 {
function onRevert(RevertContext calldata revertContext) external {
setCalledWithMessage(string(revertContext.revertMessage));
setAmountWithMessage(string(revertContext.revertMessage), 0);
senderWithMessage[revertContext.revertMessage] = revertContext.sender;
}

function setExpectedOnCallSender(address _expectedOnCallSender) external {
Expand Down
10 changes: 5 additions & 5 deletions testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
// process the revert on ZEVM
if err := k.fungibleKeeper.ProcessV2RevertDeposit(
ctx,
cctx.InboundParams.Sender,

Check warning on line 344 in x/crosschain/keeper/cctx_orchestrator_validate_outbound.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go#L344

Added line #L344 was not covered by tests
cctx.GetCurrentOutboundParam().Amount.BigInt(),
chainID,
cctx.InboundParams.CoinType,
Expand Down
6 changes: 6 additions & 0 deletions x/crosschain/keeper/gas_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
return cosmoserrors.Wrap(types.ErrCannotFindGasParams, err.Error())
}

// with V2 protocol, reverts on connected chains can eventually call a onRevert function which can require a higher gas limit
if cctx.ProtocolContractVersion == types.ProtocolContractVersion_V2 && cctx.RevertOptions.CallOnRevert &&
!cctx.RevertOptions.RevertGasLimit.IsZero() {
gas.GasLimit = cctx.RevertOptions.RevertGasLimit

Check warning on line 127 in x/crosschain/keeper/gas_payment.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/gas_payment.go#L127

Added line #L127 was not covered by tests
}

// calculate the final gas fee
outTxGasFee := gas.GasLimit.Mul(gas.GasPrice).Add(gas.ProtocolFlatFee)

Expand Down
1 change: 1 addition & 0 deletions x/crosschain/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type FungibleKeeper interface {
) (*evmtypes.MsgEthereumTxResponse, bool, error)
ProcessV2RevertDeposit(
ctx sdk.Context,
inboundSender string,
amount *big.Int,
chainID int64,
coinType coin.CoinType,
Expand Down
4 changes: 3 additions & 1 deletion x/fungible/keeper/v2_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
// ProcessV2RevertDeposit handles a revert deposit from an inbound tx with protocol version 2
func (k Keeper) ProcessV2RevertDeposit(
ctx sdk.Context,
inboundSender string,
amount *big.Int,
chainID int64,
coinType coin.CoinType,
Expand All @@ -74,7 +75,7 @@

if callOnRevert {
// no asset, call simple revert
_, err := k.CallExecuteRevert(ctx, zrc20Addr, amount, revertAddress, revertMessage)
_, err := k.CallExecuteRevert(ctx, inboundSender, zrc20Addr, amount, revertAddress, revertMessage)

Check warning on line 78 in x/fungible/keeper/v2_deposits.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/v2_deposits.go#L78

Added line #L78 was not covered by tests
return err
} else {
// no asset, no call, do nothing
Expand All @@ -87,6 +88,7 @@
// revert with a ZRC20 asset
_, err := k.CallDepositAndRevert(
ctx,
inboundSender,

Check warning on line 91 in x/fungible/keeper/v2_deposits.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/v2_deposits.go#L91

Added line #L91 was not covered by tests
zrc20Addr,
amount,
revertAddress,
Expand Down
4 changes: 4 additions & 0 deletions x/fungible/keeper/v2_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
// )
func (k Keeper) CallExecuteRevert(
ctx sdk.Context,
inboundSender string,
zrc20 common.Address,
amount *big.Int,
target common.Address,
Expand Down Expand Up @@ -184,6 +185,7 @@
"executeRevert",
target,
revert.RevertContext{
Sender: common.HexToAddress(inboundSender),

Check warning on line 188 in x/fungible/keeper/v2_evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/v2_evm.go#L188

Added line #L188 was not covered by tests
Asset: zrc20,
Amount: amount.Uint64(),
RevertMessage: message,
Expand All @@ -203,6 +205,7 @@
// )
func (k Keeper) CallDepositAndRevert(
ctx sdk.Context,
inboundSender string,
zrc20 common.Address,
amount *big.Int,
target common.Address,
Expand Down Expand Up @@ -236,6 +239,7 @@
amount,
target,
revert.RevertContext{
Sender: common.HexToAddress(inboundSender),

Check warning on line 242 in x/fungible/keeper/v2_evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/v2_evm.go#L242

Added line #L242 was not covered by tests
Asset: zrc20,
Amount: amount.Uint64(),
RevertMessage: message,
Expand Down
4 changes: 4 additions & 0 deletions zetaclient/chains/evm/signer/v2_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
// bytes calldata data
func (signer *Signer) signGatewayExecuteRevert(
ctx context.Context,
inboundSender string,
txData *OutboundData,
) (*ethtypes.Transaction, error) {
gatewayABI, err := gatewayevm.GatewayEVMMetaData.GetAbi()
Expand All @@ -78,6 +79,7 @@
txData.to,
txData.message,
revert.RevertContext{
Sender: common.HexToAddress(inboundSender),

Check warning on line 82 in zetaclient/chains/evm/signer/v2_sign.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/v2_sign.go#L82

Added line #L82 was not covered by tests
Asset: txData.asset,
Amount: txData.amount.Uint64(),
RevertMessage: txData.revertOptions.RevertMessage,
Expand Down Expand Up @@ -182,6 +184,7 @@
// bytes calldata data
func (signer *Signer) signERC20CustodyWithdrawRevert(
ctx context.Context,
inboundSender string,
txData *OutboundData,
) (*ethtypes.Transaction, error) {
erc20CustodyV2ABI, err := erc20custodyv2.ERC20CustodyMetaData.GetAbi()
Expand All @@ -196,6 +199,7 @@
txData.amount,
txData.message,
revert.RevertContext{
Sender: common.HexToAddress(inboundSender),

Check warning on line 202 in zetaclient/chains/evm/signer/v2_sign.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/v2_sign.go#L202

Added line #L202 was not covered by tests
Asset: txData.asset,
Amount: txData.amount.Uint64(),
RevertMessage: txData.revertOptions.RevertMessage,
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/signer/v2_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
// no-asset call simply hash msg.value == 0
return signer.signGatewayExecute(ctx, cctx.InboundParams.Sender, outboundData)
case evm.OutboundTypeGasWithdrawRevertAndCallOnRevert:
return signer.signGatewayExecuteRevert(ctx, outboundData)
return signer.signGatewayExecuteRevert(ctx, cctx.InboundParams.Sender, outboundData)

Check warning on line 32 in zetaclient/chains/evm/signer/v2_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/v2_signer.go#L32

Added line #L32 was not covered by tests
case evm.OutboundTypeERC20WithdrawRevertAndCallOnRevert:
return signer.signERC20CustodyWithdrawRevert(ctx, outboundData)
return signer.signERC20CustodyWithdrawRevert(ctx, cctx.InboundParams.Sender, outboundData)

Check warning on line 34 in zetaclient/chains/evm/signer/v2_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/v2_signer.go#L34

Added line #L34 was not covered by tests
}
return nil, fmt.Errorf("unsupported outbound type %d", outboundType)
}
Loading