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

--disable-hint-validation flag #85

Merged
merged 4 commits into from
Mar 29, 2022
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ This plugin defines the following Hardhat commands (also called tasks):
### `starknet-compile`

```
npx hardhat starknet-compile [PATH...] [--cairo-path "<LIB_PATH1>:<LIB_PATH2>:..."] [--account-contract]
npx hardhat starknet-compile [PATH...] [--cairo-path "<LIB_PATH1>:<LIB_PATH2>:..."] [--account-contract] [--disable-hint-validation]
```

If no paths are provided, all Starknet contracts in the default contracts directory are compiled. Paths can be files and directories.
Expand All @@ -57,6 +57,8 @@ If no paths are provided, all Starknet contracts in the default contracts direct

`--account-contract` allows compiling an account contract.

`--disable-hint-validation` allows compiling a contract without hint validation (any python code is allowed in hints, ex: print ...).

### `starknet-deploy`

```
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ task("starknet-compile", "Compiles Starknet contracts")
"Separate them with a colon (:), e.g. --cairo-path='path/to/lib1:path/to/lib2'"
)
.addFlag("accountContract", "Allows compiling an account contract.")
.addFlag("disableHintValidation", "Allows compiling a contract with any python code in hints.")
.setAction(starknetCompileAction);

task("starknet-deploy", "Deploys Starknet contracts which have been compiled.")
Expand Down
5 changes: 5 additions & 0 deletions src/starknet-wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface CompileWrapperOptions {
abi: string;
cairoPath: string;
accountContract: boolean;
disableHintValidation: boolean;
}

interface DeployWrapperOptions {
Expand Down Expand Up @@ -72,6 +73,10 @@ export abstract class StarknetWrapper {
ret.push("--account_contract");
}

if (options.disableHintValidation) {
ret.push("--disable_hint_validation");
}

return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion src/task-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export async function starknetCompileAction(args: TaskArguments, hre: HardhatRun
output: outputPath,
abi: abiPath,
cairoPath,
accountContract: args.accountContract
accountContract: args.accountContract,
disableHintValidation: args.disableHintValidation
});

statusCode += processExecuted(executed, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

PREFIX=$(dirname "$0")

CONTRACT_NAME=contract_with_unwhitelisted_hints.cairo

cp "$PREFIX/$CONTRACT_NAME" contracts/

EXPECTED="Hint is not whitelisted.
This may indicate that this library function cannot be used in StarkNet contracts."

echo "Testing rejection of compilation without the --disable-hint-validation flag"
npx hardhat starknet-compile "$CONTRACT_NAME" 2>&1 |
../scripts/assert-contains.py "$EXPECTED"
echo "Success"

npx hardhat starknet-compile "$CONTRACT_NAME" --disable-hint-validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Declare this file as a StarkNet contract.
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256, uint256_sub, uint256_signed_nn

# Define a storage variable.
@storage_var
func balance() -> (res : felt):
end

# Increases the balance by the given amount.
@external
func increase_balance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}():
let a = Uint256(1, 0)
let b = Uint256(2, 0)
let (c) = uint256_sub(a, b)
let (d) = uint256_signed_nn(c)
%{ print(f"{ids.d=}") %}
return ()
end

# Returns the current balance.
@view
func get_balance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (
res : felt):
let (res) = balance.read()
return (res)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "../dist/index.js";

module.exports = {
starknet: {
network: process.env.NETWORK
},
networks: {
devnet: {
url: "http://localhost:5000"
}
}
};