public static bool QuantSeq <U>(Dafny.Sequence <U> seq, bool frall, System.Predicate <U> pred) { foreach (var u in seq.Elements) { if (pred(u) != frall) { return(!frall); } } return(frall); }
/** Invoke PySSZ through an helper Python script to calculate the Merkle * hash root of a Bitlist * * @param bitlist The bitlist as a raw sequence of bool (without the * bit used as a sentinel for the length) * @param bitlistInBytes The raw bitlist (i.e. without the bit used * as a sentinel for the length)encoded as a * sequence of bytes. * @param limit The bitlist limit * @returns The hashtree root of the supplied bitlist * * @note The reason for having both bitlist and bitlistInBytes parameters * is that the former is used by the PySSZ bridge and the latter is used * by the PrysmaticLab bridge. */ public static Dafny.Sequence <byte> BitlistRoot(Dafny.Sequence <bool> bitlist, Dafny.Sequence <byte> bitlistInBytes, BigInteger limit) { // Convert bitlist into a byte array byte[] bl = new byte[bitlist.Elements.Length]; for (int i = 0; i < bitlist.Elements.Length; i++) { if (bitlist.Elements[i]) { bl[i] = 1; } else { bl[i] = 0; } } // Set command and command line ProcessStartInfo start = new ProcessStartInfo(); start.FileName = "python3"; start.Arguments = "PySszBitlistMerkleisation.py " + limit; // Set redirections for stdout and stdin start.UseShellExecute = false; start.RedirectStandardOutput = true; start.RedirectStandardInput = true; // Start the process Process cmdProcess = new Process(); cmdProcess.StartInfo = start; cmdProcess.Start(); // Write to the process stdin in binary format and then closes // the stream var bw = new BinaryWriter(cmdProcess.StandardInput.BaseStream); bw.Write(bl); cmdProcess.StandardInput.Close(); cmdProcess.WaitForExit(); // Read from the process stdout in binary format and store the // read data in a byte array var br = new BinaryReader(cmdProcess.StandardOutput.BaseStream); byte[] retBytes = br.ReadBytes(32); // Convert the C# byte array containing the data read from the // process stdout to a Dafny sequence of byte return(Dafny.Sequence <byte> .FromElements(retBytes)); }
public Result <Dafny.Sequence <char> > Get(Dafny.Sequence <char> key) { String result; if (content.TryGetValue(key.ToString(), out result)) { return(Result <Dafny.Sequence <char> > .create_Success( Dafny.Sequence <char> .FromString(result))); } else { return(Result <Dafny.Sequence <char> > .create_Failure( Dafny.Sequence <char> .FromString("key not found"))); } }
public static Dafny.Sequence <byte> ListBytes32Root(Dafny.Sequence <Dafny.Sequence <byte> > listOfBytes32, BigInteger limit) { // Build the list of arguments for the Python script List <String> arguments = new List <String>(); arguments.Add(limit.ToString()); foreach (Dafny.Sequence <byte> s in listOfBytes32.Elements) { foreach (BigInteger n in s.Elements) { arguments.Add(n.ToString()); } } // Set command and command line ProcessStartInfo start = new ProcessStartInfo(); start.FileName = "python3"; start.Arguments = "PySszListOfBytes32Merkleisation.py " + String.Join(" ", arguments.ToArray()); // Set redirections for stdout and stdin start.UseShellExecute = false; start.RedirectStandardOutput = true; // Start the process Process cmdProcess = new Process(); cmdProcess.StartInfo = start; cmdProcess.Start(); // Read from the process stdout in binary format and store the // read data in a byte array var br = new BinaryReader(cmdProcess.StandardOutput.BaseStream); byte[] retBytes = br.ReadBytes(32); // Convert the C# byte array containing the data read from the // process stdout to a Dafny sequence of byte return(Dafny.Sequence <byte> .FromElements(retBytes)); }
/** Invoke PySSZ through an helper Python script to calculate the Merkle * hash root of a Vector of Bytes */ public static Dafny.Sequence <byte> BytesRoot(Dafny.Sequence <byte> bs) { ProcessStartInfo start = new ProcessStartInfo(); // Set command and command line start.FileName = "python3"; start.Arguments = "PySszBytesMerkleisation.py"; // Set redirections for stdin and stdout start.UseShellExecute = false; start.RedirectStandardOutput = true; start.RedirectStandardInput = true; // Start the process Process cmdProcess = new Process(); cmdProcess.StartInfo = start; cmdProcess.Start(); // Write to the process stdin in binary format and then closes // the stream var bw = new BinaryWriter(cmdProcess.StandardInput.BaseStream); bw.Write(bs.Elements); cmdProcess.StandardInput.Close(); // Read from the process stdout in binary format and store the // read data in a byte array var br = new BinaryReader(cmdProcess.StandardOutput.BaseStream); byte[] retBytes = br.ReadBytes(32); // Convert the C# byte array containing the data read from the // process stdout to a Dafny sequence of byte return(Dafny.Sequence <byte> .FromElements(retBytes)); }
public void Put(Dafny.Sequence <char> key, Dafny.Sequence <char> value) { Console.WriteLine("C# Externs.StringMap.Put is called"); this.content.Add(key.ToString(), value.ToString()); }
public static void readln(out Dafny.Sequence <char> line) { string result = System.Console.ReadLine(); line = new Dafny.Sequence <char>((result == null ? "\0" : result).ToCharArray()); }
public static int parse(Dafny.Sequence <char> str) { return(System.Int32.Parse(str.ToString())); }
// hash calculates the SHA256 of `data` public static Dafny.Sequence <byte> hash(Dafny.Sequence <byte> data) { SHA256 sha = SHA256.Create(); return(Dafny.Sequence <byte> .FromElements(sha.ComputeHash(data.Elements))); }
public void @get__random(BigInteger countb, out Dafny.Sequence<BigInteger> @result) { int counti = (int)countb; BigInteger[] bary = new BigInteger[counti]; for (int i = 0; i < counti; i++) { int rand = rng.Next() & 0xff; bary[i] = new BigInteger(rand); } @result = new Dafny.Sequence<BigInteger>(bary); display_seq(bary); }
public static void @CopySeqIntoArray <A>(Dafny.Sequence <A> src, ulong srcIndex, A[] dst, ulong dstIndex, ulong len) { System.Array.Copy(src.Elements, (long)srcIndex, dst, (long)dstIndex, (long)len); }