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 precompiled contracts for alt_bn128 curve #2842

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 92 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Makefile
Expand Up @@ -16,3 +16,19 @@ debug:
cargo build -p near-vm-runner-standalone
cargo build -p state-viewer
cargo build -p store-validator

release-nightly:
cargo build -p neard --release --features nightly_protocol_features
cargo build -p keypair-generator --release
cargo build -p genesis-csv-to-json --release
cargo build -p near-vm-runner-standalone --release --features nightly_protocol_features
cargo build -p state-viewer --release
cargo build -p store-validator --release

debug-nightly:
cargo build -p neard --features nightly_protocol_features
cargo build -p keypair-generator
cargo build -p genesis-csv-to-json
cargo build -p near-vm-runner-standalone --features nightly_protocol_features
cargo build -p state-viewer
cargo build -p store-validator
5 changes: 5 additions & 0 deletions core/runtime-configs/Cargo.toml
Expand Up @@ -10,3 +10,8 @@ serde = { version = "1", features = ["derive"] }
near-primitives = { path = "../primitives" }
near-runtime-fees = { path = "../../runtime/near-runtime-fees" }
near-vm-logic = { path = "../../runtime/near-vm-logic" }

[features]
protocol_feature_alt_bn128 = []
nightly_protocol = []
nightly_protocol_features = ["nightly_protocol", "near-vm-logic/nightly_protocol_features"]
2 changes: 1 addition & 1 deletion neard/Cargo.toml
Expand Up @@ -59,7 +59,7 @@ no_cache = ["node-runtime/no_cache", "near-store/no_cache", "near-chain/no_cache
delay_detector = ["near-client/delay_detector"]
rosetta_rpc = ["near-rosetta-rpc"]
protocol_feature_forward_chunk_parts = ["near-client/protocol_feature_forward_chunk_parts"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_forward_chunk_parts", "near-client/nightly_protocol_features"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_forward_chunk_parts", "near-client/nightly_protocol_features", "node-runtime/nightly_protocol_features"]
nightly_protocol = ["near-primitives/nightly_protocol"]

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-errors/Cargo.toml
Expand Up @@ -20,4 +20,4 @@ borsh = "0.7.1"
near-rpc-error-macro = { path = "../../tools/rpctypegen/macro", version = "0.1.0" }

[features]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
6 changes: 6 additions & 0 deletions runtime/near-vm-errors/src/lib.rs
Expand Up @@ -177,6 +177,10 @@ pub enum HostError {
ContractSizeExceeded { size: u64, limit: u64 },
/// The host function was deprecated.
Deprecated { method_name: String },
/// Deserialization error for alt_bn128 functions
AltBn128DeserializationError { msg: String },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove msg from this error and AltBn128SerializationError.
Because right now it creates a dependency on error format from borsh create. And if the error changes due upgraded the dependency, then it may create an unexpected chain split.

Suggested change
AltBn128DeserializationError { msg: String },
AltBn128DeserializationError,

/// Serialization error for alt_bn128 functions
AltBn128SerializationError { msg: String },
}

#[derive(Debug, Clone, PartialEq, BorshDeserialize, BorshSerialize, Deserialize, Serialize)]
Expand Down Expand Up @@ -344,6 +348,8 @@ impl std::fmt::Display for HostError {
ReturnedValueLengthExceeded { length, limit } => write!(f, "The length of a returned value {} exceeds the limit {}", length, limit),
ContractSizeExceeded { size, limit } => write!(f, "The size of a contract code in DeployContract action {} exceeds the limit {}", size, limit),
Deprecated {method_name}=> write!(f, "Attempted to call deprecated host function {}", method_name),
AltBn128DeserializationError { msg } => write!(f, "AltBn128 deserialization error: {}", msg),
AltBn128SerializationError { msg } => write!(f, "AltBn128 serialization error: {}", msg),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions runtime/near-vm-logic/Cargo.toml
Expand Up @@ -25,12 +25,20 @@ near-runtime-fees = { path = "../near-runtime-fees", version = "2.2.0" }
near-vm-errors = { path = "../near-vm-errors", version = "2.2.0" }
near-runtime-utils = { path = "../near-runtime-utils", version = "2.2.0" }

[dependencies.bn]
package = "zeropool-bn"
version = "0.5.7"
features = []

[dev-dependencies]
serde_json = {version= "1", features= ["preserve_order"]}

[features]
default = ["costs_counting"]
wasmtime_default = []
protocol_feature_alt_bn128 = []
nightly_protocol = []
nightly_protocol_features = ["nightly_protocol", "protocol_feature_alt_bn128"]

# Use this feature to enable counting of fees and costs applied.
costs_counting = []
Expand Down