Skip to content

[execution, contracts] Introduce Relayer and non-enshrined tokens #867

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

Open
wants to merge 1 commit into
base: main
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
4 changes: 3 additions & 1 deletion docs/tests/AsyncToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ contract AsyncTokenSender {
Nil.FORWARD_REMAINING,
0,
tokens,
""
"",
0,
0
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion docs/tests/FT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ contract FT is NilTokenBase {
Nil.FORWARD_REMAINING,
0,
ft,
""
"",
0,
0
);
}

Expand Down
4 changes: 2 additions & 2 deletions nil/client/direct_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (c *DirectClient) SetTokenName(
return common.EmptyHash, err
}

return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
}

func (c *DirectClient) ChangeTokenAmount(
Expand All @@ -367,7 +367,7 @@ func (c *DirectClient) ChangeTokenAmount(
return common.EmptyHash, err
}

return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
}

func (c *DirectClient) DbInitTimestamp(ctx context.Context, ts uint64) error {
Expand Down
4 changes: 2 additions & 2 deletions nil/client/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func (c *Client) SetTokenName(
return common.EmptyHash, err
}

return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
}

func (c *Client) ChangeTokenAmount(
Expand All @@ -740,7 +740,7 @@ func (c *Client) ChangeTokenAmount(
return common.EmptyHash, err
}

return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
}

func callDbAPI[T any](ctx context.Context, c *Client, method string, params ...any) (T, error) {
Expand Down
2 changes: 1 addition & 1 deletion nil/cmd/nil/internal/contract/call-readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GetCallReadonlyCommand(cfg *common.Config) *cobra.Command {
"The path to the ABI file",
)

params.Fee = types.NewFeePackFromGas(100_000)
params.Fee = types.NewFeePackFromGas(500_000)
cmd.Flags().Var(
&params.Fee.FeeCredit,
feeCreditFlag,
Expand Down
3 changes: 1 addition & 2 deletions nil/cmd/nil/internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ func (d *DebugHandler) PrintReceipt(receipt *ReceiptInfo, indentEntry, indent st
fmt.Printf("%s%s\n", makeKey("CallData"), d.truncateData(96, receipt.Transaction.Data))
}
if len(receipt.Receipt.Logs) != 0 {
fmt.Println(makeKey("Logs"))

fmt.Print(makeKey("Logs"))
for i, log := range receipt.Receipt.Logs {
if hasContract {
if i == len(receipt.Receipt.Logs)-1 {
Expand Down
7 changes: 6 additions & 1 deletion nil/cmd/nil/internal/smartaccount/call-readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ func runCallReadonly(cmd *cobra.Command, args []string, cfg *common.Config, para
return nil, nil, err
}

result, err := common.CalldataToArgs(contractAbi, args[1], res.OutTransactions[0].Data)
data, err := contracts.UnpackRelayerResult(res.OutTransactions[0].Data)
if err != nil {
return nil, nil, err
}

result, err := common.CalldataToArgs(contractAbi, args[1], data)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion nil/cmd/nil_block_generator/internal/commands/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func CreateNewSmartAccount(rpcEndpoint string, logger logging.Logger) (string, s

salt := types.NewUint256(0)
amount := types.NewValueFromUint64(2_000_000_000_000_000)
fee := types.NewFeePackFromFeeCredit(types.NewValueFromUint64(200_000_000_000_000))
fee := types.NewFeePackFromGas(2_000_000)

srv, err := CreateCliService(rpcEndpoint, hexKey, logger)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion nil/cmd/nild/devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *cluster) generateZeroState(nShards uint32, servers []server) (*executio
return nil, err
}

zeroState, err := execution.CreateDefaultZeroStateConfig(mainPublicKey)
zeroState, err := execution.CreateDefaultZeroStateConfig(mainPublicKey, int(nShards))
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions nil/common/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import (
// As a rule of thumb, if you wish to use the function with a custom message,
// consider returning a wrapped error instead.

// PanicIf panics on true
func PanicIf(flag bool) {
PanicIfNot(!flag)
}

// PanicIfNot panics on false (use as simple assert).
func PanicIfNot(flag bool) {
if !flag {
Expand Down
8 changes: 4 additions & 4 deletions nil/contracts/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package contracts

import "embed"

//go:generate bash -c "solc ../../smart-contracts/contracts/*.sol --bin --abi --hashes --overwrite -o ./compiled --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "solc solidity/system/*.sol --bin --abi --hashes --overwrite -o ./compiled/system --allow-paths ./solidity/lib --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "solc solidity/tests/*.sol --allow-paths ../../ --base-path ../../ --bin --abi --hashes --overwrite -o ./compiled/tests --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "ln -nsf ../.. @nilfoundation && solc ../../uniswap/contracts/*.sol --bin --abi --overwrite -o ./compiled/uniswap --allow-paths .,../.. --via-ir && rm @nilfoundation"
//go:generate bash -c "solc solidity/lib/*.sol --via-ir --optimize --bin --abi --hashes --overwrite -o ./compiled --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "solc solidity/system/*.sol --via-ir --optimize --bin --abi --hashes --overwrite -o ./compiled/system --allow-paths ./solidity/lib --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "solc solidity/tests/*.sol --via-ir --optimize --allow-paths ../../ --base-path ../../ --bin --abi --hashes --overwrite -o ./compiled/tests --no-cbor-metadata --metadata-hash none"
//go:generate bash -c "ln -nsf ../.. @nilfoundation && solc ../../uniswap/contracts/*.sol --bin --abi --overwrite -o ./compiled/uniswap --allow-paths .,../.. --via-ir --optimize && rm @nilfoundation"
//go:embed compiled/*
var Fs embed.FS
1 change: 1 addition & 0 deletions nil/contracts/genlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def func_id_hex(self) -> str:
Type(sol_name="uint256", go_name="Uint256Ty", modifier=""),
Type(sol_name="bool", go_name="BoolTy", modifier=""),
Type(sol_name="address", go_name="AddressTy", modifier=""),
Type(sol_name="bytes", go_name="BytesTy", modifier="memory"),
]
STRING_TYPE = TYPES[0]
MAX_PARAM_COUNT = 4
Expand Down
15 changes: 14 additions & 1 deletion nil/contracts/solidity/compile-faucet.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"compilerVersion": "0.8.28",
"settings": {
"evmVersion": "cancun",
"viaIR": true,
"optimizer": {
"enabled": false,
"enabled": true,
"runs": 200
}
},
Expand All @@ -20,6 +21,18 @@
},
"Nil.sol": {
"urls": ["lib/Nil.sol"]
},
"Relayer.sol": {
"urls": ["lib/Relayer.sol"]
},
"NilTokenManager.sol": {
"urls": ["lib/NilTokenManager.sol"]
},
"IterableMapping.sol": {
"urls": ["lib/IterableMapping.sol"]
},
"system/console.sol": {
"urls": ["system/console.sol"]
}
}
}
15 changes: 14 additions & 1 deletion nil/contracts/solidity/compile-smart-account.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"compilerVersion": "0.8.28",
"settings": {
"evmVersion": "cancun",
"viaIR": true,
"optimizer": {
"enabled": false,
"enabled": true,
"runs": 200
}
},
Expand All @@ -17,6 +18,18 @@
},
"Nil.sol": {
"urls": ["lib/Nil.sol"]
},
"Relayer.sol": {
"urls": ["lib/Relayer.sol"]
},
"NilTokenManager.sol": {
"urls": ["lib/NilTokenManager.sol"]
},
"IterableMapping.sol": {
"urls": ["lib/IterableMapping.sol"]
},
"system/console.sol": {
"urls": ["system/console.sol"]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "../../contracts/solidity/lib/Nil.sol";
import "../lib/Nil.sol";
import "../system/console.sol";

contract Callee {
int32 value;
Expand All @@ -16,7 +17,7 @@ contract Callee {
}
}

contract Caller is NilBounceable {
contract BounceTest is NilBounceable {
using Nil for address;

string last_bounce_err;
Expand Down Expand Up @@ -53,10 +54,17 @@ contract Caller is NilBounceable {
return true;
}

function bounce(
string calldata err
) external payable override onlyInternal {
last_bounce_err = err;
function bounce(bytes memory returnData) external payable override onlyInternal {
console.log("BOUNCE RECEIVE: %_", returnData.length);
if (returnData.length > 68) {
assembly {
returnData := add(returnData, 0x04)
}
last_bounce_err = abi.decode(returnData, (string));
} else {
last_bounce_err = "<no revert reason>";
}
console.log("BOUNCE MSG: %_", last_bounce_err);
}

function get_bounce_err() public view returns (string memory) {
Expand Down
2 changes: 1 addition & 1 deletion nil/contracts/solidity/tests/Stresser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract Stresser is NilAwaitable {
return value;
}

// Consumes gas by using hot SSTORE(~529 gas per iteration)
// Consumes gas by using hot SSTORE(~307 gas per iteration)
function gasConsumer(uint256 v) public returns(uint256) {
for (uint256 i = 1; i < v; i++) {
value *= 2;
Expand Down
37 changes: 8 additions & 29 deletions nil/contracts/solidity/tests/TokensTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ contract TokensTest is NilTokenBase {
address(0),
address(0),
gas,
Nil.FORWARD_NONE,
Nil.FORWARD_REMAINING,
0,
tokens,
callData
callData,
0,
0
);
}

Expand Down Expand Up @@ -110,7 +112,7 @@ contract TokensTest is NilTokenBase {
function testConsole() public pure {
console.log("test console.log: int=%_, str=%_, addr=%_",
1234567890,
"Simple string",
string("Simple string"),
address(0xabcdef)
);
}
Expand All @@ -126,34 +128,11 @@ contract TokensTest is NilTokenBase {
event tokenTxnBalance(uint256 balance);

function checkIncomingToken(TokenId id) public payable {
emit tokenTxnBalance(Nil.txnTokens()[0].amount);
Nil.Token[] memory tokens = Nil.txnTokens();
require(tokens.length == 1, "Expected one token in transaction");
emit tokenTxnBalance(tokens[0].amount);
emit tokenBalance(Nil.tokenBalance(address(this), id));
}

receive() external payable {}
}

contract TokensTestNoExternalAccess is NilTokenBase {
function setTokenName(string memory) public view override onlyExternal {
revert("Not allowed");
}

function mintToken(uint256) public view override onlyExternal {
revert("Not allowed");
}

function sendToken(
address,
TokenId,
uint256
) public view override onlyExternal {
revert("Not allowed");
}

function verifyExternal(
uint256,
bytes calldata
) external pure returns (bool) {
return true;
}
}
28 changes: 0 additions & 28 deletions nil/contracts/solidity/tests/TransactionCheck.sol

This file was deleted.

27 changes: 26 additions & 1 deletion nil/contracts/solidity/tests/compile-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"compilerVersion": "0.8.28",
"settings": {
"evmVersion": "cancun",
"viaIR": true,
"optimizer": {
"enabled": false,
"enabled": true,
"runs": 200
}
},
Expand All @@ -15,8 +16,32 @@
"lib/Nil.sol": {
"urls": ["../lib/Nil.sol"]
},
"Nil.sol": {
"urls": ["../lib/Nil.sol"]
},
"lib/NilAwaitable.sol": {
"urls": ["../lib/NilAwaitable.sol"]
},
"Relayer.sol": {
"urls": ["../lib/Relayer.sol"]
},
"lib/Relayer.sol": {
"urls": ["../lib/Relayer.sol"]
},
"lib/NilTokenManager.sol": {
"urls": ["../lib/NilTokenManager.sol"]
},
"NilTokenManager.sol": {
"urls": ["../lib/NilTokenManager.sol"]
},
"lib/IterableMapping.sol": {
"urls": ["../lib/IterableMapping.sol"]
},
"IterableMapping.sol": {
"urls": ["../lib/IterableMapping.sol"]
},
"system/console.sol": {
"urls": ["../system/console.sol"]
}
}
}
Loading
Loading