Skip to content

Commit

Permalink
feat: remote omni-chain call context: sender and chainID (#912)
Browse files Browse the repository at this point in the history
* make smoketest work

* smoketest: add test for context in depositAndCall

* add missing files

* add Update System Contract Address msg

and smoketest

* fix linter complaints

* fix openapi

* fix gosec complaint and CI config

* fix linter config

* fix generated file check fail

* try fix CI config

* address PR comments

* add typed events

* migrate one more event to typed event

* cleanup fixme

* update protocol-contract package to latest main branch

* Update x/fungible/keeper/evm.go

Co-authored-by: Lucas Bertrand <[email protected]>

* PR comments address: error types

* re-generate go.sum

* use protocol-contract commit 5dfbe4f

which renames Context => zContext

---------

Co-authored-by: brewmaster012 <>
Co-authored-by: Lucas Bertrand <[email protected]>
  • Loading branch information
brewmaster012 and lumtis authored Aug 9, 2023
1 parent b7dfadf commit 50fa378
Show file tree
Hide file tree
Showing 45 changed files with 2,537 additions and 196 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ on:
- '*'
pull_request:

env:
GOPRIVATE: github.com/zeta-chain/*


jobs:
gosec:
runs-on: ubuntu-latest
Expand All @@ -23,7 +21,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19

# - name: Install Pipeline Dependencies
# uses: ./.github/actions/install-dependencies
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ on:
- '*'
pull_request:

env:
GOPRIVATE: github.com/zeta-chain/*

concurrency:
group: linters-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 7

env:
GO111MODULE: on
Expand Down
1 change: 1 addition & 0 deletions cmd/zetacore_utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func readLines(path string) ([]string, error) {
if err != nil {
return nil, err
}
/* #nosec G307 */
defer file.Close()

var lines []string
Expand Down
10 changes: 10 additions & 0 deletions common/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ func (chain Chain) EncodeAddress(b []byte) (string, error) {
return "", fmt.Errorf("chain (%d) not supported", chain.ChainId)
}

// DecodeAddress decode the address string to bytes
func (chain Chain) DecodeAddress(addr string) ([]byte, error) {
if IsEVMChain(chain.ChainId) {
return ethcommon.HexToAddress(addr).Bytes(), nil
} else if IsBitcoinChain(chain.ChainId) {
return []byte(addr), nil
}
return nil, fmt.Errorf("chain (%d) not supported", chain.ChainId)
}

func IsEVMChain(chainID int64) bool {
return chainID == 5 || // Goerli
chainID == 80001 || // Polygon mumbai
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes",
"name": "origin",
"type": "bytes"
},
{
"indexed": false,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "chainID",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "msgSender",
"type": "address"
}
],
"name": "ContextData",
"type": "event"
},
{
"inputs": [
{
"components": [
{
"internalType": "bytes",
"name": "origin",
"type": "bytes"
},
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "uint256",
"name": "chainID",
"type": "uint256"
}
],
"internalType": "struct Context",
"name": "context",
"type": "tuple"
},
{
"internalType": "address",
"name": "zrc20",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "message",
"type": "bytes"
}
],
"name": "onCrossChainCall",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50610420806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063de43156e14610030575b600080fd5b61004a60048036038101906100459190610182565b61004c565b005b7fcde88c82509f7dbeaae2782de64879ac731556f65d4474e9afc4ea01cca4498885806000019061007d91906102bf565b8760200160208101906100909190610155565b8860400135336040516100a7959493929190610271565b60405180910390a15050505050565b6000813590506100c5816103bc565b92915050565b60008083601f8401126100e1576100e0610383565b5b8235905067ffffffffffffffff8111156100fe576100fd61037e565b5b60208301915083600182028301111561011a57610119610397565b5b9250929050565b6000606082840312156101375761013661038d565b5b81905092915050565b60008135905061014f816103d3565b92915050565b60006020828403121561016b5761016a6103a6565b5b6000610179848285016100b6565b91505092915050565b60008060008060006080868803121561019e5761019d6103a6565b5b600086013567ffffffffffffffff8111156101bc576101bb6103a1565b5b6101c888828901610121565b95505060206101d9888289016100b6565b94505060406101ea88828901610140565b935050606086013567ffffffffffffffff81111561020b5761020a6103a1565b5b610217888289016100cb565b92509250509295509295909350565b61022f81610333565b82525050565b60006102418385610322565b935061024e83858461036f565b610257836103ab565b840190509392505050565b61026b81610365565b82525050565b6000608082019050818103600083015261028c818789610235565b905061029b6020830186610226565b6102a86040830185610262565b6102b56060830184610226565b9695505050505050565b600080833560016020038436030381126102dc576102db610392565b5b80840192508235915067ffffffffffffffff8211156102fe576102fd610388565b5b60208301925060018202360383131561031a5761031961039c565b5b509250929050565b600082825260208201905092915050565b600061033e82610345565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6103c581610333565b81146103d057600080fd5b50565b6103dc81610365565b81146103e757600080fd5b5056fea26469706673582212203bf8ff0cc81cde452b74dd59e10fc546b8344cb0b268971059b45bc40191115d64736f6c63430008070033
Loading

0 comments on commit 50fa378

Please sign in to comment.