Skip to content

Commit ba20ebc

Browse files
authored
Merge commit from fork
* Clean up events on EVM reversion in try-catch * backport v0.3.x-specific file layout and helpers * yihuang-patch adaptation for v0.3.x Adds balance handler factory to un-refactored precompile code, adapting it for Distribution, Staking, Slashing, ICS20, Gov, and the now-deprecated Evidence. Skips the ERC20 as that one did not yet make use of the balance handler in v0.4.x. * Add adapted test for v0.3.x Added balance handler test, adapted for the v0.4.x precompile structure. Uses a decomposed version of the p.RunSetup function without the method checks. Also, has to use Ginkgo tests with explicit state saving to prevent overwrites. Note that the events list here is much larger due to the structure of the factory contract caller. * fix mocks2 * Add debug json * add debug comments
1 parent 7964aaa commit ba20ebc

36 files changed

Lines changed: 3036 additions & 65 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package contracts
2+
3+
import (
4+
_ "embed"
5+
6+
contractutils "github.com/cosmos/evm/contracts/utils"
7+
evmtypes "github.com/cosmos/evm/x/vm/types"
8+
)
9+
10+
var (
11+
//go:embed solidity/DebugPrecompileCaller.json
12+
DebugPrecompileCallerJSON []byte
13+
14+
// GreeterContract is the compiled Greeter contract
15+
DebugPrecompileCallerContract evmtypes.CompiledContract
16+
)
17+
18+
func init() {
19+
var err error
20+
if DebugPrecompileCallerContract, err = contractutils.ConvertHardhatBytesToCompiledContract(
21+
DebugPrecompileCallerJSON,
22+
); err != nil {
23+
panic(err)
24+
}
25+
}
26+
27+
// LoadGreeter loads the Greeter contract
28+
func LoadDebugPrecompileCaller() (evmtypes.CompiledContract, error) {
29+
return DebugPrecompileCallerContract, nil
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package contracts
2+
3+
import (
4+
contractutils "github.com/cosmos/evm/contracts/utils"
5+
evmtypes "github.com/cosmos/evm/x/vm/types"
6+
)
7+
8+
func LoadERC20RecursiveNonReverting() (evmtypes.CompiledContract, error) {
9+
return contractutils.LoadContractFromJSONFile("solidity/ERC20RecursiveNonRevertingPrecompileCall.json")
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package contracts
2+
3+
import (
4+
contractutils "github.com/cosmos/evm/contracts/utils"
5+
evmtypes "github.com/cosmos/evm/x/vm/types"
6+
)
7+
8+
func LoadERC20RecursiveReverting() (evmtypes.CompiledContract, error) {
9+
return contractutils.LoadContractFromJSONFile("solidity/ERC20RecursiveRevertingPrecompileCall.json")
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"_format": "hh-sol-artifact-1",
3+
"contractName": "DebugPrecompileCaller",
4+
"sourceName": "solidity/DebugPrecompileCaller.sol",
5+
"abi": [
6+
{
7+
"inputs": [
8+
{
9+
"internalType": "bytes",
10+
"name": "data",
11+
"type": "bytes"
12+
}
13+
],
14+
"name": "CallFailed",
15+
"type": "error"
16+
},
17+
{
18+
"inputs": [
19+
{
20+
"internalType": "uint256",
21+
"name": "counter",
22+
"type": "uint256"
23+
}
24+
],
25+
"name": "callback",
26+
"outputs": [],
27+
"stateMutability": "nonpayable",
28+
"type": "function"
29+
}
30+
],
31+
"bytecode": "0x608080604052346100165761023e908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b6000803560e01c63ff585caf1461002857600080fd5b34610047576020366003190112610047576100446004356100f4565b80f35b80fd5b3d156100a65767ffffffffffffffff903d8281116100905760405192601f8201601f19908116603f01168401908111848210176100905760405282523d6000602084013e565b634e487b7160e01b600052604160045260246000fd5b606090565b6020808252825181830181905290939260005b8281106100e057505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016100be565b60005b81811061017a5750600381116101775760405190602082019060008252602183015260218252606082019082821067ffffffffffffffff8311176100905760009283926040525190826107995af161014d61004a565b90156101565750565b60405163a5fa8d2b60e01b815290819061017390600483016100ab565b0390fd5b50565b60408051600160f81b60208201908152600182528183019067ffffffffffffffff82118383101761009057600092839285525190826107995af1906101bd61004a565b91156101ec57505060001981146101d6576001016100f7565b634e487b7160e01b600052601160045260246000fd5b5163a5fa8d2b60e01b81529150819061017390600483016100ab56fea2646970667358221220f0ddd005e729c0bf54b8295a483a2d7c84c3948a24b42ea5b8f906cf9b1c361f64736f6c63430008140033",
32+
"deployedBytecode": "0x6080604052600436101561001257600080fd5b6000803560e01c63ff585caf1461002857600080fd5b34610047576020366003190112610047576100446004356100f4565b80f35b80fd5b3d156100a65767ffffffffffffffff903d8281116100905760405192601f8201601f19908116603f01168401908111848210176100905760405282523d6000602084013e565b634e487b7160e01b600052604160045260246000fd5b606090565b6020808252825181830181905290939260005b8281106100e057505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016100be565b60005b81811061017a5750600381116101775760405190602082019060008252602183015260218252606082019082821067ffffffffffffffff8311176100905760009283926040525190826107995af161014d61004a565b90156101565750565b60405163a5fa8d2b60e01b815290819061017390600483016100ab565b0390fd5b50565b60408051600160f81b60208201908152600182528183019067ffffffffffffffff82118383101761009057600092839285525190826107995af1906101bd61004a565b91156101ec57505060001981146101d6576001016100f7565b634e487b7160e01b600052601160045260246000fd5b5163a5fa8d2b60e01b81529150819061017390600483016100ab56fea2646970667358221220f0ddd005e729c0bf54b8295a483a2d7c84c3948a24b42ea5b8f906cf9b1c361f64736f6c63430008140033",
33+
"linkReferences": {},
34+
"deployedLinkReferences": {}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.4;
3+
4+
contract DebugPrecompileCaller {
5+
address constant debugPrecompile = 0x0000000000000000000000000000000000000799;
6+
error CallFailed(bytes data);
7+
function callback(uint256 counter) public {
8+
bool result;
9+
bytes memory data;
10+
11+
// emit events
12+
for (uint i = 0; i < counter; i++) {
13+
(result, data) = debugPrecompile.call(abi.encodePacked(uint8(1)));
14+
if (!result) {
15+
revert CallFailed(data);
16+
}
17+
}
18+
19+
if (counter > 3) {
20+
// stop the recursion
21+
return;
22+
}
23+
24+
// recursive call
25+
(result, data) = debugPrecompile.call(abi.encodePacked(uint8(0), counter));
26+
if (!result) {
27+
revert CallFailed(data);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)