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

add precompile #12

Open
wants to merge 10 commits into
base: llm-precompile
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ func New(
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(ctx, app.ICAControllerKeeper, &app.CronosKeeper, appCodec, gasConfig)
},
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewLLamaContract(gasConfig)
},
},
)

Expand Down
13 changes: 13 additions & 0 deletions integration_tests/contracts/contracts/TestLLama.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {ILLamaModule} from "./src/LLama.sol";

contract TestLLama {
address constant llamaContract = 0x0000000000000000000000000000000000000067;
ILLamaModule llama = ILLamaModule(llamaContract);

function inference(string calldata prompt, int64 seed, int32 steps) public returns (string memory) {
return llama.inference(prompt, seed, steps);
}
}
35 changes: 35 additions & 0 deletions integration_tests/test_llama.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from .utils import ADDRS, CONTRACTS, deploy_contract, send_transaction

Check failure on line 1 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:1:1: I003 isort expected 1 blank line in imports, found 0

Check failure on line 1 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:1:1: I003 isort expected 1 blank line in imports, found 0
from pystarport import ports

Check failure on line 2 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:2:1: I001 isort found an import in the wrong position
import requests

Check failure on line 3 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:3:1: I001 isort found an import in the wrong position
import time

Check failure on line 4 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:4:1: I001 isort found an import in the wrong position

Check failure on line 4 in integration_tests/test_llama.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_llama.py:4:1: F401 'time' imported but unused


def test_call(cronos):
w3 = cronos.w3
addr = ADDRS["validator"]
contract = deploy_contract(w3, CONTRACTS["TestLLama"])
prompt = ""
seed = 2
steps = 256
data = {"from": addr, "gasPrice": w3.eth.gas_price, "gas": 600000}
tx = contract.functions.inference(prompt, seed, steps).build_transaction(data)
print("mm-tx", tx)
receipt = send_transaction(w3, tx)
print("mm-receipt", receipt)
assert receipt.status == 1
param = {
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"data": tx["data"],
"to": "0x0000000000000000000000000000000000000067",
},
"latest",
],
"id": 1,
}
url = f"http://127.0.0.1:{ports.evmrpc_port(cronos.base_port(0))}"
rsp = requests.post(url, json=[param])
assert rsp.status_code == 200
print(rsp.json())
1 change: 1 addition & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"TestICA": "TestICA.sol",
"Random": "Random.sol",
"TestRelayer": "TestRelayer.sol",
"TestLLama": "TestLLama.sol",
}


Expand Down
4 changes: 2 additions & 2 deletions scripts/gen-bindings-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ solc08 --abi --bin x/cronos/events/bindings/src/RelayerFunctions.sol -o build --
solc08 --abi --bin x/cronos/events/bindings/src/Bank.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/ICA.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/ICACallback.sol -o build --overwrite


solc08 --abi --bin x/cronos/events/bindings/src/LLama.sol -o build --overwrite
abigen --pkg lib --abi build/CosmosTypes.abi --bin build/CosmosTypes.bin --out x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go --type CosmosTypes
abigen --pkg relayer --abi build/IRelayerModule.abi --bin build/IRelayerModule.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go --type RelayerModule
abigen --pkg relayer --abi build/IRelayerFunctions.abi --bin build/IRelayerFunctions.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go --type RelayerFunctions
abigen --pkg bank --abi build/IBankModule.abi --bin build/IBankModule.bin --out x/cronos/events/bindings/cosmos/precompile/bank/i_bank_module.abigen.go --type BankModule
abigen --pkg ica --abi build/IICAModule.abi --bin build/IICAModule.bin --out x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go --type ICAModule
abigen --pkg icacallback --abi build/IICACallback.abi --bin build/IICACallback.bin --out x/cronos/events/bindings/cosmos/precompile/icacallback/i_ica_callback.abigen.go --type ICACallback
abigen --pkg llama --abi build/ILLamaModule.abi --bin build/ILLamaModule.bin --out x/cronos/events/bindings/cosmos/precompile/llama/i_llama.abigen.go --type ILLamaModule
Loading
Loading