Skip to content

Commit

Permalink
new predicate utils for tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Lam committed Sep 8, 2023
1 parent 7168076 commit 3063759
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.18

require (
github.com/ava-labs/avalanchego v1.10.9
github.com/ava-labs/subnet-evm v0.5.4
github.com/ava-labs/subnet-evm v0.5.6-0.20230831214243-27e0ca9c1e40
github.com/ethereum/go-ethereum v1.12.0
github.com/golang/mock v1.6.0
github.com/prometheus/client_golang v1.16.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
go.uber.org/mock v0.2.0
go.uber.org/zap v1.25.0
)

Expand All @@ -36,7 +36,6 @@ require (
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.uber.org/mock v0.2.0 // indirect
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.10.9 h1:qxhp3YoD2Wm/iIKP6Wb1isbkUPWmIrJxWgivDoL0obM=
github.com/ava-labs/avalanchego v1.10.9/go.mod h1:C8R5uiltpc8MQ62ixxgODR+15mesWF0aAw3H+Qrl9Iw=
github.com/ava-labs/subnet-evm v0.5.4 h1:4+UHva8rhGlvH4gDYpI0Lt6/J5ie1DqQa6kEmbebArI=
github.com/ava-labs/subnet-evm v0.5.4/go.mod h1:PAyhfYnECzA17N62i7OAdKazjfSsN2l8KR5nOspg39I=
github.com/ava-labs/subnet-evm v0.5.6-0.20230831214243-27e0ca9c1e40 h1:8n7WxrwwCWUSXPATwrwEsE+HY/Me1+/FBE5HNt6W/mM=
github.com/ava-labs/subnet-evm v0.5.6-0.20230831214243-27e0ca9c1e40/go.mod h1:PAyhfYnECzA17N62i7OAdKazjfSsN2l8KR5nOspg39I=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -217,8 +217,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -818,7 +816,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
33 changes: 13 additions & 20 deletions vms/evm/destination_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,25 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message,
return err
}

// Pack the signed message to be delivered in the storage slots.
// The predicate bytes are packed with a delimiter of 0xff.
predicateBytes := predicateutils.PackPredicate(signedMessage.Bytes())

to := common.HexToAddress(toAddress)

gasFeeCap := baseFee.Mul(baseFee, big.NewInt(BaseFeeFactor))
gasFeeCap.Add(gasFeeCap, big.NewInt(MaxPriorityFeePerGas))

// Construct the actual transaction to broadcast on the destination chain
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: destinationChainIDBigInt,
Nonce: tdc.currentNonce,
To: &to,
Gas: gasLimit,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Value: big.NewInt(0),
Data: callData,
AccessList: types.AccessList{
{
Address: warp.ContractAddress,
StorageKeys: predicateutils.BytesToHashSlice(predicateBytes),
},
},
})
tx := predicateutils.NewPredicateTx(
destinationChainIDBigInt,
tdc.currentNonce,
&to,
gasLimit,
gasFeeCap,
gasTipCap,
big.NewInt(0),
callData,
types.AccessList{},
warp.ContractAddress,
signedMessage.Bytes(),
)

// Sign and send the transaction on the destination chain
signer := types.LatestSignerForChainID(destinationChainIDBigInt)
Expand Down

0 comments on commit 3063759

Please sign in to comment.