88 "math/big"
99
1010 "github.com/ava-labs/coreth/precompile/contract"
11- "github.com/ava-labs/coreth/vmerrs"
1211 "github.com/ava-labs/libevm/common"
1312 "github.com/ava-labs/libevm/core/vm"
1413 "github.com/ava-labs/libevm/log"
@@ -56,18 +55,18 @@ func UnpackNativeAssetBalanceInput(input []byte) (common.Address, common.Hash, e
5655func (b * NativeAssetBalance ) Run (accessibleState contract.AccessibleState , caller common.Address , addr common.Address , input []byte , suppliedGas uint64 , readOnly bool ) (ret []byte , remainingGas uint64 , err error ) {
5756 // input: encodePacked(address 20 bytes, assetID 32 bytes)
5857 if suppliedGas < b .GasCost {
59- return nil , 0 , vmerrs .ErrOutOfGas
58+ return nil , 0 , vm .ErrOutOfGas
6059 }
6160 remainingGas = suppliedGas - b .GasCost
6261
6362 address , assetID , err := UnpackNativeAssetBalanceInput (input )
6463 if err != nil {
65- return nil , remainingGas , vmerrs .ErrExecutionReverted
64+ return nil , remainingGas , vm .ErrExecutionReverted
6665 }
6766
6867 res , overflow := uint256 .FromBig (accessibleState .GetStateDB ().GetBalanceMultiCoin (address , assetID ))
6968 if overflow {
70- return nil , remainingGas , vmerrs .ErrExecutionReverted
69+ return nil , remainingGas , vm .ErrExecutionReverted
7170 }
7271 return common .LeftPadBytes (res .Bytes (), 32 ), remainingGas , nil
7372}
@@ -107,7 +106,7 @@ func UnpackNativeAssetCallInput(input []byte) (common.Address, common.Hash, *big
107106func (c * NativeAssetCall ) Run (accessibleState contract.AccessibleState , caller common.Address , addr common.Address , input []byte , suppliedGas uint64 , readOnly bool ) (ret []byte , remainingGas uint64 , err error ) {
108107 env := accessibleState .GetPrecompileEnv ()
109108 if ! env .UseGas (c .GasCost ) {
110- return nil , 0 , vmerrs .ErrOutOfGas
109+ return nil , 0 , vm .ErrOutOfGas
111110 }
112111 ret , err = c .run (env , accessibleState .GetStateDB (), caller , addr , input , readOnly )
113112 // This precompile will be wrapped in a libevm `legacy` wrapper, which
@@ -123,26 +122,26 @@ func (c *NativeAssetCall) Run(accessibleState contract.AccessibleState, caller c
123122// avoids mixing gas-accounting patterns when using env.Call().
124123func (c * NativeAssetCall ) run (env vm.PrecompileEnvironment , stateDB contract.StateDB , caller common.Address , addr common.Address , input []byte , readOnly bool ) (ret []byte , err error ) {
125124 if readOnly {
126- return nil , vmerrs .ErrExecutionReverted
125+ return nil , vm .ErrExecutionReverted
127126 }
128127
129128 to , assetID , assetAmount , callData , err := UnpackNativeAssetCallInput (input )
130129 if err != nil {
131130 log .Debug ("unpacking native asset call input failed" , "err" , err )
132- return nil , vmerrs .ErrExecutionReverted
131+ return nil , vm .ErrExecutionReverted
133132 }
134133
135134 // Note: it is not possible for a negative assetAmount to be passed in here due to the fact that decoding a
136135 // byte slice into a *big.Int type will always return a positive value, as documented on [big.Int.SetBytes].
137136 if assetAmount .Sign () != 0 && stateDB .GetBalanceMultiCoin (caller , assetID ).Cmp (assetAmount ) < 0 {
138- return nil , vmerrs .ErrInsufficientBalance
137+ return nil , vm .ErrInsufficientBalance
139138 }
140139
141140 snapshot := stateDB .Snapshot ()
142141
143142 if ! stateDB .Exist (to ) {
144143 if ! env .UseGas (c .CallNewAccountGas ) {
145- return nil , vmerrs .ErrOutOfGas
144+ return nil , vm .ErrOutOfGas
146145 }
147146 stateDB .CreateAccount (to )
148147 }
@@ -152,13 +151,12 @@ func (c *NativeAssetCall) run(env vm.PrecompileEnvironment, stateDB contract.Sta
152151 stateDB .AddBalanceMultiCoin (to , assetID , assetAmount )
153152
154153 ret , err = env .Call (to , callData , env .Gas (), new (uint256.Int ), vm .WithUNSAFECallerAddressProxying ())
155-
156154 // When an error was returned by the EVM or when setting the creation code
157155 // above we revert to the snapshot and consume any gas remaining. Additionally
158156 // when we're in homestead this also counts for code storage gas errors.
159157 if err != nil {
160158 stateDB .RevertToSnapshot (snapshot )
161- if err != vmerrs .ErrExecutionReverted {
159+ if err != vm .ErrExecutionReverted {
162160 env .UseGas (env .Gas ())
163161 }
164162 // TODO: consider clearing up unused snapshots:
@@ -171,5 +169,5 @@ func (c *NativeAssetCall) run(env vm.PrecompileEnvironment, stateDB contract.Sta
171169type DeprecatedContract struct {}
172170
173171func (* DeprecatedContract ) Run (accessibleState contract.AccessibleState , caller common.Address , addr common.Address , input []byte , suppliedGas uint64 , readOnly bool ) (ret []byte , remainingGas uint64 , err error ) {
174- return nil , suppliedGas , vmerrs .ErrExecutionReverted
172+ return nil , suppliedGas , vm .ErrExecutionReverted
175173}
0 commit comments